Class: FatZebra::Purchase
- Inherits:
-
APIResource
- Object
- FatZebraObject
- APIResource
- FatZebra::Purchase
- Defined in:
- lib/fat_zebra/purchase.rb
Overview
FatZebra Purchase
Manage purchase for the API
-
search
-
save
-
find
-
void
-
settlement
-
refund
-
capture
Constant Summary
Constants included from APIOperation::Search
APIOperation::Search::DEFAULT_PARAMS
Instance Attribute Summary
Attributes inherited from FatZebraObject
Attributes included from ObjectHelper
Class Method Summary collapse
-
.create(params, options = {}) ⇒ FatZebra::PaymentPlan
Create a payment plan Default currency to AUD.
-
.settlement(params = {}, options = {}) ⇒ FatZebra::Purchase
Return all the settlements.
Instance Method Summary collapse
-
#capture(params = {}, options = {}) ⇒ Response
Captures an authorization.
-
#extend!(options = {}) ⇒ Response
Extends an authorization expiry (if not already expired).
-
#increment!(additional_amount, options = {}) ⇒ Response
Increments an authorization amount.
-
#refund(params = {}, options = {}) ⇒ FatZebra::Refund
Refunds the current purchase.
Methods included from APIOperation::Void
Methods included from APIOperation::Save
Methods included from APIOperation::Search
Methods included from APIOperation::Find
Methods inherited from APIResource
Methods included from APIHelper
included, #request, #resource_name, #resource_path
Methods inherited from FatZebraObject
initialize_from, #load_response_api, #update_from
Methods included from Validation
#errors, #valid!, #valid?, #validates
Methods included from ObjectHelper
#[], #[]=, #add_accessor, #add_accessors, #add_data, #initialize, #inspect, #keys, #method_missing, #remove_accessor, #to_hash, #to_json, #update_attributes
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FatZebra::ObjectHelper
Class Method Details
.create(params, options = {}) ⇒ FatZebra::PaymentPlan
Create a payment plan Default currency to AUD
44 45 46 47 48 |
# File 'lib/fat_zebra/purchase.rb', line 44 def create(params, = {}) params[:currency] ||= 'AUD' super(params, ) end |
.settlement(params = {}, options = {}) ⇒ FatZebra::Purchase
Return all the settlements
57 58 59 60 61 62 |
# File 'lib/fat_zebra/purchase.rb', line 57 def settlement(params = {}, = {}) valid!(params, :settlement) if respond_to?(:valid!) response = request(:get, "#{resource_path}/settlement", params, ) initialize_from(response) end |
Instance Method Details
#capture(params = {}, options = {}) ⇒ Response
Captures an authorization
88 89 90 91 92 93 94 95 |
# File 'lib/fat_zebra/purchase.rb', line 88 def capture(params = {}, = {}) params = { amount: amount }.merge(params) response = request(:post, resource_path("purchases/#{id}/capture"), params, ) update_from(response) end |
#extend!(options = {}) ⇒ Response
Extends an authorization expiry (if not already expired)
103 104 105 106 |
# File 'lib/fat_zebra/purchase.rb', line 103 def extend!( = {}) response = request(:put, resource_path("purchases/#{id}"), { extend: true }, ) update_from(response) end |
#increment!(additional_amount, options = {}) ⇒ Response
Increments an authorization amount
115 116 117 118 119 120 |
# File 'lib/fat_zebra/purchase.rb', line 115 def increment!(additional_amount, = {}) raise ArgumentError, 'Amount must be a positive amount' unless additional_amount > 0 response = request(:put, resource_path("purchases/#{id}"), { amount: amount + additional_amount }, ) update_from(response) end |
#refund(params = {}, options = {}) ⇒ FatZebra::Refund
Refunds the current purchase
73 74 75 76 77 78 79 |
# File 'lib/fat_zebra/purchase.rb', line 73 def refund(params = {}, = {}) Refund.create({ transaction_id: id, amount: amount, reference: reference }.merge(params), ) end |