Sha256: 51dd129776d64a96b8740bb8017306d154e6fc0c28a4c5c6c7c7dbd30c70e528

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

module PagSeguro
  class Checkout < Base
    def create(params)
      params = build_request(params).to_xml(encoding: "UTF-8")

      response = api.post "/v2/checkout", params do |conn|
        conn.headers[:content_type] = FORMATS[:xml]
        conn.headers[:accept] = FORMATS[:xml]
      end

      parse response.body["checkout"]
    end

    def url(code)
      api.build_url :site, "/v2/checkout/payment.html", code: code
    end

    private

    def build_request(params)
      builder do
        checkout do
          currency "BRL"
          sender do
            ip params[:remote_ip]
          end if params.key?(:remote_ip)
          items do
            item do
              id params[:id]
              description { cdata(params[:description]) }
              amount format("%.2f", params[:amount].to_f)
              quantity 1
            end
          end
          shipping do
            addressRequired false
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pagseguro_next-0.4.0 lib/pagseguro/checkout.rb