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:



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

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:



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

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



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

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:



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

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