Class: SpookAndPay::Providers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/spook_and_pay/providers/base.rb

Overview

The abstract class from which other Provider classes should inherit. This class is intended to behave more as a template than anything else. It provides very little in the way of actual implementation.

To implement a provider all of the public methods of this class — excluding #initialize — must be implemented.

Some features may not be supported by a provider, in which case the ‘NotSupportedError` should be raised in lieu of a real implementation.

Direct Known Subclasses

Braintree, Spreedly

Defined Under Namespace

Classes: InvalidOptionsError, NotSupportedError

Constant Summary collapse

FORM_FIELD_NAMES =

A hash which maps between the fields for a credit card and the actual form field names required by the provider.

It should be over-ridden per provider.

{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env, config) ⇒ Object

Returns nil.

Parameters:

  • env (:production, :development, :test)
  • Hash

    config



49
50
51
52
53
54
# File 'lib/spook_and_pay/providers/base.rb', line 49

def initialize(env, config)
  @environment = env
  @config = config

  nil
end

Instance Attribute Details

#configObject (readonly)

Basic attributes



43
44
45
# File 'lib/spook_and_pay/providers/base.rb', line 43

def config
  @config
end

#environmentObject (readonly)

Basic attributes



43
44
45
# File 'lib/spook_and_pay/providers/base.rb', line 43

def environment
  @environment
end

Instance Method Details

#authorize_via_credit_card(id, amount) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Subclass to implement

Authorizes a payment against a credit card

This should not be called directly. Instead, use the #authorize! method provided by a CreditCard instance.

Parameters:

Returns:

  • SpookAndPay::Result



241
242
243
# File 'lib/spook_and_pay/providers/base.rb', line 241

def authorize_via_credit_card(id, amount)
  check_support('authorize')
end

#capture_transaction(id) ⇒ Object

Captures funds that have been pre-authorized.

This should not be called directly. Instead, use the #capture! method provided by a Transaction instance.

Parameters:

Returns:

  • SpookAndPay::Result



120
121
122
# File 'lib/spook_and_pay/providers/base.rb', line 120

def capture_transaction(id)
  check_support('capture')
end

#confirm_payment_submission(*args) ⇒ Object

Confirms the submission of payment details to the provider.

The arguments for this method are specific to a provider.

Raises:

  • (NotImplementedError)


109
110
111
# File 'lib/spook_and_pay/providers/base.rb', line 109

def confirm_payment_submission(*args)
  raise NotImplementedError
end

#credit_card(id) ⇒ SpookAndPay::CreditCard?

Retrieves the payment method details from the provider’s vault.

Parameters:

  • String

    id

Returns:

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/spook_and_pay/providers/base.rb', line 61

def credit_card(id)
  raise NotImplementedError
end

#credit_card_from_transaction(transaction_or_id) ⇒ SpookAndPay::CreditCard?

Retrieves a credit card from the provider based on the transaction or transaction id provided. Some providers may not support this action.

Parameters:

Returns:

Raises:



70
71
72
# File 'lib/spook_and_pay/providers/base.rb', line 70

def credit_card_from_transaction(transaction_or_id)
  raise NotSupportedError
end

#credit_via_credit_card(id, amount) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Subclass to implement

Credits funds to a credit card

This should not be called directly. Instead, use the #authorize! method provided by a CreditCard instance.

Parameters:

Returns:

  • SpookAndPay::Result



255
256
257
# File 'lib/spook_and_pay/providers/base.rb', line 255

def credit_via_credit_card(id, amount)
  check_support('credit')
end

#delete_credit_card(id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Subclass to implement

Removes payment details from the provider’s vault.

This should not be called directly. Instead, use the #delete! method provided by a CreditCard instance.

Parameters:

Returns:

  • SpookAndPay::Result



282
283
284
# File 'lib/spook_and_pay/providers/base.rb', line 282

def delete_credit_card(id)
  check_support('delete')
end

#partially_refund_transaction(id) ⇒ Object

Partially refunds the amount of money captured in a transaction.

This should not be called directly. Instead, use the #partial_refund! method provided by a Transaction instance.

Parameters:

Returns:

  • SpookAndPay::Result



142
143
144
# File 'lib/spook_and_pay/providers/base.rb', line 142

def partially_refund_transaction(id)
  check_support('partial_refund')
end

#prepare_payment_submission(*args) ⇒ Object

Returns a hash containing the details necessary for making a submission. If you know what you’re doing, you can use this directly, but otherwise you should be using the form helpers.

The details generated by this method are for submitting card details to the provider for storage. Billing etc has to be handled via a separate step after submission.

The arguments for this are specific to each provider implementation, but they all return a Hash with the same keys, like so:

{
  :url => "...",
  :hidden_fields => {...},
  :field_names => {...}
}

Where :url is the target URL, :hidden_fields should be embedded in a form as they are and :field_names provide the mapping between known keys like :number and :cvv to the input names required by the provider.

Raises:

  • (NotImplementedError)


102
103
104
# File 'lib/spook_and_pay/providers/base.rb', line 102

def prepare_payment_submission(*args)
  raise NotImplementedError
end

#purchase_via_credit_card(id, amount) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Subclass to implement

Creates a purchase against a credit card.

This should not be called directly. Instead, use the #purchase! method provided by a CreditCard instance.

Parameters:

Returns:

  • SpookAndPay::Result



269
270
271
# File 'lib/spook_and_pay/providers/base.rb', line 269

def purchase_via_credit_card(id, amount)
  check_support('purchase')
end

#refund_transaction(id) ⇒ Object

Refunds the amount of money captured in a transaction.

This should not be called directly. Instead, use the #refund! method provided by a Transaction instance.

Parameters:

Returns:

  • SpookAndPay::Result



131
132
133
# File 'lib/spook_and_pay/providers/base.rb', line 131

def refund_transaction(id)
  check_support('refund')
end

#retain_credit_card(id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Subclass to implement

Retains a credit card within the provider’s vault.

This should not be called directly. Instead, use the #retain! method provided by a CreditCard instance.

Parameters:

Returns:

  • SpookAndPay::Result



295
296
297
# File 'lib/spook_and_pay/providers/base.rb', line 295

def retain_credit_card(id)
  check_support('retain')
end

#supports_authorize?true, false

Checks to see if authorizing is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


205
206
207
# File 'lib/spook_and_pay/providers/base.rb', line 205

def supports_authorize?
  true
end

#supports_capture?true, false

Checks to see if capturing is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


196
197
198
# File 'lib/spook_and_pay/providers/base.rb', line 196

def supports_capture?
  true
end

#supports_credit?true, false

Checks to see if crediting is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


169
170
171
# File 'lib/spook_and_pay/providers/base.rb', line 169

def supports_credit?
  true
end

#supports_delete?true, false

Checks to see if the deletion of payment details is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


214
215
216
# File 'lib/spook_and_pay/providers/base.rb', line 214

def supports_delete?
  true
end

#supports_partial_refund?true, false

Checks to see if partial refunding is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


187
188
189
# File 'lib/spook_and_pay/providers/base.rb', line 187

def supports_partial_refund?
  true
end

#supports_purchase?true, false

Checks to see if purchasing is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


151
152
153
# File 'lib/spook_and_pay/providers/base.rb', line 151

def supports_purchase?
  true
end

#supports_refund?true, false

Checks to see if refunding is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


178
179
180
# File 'lib/spook_and_pay/providers/base.rb', line 178

def supports_refund?
  true
end

#supports_void?true, false

Checks to see if voiding is supported. This is dependent on the payment provider. The default implementation simply returns true. Specific implementations should over-ride this method.

Returns:

  • (true, false)


160
161
162
# File 'lib/spook_and_pay/providers/base.rb', line 160

def supports_void?
  true
end

#transaction(id) ⇒ SpookAndPay::Transaction?

Retrieves the transaction details from the provider’s vault.

Parameters:

  • String

    id

Returns:

Raises:

  • (NotImplementedError)


79
80
81
# File 'lib/spook_and_pay/providers/base.rb', line 79

def transaction(id)
  raise NotImplementedError
end

#void_transaction(id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Subclass to implement

Voids an authorization.

This should not be called directly. Instead, use the #void! method provided by a Transaction instance.

Parameters:

Returns:

  • SpookAndPay::Result



227
228
229
# File 'lib/spook_and_pay/providers/base.rb', line 227

def void_transaction(id)
  check_support('void')
end