Sha256: 11150b54e4151b1419490c7b8b2203d96c26a13188adf9da681ec1bd44690048

Contents?: true

Size: 933 Bytes

Versions: 1

Compression:

Stored size: 933 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].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-1.0.1 lib/pagseguro/checkout.rb