Class: Epay::Transaction
- Inherits:
-
Object
- Object
- Epay::Transaction
- Includes:
- Model
- Defined in:
- lib/epay/transaction.rb
Instance Attribute Summary
Attributes included from Model
Class Method Summary collapse
-
.create(params) ⇒ Object
Epay::Transaction.create(:card_no => ‘1234…’, :cvc => ‘123’, :exp_month => ‘11’, :exp_year => ‘12’, :amount => ‘119’, :order_no => ‘ND-TEST’).
- .find(id) ⇒ Object
- .inspectable_attributes ⇒ Object
Instance Method Summary collapse
- #acquirer ⇒ Object
- #amount ⇒ Object
- #capture ⇒ Object
- #captured ⇒ Object (also: #captured?)
- #captured_amount ⇒ Object
- #captured_at ⇒ Object
- #card ⇒ Object
- #cardholder ⇒ Object
- #created_at ⇒ Object
- #credit(amount_to_be_credited = nil) ⇒ Object
- #credited_amount ⇒ Object
- #currency ⇒ Object
- #delete ⇒ Object
- #description ⇒ Object
- #error ⇒ Object
- #failed? ⇒ Boolean
- #group ⇒ Object
- #order_no ⇒ Object
- #permanent_error? ⇒ Boolean
- #production? ⇒ Boolean
-
#reload ⇒ Object
Actions.
- #success? ⇒ Boolean
- #temporary_error? ⇒ Boolean
- #test? ⇒ Boolean
Methods included from Model
#initialize, #inspect, inspect
Class Method Details
.create(params) ⇒ Object
Epay::Transaction.create(:card_no => ‘1234…’, :cvc => ‘123’, :exp_month => ‘11’, :exp_year => ‘12’, :amount => ‘119’, :order_no => ‘ND-TEST’)
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/epay/transaction.rb', line 139 def create(params) post = Api.default_post_for_params(params).merge({ :orderid => params[:order_no], :amount => params[:amount]*100, :currency => Epay::CURRENCY_CODES[(params[:currency] || Epay.default_currency).to_sym], :description => params[:description], :cardholder => params[:cardholder], :group => params[:group], :instantcapture => params[:instant_capture] ? '1' : '0' }) query = Api.(post) if query['accept'] # Find the transaction transaction = Transaction.find(query["tid"].to_i) else # Return a new transaction with error code filled new(nil, { 'failed' => true, 'error' => query["error"], 'orderid' => post[:orderid], 'authamount' => post[:amount], 'description' => post[:description], 'cardholder' => post[:cardholder], 'group' => post[:group], 'currency' => post[:currency] }) end end |
.find(id) ⇒ Object
132 133 134 135 |
# File 'lib/epay/transaction.rb', line 132 def find(id) transaction = new(id) transaction.reload end |
.inspectable_attributes ⇒ Object
5 6 7 |
# File 'lib/epay/transaction.rb', line 5 def self.inspectable_attributes %w(id amount created_at order_no description cardholder acquirer currency group captured) end |
Instance Method Details
#acquirer ⇒ Object
34 35 36 |
# File 'lib/epay/transaction.rb', line 34 def acquirer data['acquirer'] end |
#amount ⇒ Object
9 10 11 |
# File 'lib/epay/transaction.rb', line 9 def amount data['authamount'].to_f / 100 end |
#capture ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/epay/transaction.rb', line 102 def capture response = Epay::Api.request(PAYMENT_SOAP_URL, 'capture', :transactionid => id, :amount => (amount * 100).to_i) if response.success? reload true else false end end |
#captured ⇒ Object Also known as: captured?
62 63 64 |
# File 'lib/epay/transaction.rb', line 62 def captured !captured_at.nil? end |
#captured_amount ⇒ Object
51 52 53 |
# File 'lib/epay/transaction.rb', line 51 def captured_amount data['capturedamount'].to_f / 100 end |
#captured_at ⇒ Object
55 56 57 58 59 60 |
# File 'lib/epay/transaction.rb', line 55 def captured_at return nil if failed? time = Time.parse(data['captureddate'].to_s) time < created_at ? nil : time end |
#card ⇒ Object
42 43 44 45 |
# File 'lib/epay/transaction.rb', line 42 def card # We can find some card data in the history: @card ||= Card.new(:kind => CARD_KINDS[data['cardtypeid'].to_i], :number => data['tcardno'], :exp_year => data['expyear'].to_i, :exp_month => data['expmonth'].to_i) end |
#cardholder ⇒ Object
30 31 32 |
# File 'lib/epay/transaction.rb', line 30 def cardholder data['cardholder'] end |
#created_at ⇒ Object
13 14 15 16 |
# File 'lib/epay/transaction.rb', line 13 def created_at return nil if failed? Time.parse(data['authdate']) end |
#credit(amount_to_be_credited = nil) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/epay/transaction.rb', line 112 def credit(amount_to_be_credited = nil) amount_to_be_credited ||= amount - credited_amount Epay::Api.request(PAYMENT_SOAP_URL, 'credit', :transactionid => id, :amount => amount_to_be_credited * 100) do |response| if response.success? true else raise TransactionInGracePeriod if response.data['epayresponse'] == "-1021" false end end end |
#credited_amount ⇒ Object
47 48 49 |
# File 'lib/epay/transaction.rb', line 47 def credited_amount data['creditedamount'].to_f / 100 end |
#currency ⇒ Object
22 23 24 |
# File 'lib/epay/transaction.rb', line 22 def currency Epay::CURRENCY_CODES.key(data['currency']) end |
#delete ⇒ Object
126 127 128 |
# File 'lib/epay/transaction.rb', line 126 def delete Epay::Api.request(PAYMENT_SOAP_URL, 'delete', :transactionid => id).success? end |
#description ⇒ Object
26 27 28 |
# File 'lib/epay/transaction.rb', line 26 def description data['description'] end |
#error ⇒ Object
75 76 77 |
# File 'lib/epay/transaction.rb', line 75 def error data['error'] end |
#failed? ⇒ Boolean
71 72 73 |
# File 'lib/epay/transaction.rb', line 71 def failed? !!data['failed'] end |
#group ⇒ Object
38 39 40 |
# File 'lib/epay/transaction.rb', line 38 def group data['group'] end |
#order_no ⇒ Object
18 19 20 |
# File 'lib/epay/transaction.rb', line 18 def order_no data['orderid'] end |
#permanent_error? ⇒ Boolean
83 84 85 |
# File 'lib/epay/transaction.rb', line 83 def permanent_error? failed? && !temporary_error? end |
#production? ⇒ Boolean
91 92 93 |
# File 'lib/epay/transaction.rb', line 91 def production? !test? end |
#reload ⇒ Object
Actions
96 97 98 99 100 |
# File 'lib/epay/transaction.rb', line 96 def reload response = Epay::Api.request(PAYMENT_SOAP_URL, 'gettransaction', :transactionid => id) @data = response.data['transactionInformation'] self end |
#success? ⇒ Boolean
67 68 69 |
# File 'lib/epay/transaction.rb', line 67 def success? !failed? end |
#temporary_error? ⇒ Boolean
79 80 81 |
# File 'lib/epay/transaction.rb', line 79 def temporary_error? failed? && TEMPORARY_ERROR_CODES.include?(error) end |
#test? ⇒ Boolean
87 88 89 |
# File 'lib/epay/transaction.rb', line 87 def test? data['mode'] == 'MODE_EPAY' || data['mode'] == 'MODE_TEST' end |