Module: Opensteam::Payment::PaymentTransactionExtension

Defined in:
lib/opensteam/payment.rb

Overview

Default Extension for the PaymentTransaction Association in Opensteam::Payment::Base

create a new payment_transaction object, yields the given block and save the response of the block in the current-transaction. The given block must return either a string (which is save in the transaction#message attribute) or an object with the following attributes/methods:

success?, authorization, message, params

The PaymentTransaction Model is basically used to wrap the response of an ActiveMerchant Gateway. The first parameter for the block must be a gateway. (See ActiveMerchant#Gateways for more information.)

Instance Method Summary collapse

Instance Method Details

#process(*args) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/opensteam/payment.rb', line 34

def process *args 
  
  args = args.first if args.is_a? Array
  
  create do |t|
    
    t.action = args[:action]
    t.amount = args[:amount]
    
    begin
      response = yield t.payment.gateway
      
      if response.is_a? String
        t.message = response
        break
      end
      
      t.success   = response.success? 
      t.reference = response.authorization
      t.message   = response.message
      t.params    = response.params
      t.test      = t.payment.gateway ? t.payment.gateway.test? : true
      
    rescue ActiveMerchant::ActiveMerchantError => e
      t.success   = false
      t.reference = nil
      t.message   = e.message
      t.params    = {}
      t.test      = t.payment.gateway.test?
      
    end

  end

end