Sha256: 83384da050e4e3114b189d5074e1688c06ccb32b073b7f0252c66a39c1f02925

Contents?: true

Size: 956 Bytes

Versions: 4

Compression:

Stored size: 956 Bytes

Contents

module PagSeguro
  class Checkout < Base
    def create(params)
      params = build_request(params).to_xml

      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 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

4 entries across 4 versions & 1 rubygems

Version Path
pagseguro_next-0.3.0 lib/pagseguro/checkout.rb
pagseguro_next-0.2.0 lib/pagseguro/checkout.rb
pagseguro_next-0.1.1 lib/pagseguro/checkout.rb
pagseguro_next-0.1.0 lib/pagseguro/checkout.rb