Sha256: a110982d787c325d77017667495b92292a74b8d0a68201e541b545c11beea92e

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

module PagSeguro
  class Checkout
    include Restful

    def create(params)
      body = build_request(params).to_xml(encoding: "UTF-8")
      response = post("/v2/checkout", body, xml: :simple)
      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.3 lib/pagseguro/checkout.rb