Class: FatZebra::Purchase

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

#data, #errors, #raw, #successful

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperation::Find

find

Methods included from APIOperation::Search

search

Methods included from APIOperation::Void

included, #void

Methods included from APIOperation::Save

included, #save

Methods inherited from APIResource

class_name, #request, request, #resource_name, resource_name, resource_path, #resource_path

Methods inherited from FatZebraObject

#[], #[]=, #add_data, #initialize, initialize_from, #keys, #load_response_api, #to_hash, #to_json, #update_attributes, #update_from

Methods included from Validation

#errors, #valid!, #valid?, #validates

Constructor Details

This class inherits a constructor from FatZebra::FatZebraObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FatZebra::FatZebraObject

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:



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

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:



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

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

  params = Util.format_dates_in_hash(params)

  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



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

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

  response = request(:post, resource_path("purchases/#{id}/capture"), params, 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:



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

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