Class: ActiveMerchant::Billing::RedsysGateway
- Defined in:
- lib/active_merchant/billing/gateways/redsys.rb
Overview
Redsys Merchant Gateway
Gateway support for the Spanish “Redsys” payment gateway system. This is used by many banks in Spain and is particularly well supported by Catalunya Caixa’s ecommerce department.
Standard ActiveMerchant methods are supported, with one notable exception: :order_id must be provided and must conform to a very specific format.
Example use:
gateway = ActiveMerchant::Billing::RedsysGateway.new(
:login => "091358382",
:secret_key => "qwertyasdf0123456789"
)
# Run a purchase for 10 euros
response = gateway.purchase(1000, creditcard, :order_id => "123456")
puts reponse.success? # => true
# Partially refund the purchase
response = gateway.refund(500, response.)
Redsys requires an order_id be provided with each transaction of a specific format. The rules are as follows:
* Minimum length: 4
* Maximum length: 12
* First 4 digits must be numerical
* Remaining 8 digits may be alphanumeric
Much of the code for this library is based on the active_merchant_sermepa integration gateway which uses essentially the same API but with the banks own payment screen.
Written by Samuel Lown for Cabify. For implementation questions, or test access details please get in touch: [email protected].
Constant Summary collapse
- CURRENCY_CODES =
{ "ARS" => '032', "AUD" => '036', "BRL" => '986', "BOB" => '068', "CAD" => '124', "CHF" => '756', "CLP" => '152', "COP" => '170', "EUR" => '978', "GBP" => '826', "GTQ" => '320', "JPY" => '392', "MXN" => '484', "NZD" => '554', "PEN" => '604', "RUB" => '643', "USD" => '840', "UYU" => '858' }
- SUPPORTED_TRANSACTIONS =
The set of supported transactions for this gateway. More operations are supported by the gateway itself, but are not supported in this library.
{ :purchase => 'A', :authorize => '1', :capture => '2', :refund => '3', :cancel => '9' }
- RESPONSE_TEXTS =
These are the text meanings sent back by the acquirer when a card has been rejected. Syntax or general request errors are not covered here.
{ # Accepted Codes 0 => "Transaction Approved", 400 => "Cancellation Accepted", 481 => "Cancellation Accepted", 500 => "Reconciliation Accepted", 900 => "Refund / Confirmation approved", # Declined error codes 101 => "Card expired", 102 => "Card blocked temporarily or under susciption of fraud", 104 => "Transaction not permitted", 107 => "Contact the card issuer", 109 => "Invalid identification by merchant or POS terminal", 110 => "Invalid amount", 114 => "Card cannot be used to the requested transaction", 116 => "Insufficient credit", 118 => "Non-registered card", 125 => "Card not effective", 129 => "CVV2/CVC2 Error", 167 => "Contact the card issuer: suspected fraud", 180 => "Card out of service", 181 => "Card with credit or debit restrictions", 182 => "Card with credit or debit restrictions", 184 => "Authentication error", 190 => "Refusal with no specific reason", 191 => "Expiry date incorrect", # Declined, and suspected of fraud 201 => "Card expired", 202 => "Card blocked temporarily or under suscipition of fraud", 204 => "Transaction not permitted", 207 => "Contact the card issuer", 208 => "Lost or stolen card", 209 => "Lost or stolen card", 280 => "CVV2/CVC2 Error", 290 => "Declined with no specific reason", # More general codes for specific types of transaction 480 => "Original transaction not located, or time-out exceeded", 501 => "Original transaction not located, or time-out exceeded", 502 => "Original transaction not located, or time-out exceeded", 503 => "Original transaction not located, or time-out exceeded", # Declined transactions by the bank 904 => "Merchant not registered at FUC", 909 => "System error", 912 => "Issuer not available", 913 => "Duplicate transmission", 916 => "Amount too low", 928 => "Time-out exceeded", 940 => "Transaction cancelled previously", 941 => "Authorization operation already cancelled", 942 => "Original authorization declined", 943 => "Different details from origin transaction", 944 => "Session error", 945 => "Duplicate transmission", 946 => "Cancellation of transaction while in progress", 947 => "Duplicate tranmission while in progress", 949 => "POS Inoperative", 950 => "Refund not possible", 9064 => "Card number incorrect", 9078 => "No payment method available", 9093 => "Non-existent card", 9218 => "Recursive transaction in bad gateway", 9253 => "Check-digit incorrect", 9256 => "Preauth not allowed for merchant", 9257 => "Preauth not allowed for card", 9261 => "Operating limit exceeded", 9912 => "Issuer not available", 9913 => "Confirmation error", 9914 => "KO Confirmation" }
Constants inherited from Gateway
Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::CURRENCIES_WITHOUT_FRACTIONS, Gateway::DEBIT_CARDS
Instance Attribute Summary
Attributes inherited from Gateway
Instance Method Summary collapse
- #authorize(money, creditcard, options = {}) ⇒ Object
- #capture(money, authorization, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ RedsysGateway
constructor
Creates a new instance.
- #purchase(money, creditcard, options = {}) ⇒ Object
- #refund(money, authorization, options = {}) ⇒ Object
- #void(authorization, options = {}) ⇒ Object
Methods inherited from Gateway
#card_brand, card_brand, inherited, supports?, #test?
Methods included from CreditCardFormatting
Constructor Details
#initialize(options = {}) ⇒ RedsysGateway
Creates a new instance
Redsys requires a login and secret_key, and optionally also accepts a non-default terminal.
Options
-
:login
– The Redsys Merchant ID (REQUIRED) -
:secret_key
– The Redsys Secret Key. (REQUIRED) -
:terminal
– The Redsys Terminal. Defaults to 1. (OPTIONAL) -
:test
–true
orfalse
. Defaults tofalse
. (OPTIONAL)
181 182 183 184 185 |
# File 'lib/active_merchant/billing/gateways/redsys.rb', line 181 def initialize( = {}) requires!(, :login, :secret_key) [:terminal] ||= 1 super end |
Instance Method Details
#authorize(money, creditcard, options = {}) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/active_merchant/billing/gateways/redsys.rb', line 199 def (money, creditcard, = {}) requires!(, :order_id) data = {} add_action(data, :authorize) add_amount(data, money, ) add_order(data, [:order_id]) add_creditcard(data, creditcard) commit data end |
#capture(money, authorization, options = {}) ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/active_merchant/billing/gateways/redsys.rb', line 211 def capture(money, , = {}) data = {} add_action(data, :capture) add_amount(data, money, ) order_id, _, _ = () add_order(data, order_id) commit data end |
#purchase(money, creditcard, options = {}) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/active_merchant/billing/gateways/redsys.rb', line 187 def purchase(money, creditcard, = {}) requires!(, :order_id) data = {} add_action(data, :purchase) add_amount(data, money, ) add_order(data, [:order_id]) add_creditcard(data, creditcard) commit data end |
#refund(money, authorization, options = {}) ⇒ Object
231 232 233 234 235 236 237 238 239 |
# File 'lib/active_merchant/billing/gateways/redsys.rb', line 231 def refund(money, , = {}) data = {} add_action(data, :refund) add_amount(data, money, ) order_id, _, _ = () add_order(data, order_id) commit data end |
#void(authorization, options = {}) ⇒ Object
221 222 223 224 225 226 227 228 229 |
# File 'lib/active_merchant/billing/gateways/redsys.rb', line 221 def void(, = {}) data = {} add_action(data, :cancel) order_id, amount, currency = () add_amount(data, amount, :currency => currency) add_order(data, order_id) commit data end |