Sha256: 5093808112289b69249825b97185f3f696e3accc60525dc6005ba7c20a70c24b

Contents?: true

Size: 1008 Bytes

Versions: 10

Compression:

Stored size: 1008 Bytes

Contents

module MyMoip
  class PaymentRequest < Request

    HTTP_METHOD   = :get
    PATH          = "/rest/pagamento?callback=?"
    REQUIRES_AUTH = false
    FORMAT        = :json

    def api_call(data, opts)
      opts[:referer_url] ||= MyMoip.default_referer_url
      opts[:parser]      ||= MyMoip::JsonParser

      json = JSON.generate({
        pagamentoWidget: {
          referer:        opts[:referer_url],
          token:          opts[:token],
          dadosPagamento: data.to_json
        }
      })

      params = {
        query:         { pagamentoWidget: json },
        http_method:   HTTP_METHOD,
        requires_auth: REQUIRES_AUTH,
        path:          PATH,
        format:        FORMAT
      }
      params[:parser] = opts.delete(:parser) unless opts[:parser].nil?

      super(params)
    end

    def success?
      @response && @response["StatusPagamento"] == "Sucesso"
    end

    def code
      @response["CodigoMoIP"]
    rescue NoMethodError => e
      nil
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mymoip-0.7.0 lib/mymoip/requests/payment_request.rb
mymoip-0.6.2 lib/mymoip/requests/payment_request.rb
mymoip-0.6.1 lib/mymoip/requests/payment_request.rb
mymoip-0.6.0 lib/mymoip/requests/payment_request.rb
mymoip-0.5.0 lib/mymoip/requests/payment_request.rb
mymoip-0.4.1 lib/mymoip/requests/payment_request.rb
mymoip-0.4.0 lib/mymoip/requests/payment_request.rb
mymoip-0.3.1 lib/mymoip/requests/payment_request.rb
mymoip-0.2.6 lib/mymoip/requests/payment_request.rb
mymoip-0.2.5 lib/mymoip/requests/payment_request.rb