Class: ActiveMerchant::Billing::SpreedlyCoreGateway

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_merchant/billing/gateways/spreedly_core.rb

Overview

Public: This gateway allows you to interact with any gateway you’ve created in Spreedly (spreedly.com). It’s an adapter which can be particularly useful if you already have code interacting with ActiveMerchant and want to easily take advantage of Spreedly’s vault.

Constant Summary

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#card_brand, card_brand, inherited, supports?, #test?

Methods included from CreditCardFormatting

#format

Constructor Details

#initialize(options = {}) ⇒ SpreedlyCoreGateway

Public: Create a new Spreedly gateway.

options - A hash of options:

:login         - The environment key.
:password      - The access secret.
:gateway_token - The token of the gateway you've created in
                 Spreedly.


30
31
32
33
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 30

def initialize(options = {})
  requires!(options, :login, :password, :gateway_token)
  super
end

Instance Method Details

#authorize(money, payment_method, options = {}) ⇒ Object

Public: Run an authorize transaction.

money - The monetary amount of the transaction in cents. payment_method - The CreditCard or the Spreedly payment method token. options - A standard ActiveMerchant options hash



56
57
58
59
60
61
62
63
64
65
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 56

def authorize(money, payment_method, options = {})
  if payment_method.is_a?(String)
    authorize_with_token(money, payment_method, options)
  else
    MultiResponse.run do |r|
      r.process { save_card(false, payment_method, options) }
      r.process { authorize_with_token(money, r.authorization, options) }
    end
  end
end

#capture(money, authorization, options = {}) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 67

def capture(money, authorization, options={})
  request = build_xml_request('transaction') do |doc|
    add_invoice(doc, money, options)
  end

  commit("transactions/#{authorization}/capture.xml", request)
end

#purchase(money, payment_method, options = {}) ⇒ Object

Public: Run a purchase transaction.

money - The monetary amount of the transaction in cents. payment_method - The CreditCard or the Spreedly payment method token. options - A standard ActiveMerchant options hash



40
41
42
43
44
45
46
47
48
49
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 40

def purchase(money, payment_method, options = {})
  if payment_method.is_a?(String)
    purchase_with_token(money, payment_method, options)
  else
    MultiResponse.run do |r|
      r.process { save_card(false, payment_method, options) }
      r.process { purchase_with_token(money, r.authorization, options) }
    end
  end
end

#refund(money, authorization, options = {}) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 75

def refund(money, authorization, options={})
  request = build_xml_request('transaction') do |doc|
    add_invoice(doc, money, options)
  end

  commit("transactions/#{authorization}/credit.xml", request)
end

#store(credit_card, options = {}) ⇒ Object

Public: Store a credit card in the Spreedly vault and retain it.

credit_card - The CreditCard to store options - A standard ActiveMerchant options hash



91
92
93
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 91

def store(credit_card, options={})
  save_card(true, credit_card, options)
end

#unstore(authorization, options = {}) ⇒ Object

Public: Redact the CreditCard in Spreedly. This wipes the sensitive

payment information from the card.

credit_card - The CreditCard to store options - A standard ActiveMerchant options hash



100
101
102
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 100

def unstore(authorization, options={})
  commit("payment_methods/#{authorization}/redact.xml", '', :put)
end

#void(authorization, options = {}) ⇒ Object



83
84
85
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 83

def void(authorization, options={})
  commit("transactions/#{authorization}/void.xml", '')
end