Class: FatZebra::Purchase

Inherits:
APIResource show all
Includes:
APIOperation::Find, APIOperation::Save, APIOperation::Search, APIOperation::Void
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

#accepted

Attributes included from ObjectHelper

#data, #errors, #raw

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperation::Void

included, #void

Methods included from APIOperation::Save

included, #save

Methods included from APIOperation::Search

included

Methods included from APIOperation::Find

included

Methods inherited from APIResource

base_path, request

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

Parameters:

  • params (Hash)
  • options (Hash) (defaults to: {})

    for the request, and configurations (Optional)

Returns:



44
45
46
47
48
# File 'lib/fat_zebra/purchase.rb', line 44

def create(params, options = {})
  params[:currency] ||= 'AUD'

  super(params, options)
end

.settlement(params = {}, options = {}) ⇒ FatZebra::Purchase

Return all the settlements

Parameters:

  • params (Hash) (defaults to: {})

    (from and to are date required)

  • options (Hash) (defaults to: {})

    for the request, and configurations (Optional)

Returns:



57
58
59
60
61
62
# File 'lib/fat_zebra/purchase.rb', line 57

def settlement(params = {}, options = {})
  valid!(params, :settlement) if respond_to?(:valid!)

  response = request(:get, "#{resource_path}/settlement", params, options)
  initialize_from(response)
end

Instance Method Details

#capture(params = {}, options = {}) ⇒ Response

Captures an authorization

Parameters:

  • params (Hash) (defaults to: {})

    for capture API (Optional)

  • options (Hash) (defaults to: {})

    for the request, and configurations (Optional)

Returns:

  • (Response)

    Purchase response object



88
89
90
91
92
93
94
95
# File 'lib/fat_zebra/purchase.rb', line 88

def capture(params = {}, options = {})
  params = {
    amount: amount
  }.merge(params)

  response = request(:post, resource_path("purchases/#{id}/capture"), params, options)
  update_from(response)
end

#extend!(options = {}) ⇒ Response

Extends an authorization expiry (if not already expired)

Parameters:

  • options (Hash) (defaults to: {})

    for the request, and configurations (Optional)

Returns:

  • (Response)

    Purchase response object



103
104
105
106
# File 'lib/fat_zebra/purchase.rb', line 103

def extend!(options = {})
  response = request(:put, resource_path("purchases/#{id}"), { extend: true }, options)
  update_from(response)
end

#increment!(additional_amount, options = {}) ⇒ Response

Increments an authorization amount

Parameters:

  • amount (Int)

    to increment the authorization by

  • options (Hash) (defaults to: {})

    for the request, and configurations (Optional)

Returns:

  • (Response)

    Purchase response object

Raises:

  • (ArgumentError)


115
116
117
118
119
120
# File 'lib/fat_zebra/purchase.rb', line 115

def increment!(additional_amount, options = {})
  raise ArgumentError, 'Amount must be a positive amount' unless additional_amount > 0

  response = request(:put, resource_path("purchases/#{id}"), { amount: amount + additional_amount }, options)
  update_from(response)
end

#refund(params = {}, options = {}) ⇒ FatZebra::Refund

Refunds the current purchase

Parameters:

  • params (Hash) (defaults to: {})

    for refund API (Optional)

  • options (Hash) (defaults to: {})

    for the request, and configurations (Optional)

Returns:



73
74
75
76
77
78
79
# File 'lib/fat_zebra/purchase.rb', line 73

def refund(params = {}, options = {})
  Refund.create({
    transaction_id: id,
    amount: amount,
    reference: reference
  }.merge(params), options)
end