class Paymongo::TransactionGateway

Public Class Methods

new(gateway) click to toggle source
# File lib/paymongo/transaction_gateway.rb, line 3
def initialize(gateway)
  @gateway = gateway
  @config = gateway.config
  @config.assert_has_keys
end

Public Instance Methods

_do_create(path, params = nil) click to toggle source
# File lib/paymongo/transaction_gateway.rb, line 30
def _do_create(path, params = nil)
  response = @config.https.post("#{@config.base_url}#{path}", params)
  _handle_transaction_response(response)
end
_handle_transaction_response(response) click to toggle source
# File lib/paymongo/transaction_gateway.rb, line 35
def _handle_transaction_response(response)
  if response[:data]
    SuccessfulResult.new(
      transaction: Transaction._new(@gateway, response[:data])
    )
  elsif response[:errors]
    ErrorResult.new(@gateway, response[:errors])
  else
    raise UnexpectedError, 'expected :data'
  end
end
create(attributes) click to toggle source
# File lib/paymongo/transaction_gateway.rb, line 26
def create(attributes)
  _do_create '/payments', transaction: attributes
end
sale(attributes) click to toggle source
# File lib/paymongo/transaction_gateway.rb, line 9
def sale(attributes)
  # Wrap the hash
  create(
    {
      data: {
        attributes: {
          amount: attributes[:amount],
          currency: attributes[:currency],
          description: attributes[:description],
          statement_descriptor: attributes[:statement_descriptor],
          source: { id: attributes[:token], type: 'token' }
        }
      }
    }
  )
end