Class: ActiveMerchant::Billing::SpreedlyCoreGateway
- 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 collapse
- SUCCESS_CODE =
200- SOFT_DECLINE_CODES =
[401, 402, 408, 415, 422].freeze
Constants inherited from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE
Instance Attribute Summary
Attributes inherited from Gateway
Instance Method Summary collapse
-
#authorize(money, payment_method, options = {}) ⇒ Object
Public: Run an authorize transaction.
- #capture(money, authorization, options = {}) ⇒ Object
- #deliver(receiver_token, request) ⇒ Object
-
#find(transaction_token) ⇒ Object
(also: #status)
Public: Get the transaction with the given token.
-
#initialize(options = {}) ⇒ SpreedlyCoreGateway
constructor
Public: Create a new Spreedly gateway.
-
#purchase(money, payment_method, options = {}) ⇒ Object
Public: Run a purchase transaction.
- #refund(money, authorization, options = {}) ⇒ Object
- #scrub(transcript) ⇒ Object
-
#store(credit_card, options = {}) ⇒ Object
Public: Store a credit card in the Spreedly vault and retain it.
- #supports_scrubbing? ⇒ Boolean
-
#unstore(authorization, options = {}) ⇒ Object
Public: Redact the CreditCard in Spreedly.
-
#verify(payment_method, options = {}) ⇒ Object
Public: Determine whether a credit card is chargeable card and available for purchases.
- #void(authorization, options = {}) ⇒ Object
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
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.
33 34 35 36 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 33 def initialize( = {}) requires!(, :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)
57 58 59 60 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 57 def (money, payment_method, = {}) request = build_transaction_request(money, payment_method, ) commit("gateways/#{@options[:gateway_token]}/authorize.xml", request) end |
#capture(money, authorization, options = {}) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 62 def capture(money, , = {}) request = build_xml_request('transaction') do |doc| add_invoice(doc, money, ) end commit("transactions/#{}/capture.xml", request) end |
#deliver(receiver_token, request) ⇒ Object
123 124 125 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 123 def deliver(receiver_token, request) commit("receivers/#{receiver_token}/deliver.xml", request) end |
#find(transaction_token) ⇒ Object Also known as: status
Public: Get the transaction with the given token.
119 120 121 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 119 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)
45 46 47 48 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 45 def purchase(money, payment_method, = {}) request = build_transaction_request(money, payment_method, ) commit("gateways/#{[:gateway_token] || @options[:gateway_token]}/purchase.xml", request) end |
#refund(money, authorization, options = {}) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 70 def refund(money, , = {}) request = build_xml_request('transaction') do |doc| add_invoice(doc, money, ) (:gateway_specific_fields, doc, ) end commit("transactions/#{}/credit.xml", request) end |
#scrub(transcript) ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 133 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
104 105 106 107 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 104 def store(credit_card, = {}) retain = true save_card(retain, credit_card, ) end |
#supports_scrubbing? ⇒ Boolean
129 130 131 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 129 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
114 115 116 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 114 def unstore(, = {}) commit("payment_methods/#{}/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)
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 89 def verify(payment_method, = {}) if payment_method.is_a?(String) verify_with_token(payment_method, ) else MultiResponse.run do |r| r.process { save_card([:store], payment_method, ) } r.process { verify_with_token(r., ) } end end end |
#void(authorization, options = {}) ⇒ Object
79 80 81 |
# File 'lib/active_merchant/billing/gateways/spreedly_core.rb', line 79 def void(, = {}) commit("transactions/#{}/void.xml", '') end |