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::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, supported_countries, #supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #test?

Methods included from CreditCardFormatting

#expdate, #format

Methods included from PostsData

included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request

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 hash of options:

:store - Retain the payment method if the authorize
         succeeds.  Defaults to false.  (optional)

54
55
56
57
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 54

def authorize(money, payment_method, options = {})
  request = build_transaction_request(money, payment_method, options)
  commit("gateways/#{@options[:gateway_token]}/authorize.xml", request)
end

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


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

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

#find(transaction_token) ⇒ Object Also known as: status

Public: Get the transaction with the given token.


116
117
118
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 116

def find(transaction_token)
  commit("transactions/#{transaction_token}.xml", nil, :get)
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 Check or the Spreedly payment method token. options - A hash of options:

:store - Retain the payment method if the purchase
         succeeds.  Defaults to false.  (optional)

42
43
44
45
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 42

def purchase(money, payment_method, options = {})
  request = build_transaction_request(money, payment_method, options)
  commit("gateways/#{options[:gateway_token] || @options[:gateway_token]}/purchase.xml", request)
end

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


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

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

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

#scrub(transcript) ⇒ Object


126
127
128
129
130
131
132
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 126

def scrub(transcript)
  transcript.
    gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
    gsub(%r((<number>).+(</number>)), '\1[FILTERED]\2').
    gsub(%r((<verification_value>).+(</verification_value>)), '\1[FILTERED]\2').
    gsub(%r((<payment_method_token>).+(</payment_method_token>)), '\1[FILTERED]\2')
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


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

def store(credit_card, options = {})
  retain = (options.has_key?(:retain) ? options[:retain] : true)
  save_card(retain, credit_card, options)
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)

122
123
124
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 122

def supports_scrubbing?
  true
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


111
112
113
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 111

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

#verify(payment_method, options = {}) ⇒ Object

Public: Determine whether a credit card is chargeable card and available for purchases.

payment_method - The CreditCard or the Spreedly payment method token. options - A hash of options:

:store - Retain the payment method if the verify
         succeeds.  Defaults to false.  (optional)

86
87
88
89
90
91
92
93
94
95
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 86

def verify(payment_method, options = {})
  if payment_method.is_a?(String)
    verify_with_token(payment_method, options)
  else
    MultiResponse.run do |r|
      r.process { save_card(options[:store], payment_method, options) }
      r.process { verify_with_token(r.authorization, options) }
    end
  end
end

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


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

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