Class: FatZebra::Models::Purchase
- Defined in:
- lib/fat_zebra/models/purchase.rb
Class Method Summary collapse
-
.create(amount, card_data, reference, customer_ip, currency = 'AUD', optional = {}) ⇒ Response
Performs a purchase transaction against the gateway.
-
.find(options = {}) ⇒ Array<Purchase>
Retrieves purchases specified by the options hash.
Instance Method Summary collapse
-
#refund(amount, reference) ⇒ Object
Refunds the current transaction.
-
#to_hash ⇒ Hash
Returns the record as a Hash.
Methods inherited from Base
attribute, #initialize, #inspect, #to_s
Constructor Details
This class inherits a constructor from FatZebra::Models::Base
Class Method Details
.create(amount, card_data, reference, customer_ip, currency = 'AUD', optional = {}) ⇒ Response
Performs a purchase transaction against the gateway
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/fat_zebra/models/purchase.rb', line 59 def create(amount, card_data, reference, customer_ip, currency = 'AUD', optional = {}) params = { :amount => amount, :card_holder => card_data.delete(:card_holder), :card_number => card_data.delete(:number), :card_expiry => extract_date(card_data.delete(:expiry)), :cvv => card_data.delete(:cvv), :card_token => card_data.delete(:token), :reference => reference, :customer_ip => customer_ip, :currency => currency } params.delete_if {|_, value| value.nil? } # If token is nil, remove, otherwise, remove card values params.merge!(optional) validate_params!(params) response = FatZebra.gateway.make_request(:post, 'purchases', params) Response.new(response) end |
.find(options = {}) ⇒ Array<Purchase>
Retrieves purchases specified by the options hash
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fat_zebra/models/purchase.rb', line 90 def find( = {}) id = .delete(:id) .merge!({:offets => 0, :limit => 10}) # Format dates for the request [:from] = [:from].strftime('%Y%m%dT%H%M') if [:from] [:to] = [:to].strftime('%Y%m%dT%H%M') if [:to] if id.nil? response = FatZebra.gateway.make_request(:get, 'purchases', ) if response['successful'] purchases = [] response['response'].each do |purchase| purchases << Purchase.new(purchase) end purchases.size == 1 ? purchases.first : purchases else # TODO: This should raise a defined exception raise StandardError, "Unable to query purchases, #{response['errors'].inspect}" end else response = FatZebra.gateway.make_request(:get, "purchases/#{id}.json") if response['successful'] Purchase.new(response['response']) else raise StandardError, "Unable to query purchases, #{response['errors'].inspect}" end end end |
Instance Method Details
#refund(amount, reference) ⇒ Object
Refunds the current transaction
14 15 16 |
# File 'lib/fat_zebra/models/purchase.rb', line 14 def refund(amount, reference) Refund.create(self.id, amount, reference) end |
#to_hash ⇒ Hash
Returns the record as a Hash
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fat_zebra/models/purchase.rb', line 21 def to_hash { id: self.id, amount: self.amount, reference: self.reference, message: self., authorization: self., card_number: self.card_number, card_holder: self.card_holder, card_expiry: self.card_expiry, card_token: self.card_token, currency: self.currency, authorized: self., successful: self.successful, captured: self.captured, response_code: self.response_code, cvv_match: self.cvv_match, rrn: self.rrn, fraud_result: self.fraud_result, fraud_messages: self. } end |