Sha256: ad87811a0be68b0c2ce10b4d1c9947a2d1d8a1010a9ff67df2747c232fdde815

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module PagSeguro
  class Checkout
    include Restful

    def create(params)
      params = build_request(params).to_xml(encoding: "UTF-8")
      response = post_xml("/v2/checkout", params)
      response.checkout
    end

    def url(code)
      url_for :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])
                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-1.0.2 lib/pagseguro/checkout.rb