Sha256: 617c51ef50e01a19a0f4a9f6e65c49489a245dda782816daba8051308a599db8

Contents?: true

Size: 963 Bytes

Versions: 4

Compression:

Stored size: 963 Bytes

Contents

# frozen_string_literal: true

module PagSeguro
  class Plans
    include Restful

    def create(params)
      body = build_request(params).to_xml
      post("/pre-approvals/request", body, xml: :versioned)
    end

    def update(code, params)
      params[:amount_per_payment] = to_money params[:amount_per_payment]
      params = parameterize params

      put("/pre-approvals/request/#{code}/payment", params)
    end

    private
      def to_money(value)
        format "%.2f", value.to_f
      end

      def build_request(params)
        builder do
          preApprovalRequest do
            reference params[:reference]
            preApproval do
              charge params[:charge]
              name { cdata(params[:name]) }
              details { cdata(params[:details]) }
              period params[:period]
              amountPerPayment format("%.2f", params[:amount_per_payment])
            end
          end
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pagseguro_next-1.0.6 lib/pagseguro/plans.rb
pagseguro_next-1.0.5 lib/pagseguro/plans.rb
pagseguro_next-1.0.4 lib/pagseguro/plans.rb
pagseguro_next-1.0.3 lib/pagseguro/plans.rb