Class: ActiveMerchant::Billing::CyberSourceGateway

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

Overview

Initial setup instructions can be found in apps.cybersource.com/library/documentation/dev_guides/SOAP_Toolkits/SOAP_toolkits.pdf

Important Notes

  • For checks you can purchase and store.

  • AVS and CVV only work against the production server. You will always get back X for AVS and no response for CVV against the test server.

  • Nexus is the list of states or provinces where you have a physical presence. Nexus is used to calculate tax. Leave blank to tax everyone.

  • If you want to calculate VAT for overseas customers you must supply a registration number in the options hash as vat_reg_number.

  • productCode is a value in the line_items hash that is used to tell CyberSource what kind of item you are selling. It is used when calculating tax/VAT.

  • All transactions use dollar values.

  • The order of the XML elements does matter, make sure to follow the order in the documentation exactly.

Constant Summary collapse

TEST_XSD_VERSION =

Schema files can be found here: ics2ws.ic3.com/commerce/1.x/transactionProcessor/

'1.201'
PRODUCTION_XSD_VERSION =
'1.201'
ECI_BRAND_MAPPING =
{
  visa: 'vbv',
  master: 'spa',
  maestro: 'spa',
  american_express: 'aesk',
  jcb: 'js',
  discover: 'pb',
  diners_club: 'pb'
}.freeze
THREEDS_EXEMPTIONS =
{
  authentication_outage: 'authenticationOutageExemptionIndicator',
  corporate_card: 'secureCorporatePaymentIndicator',
  delegated_authentication: 'delegatedAuthenticationExemptionIndicator',
  low_risk: 'riskAnalysisExemptionIndicator',
  low_value: 'lowValueExemptionIndicator',
  trusted_merchant: 'trustedMerchantExemptionIndicator'
}
DEFAULT_COLLECTION_INDICATOR =
2
NT_PAYMENT_SOLUTION =
{
  'master' => '014',
  'visa' => '015'
}
@@credit_card_codes =
{
  visa: '001',
  master: '002',
  american_express: '003',
  discover: '004',
  diners_club: '005',
  jcb: '007',
  dankort: '034',
  maestro: '042',
  elo: '054',
  carnet: '002'
}
@@decision_codes =
{
  accept: 'ACCEPT',
  review: 'REVIEW'
}
@@response_codes =
{
  r100: 'Successful transaction',
  r101: 'Request is missing one or more required fields',
  r102: 'One or more fields contains invalid data',
  r104: 'The merchantReferenceCode sent with this authorization request matches the merchantReferenceCode of another authorization request that you sent in the last 15 minutes.', r110: 'Partial amount was approved',
  r150: 'General failure',
  r151: 'The request was received but a server time-out occurred',
  r152: 'The request was received, but a service timed out',
  r200: 'The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the AVS check',
  r201: 'The issuing bank has questions about the request',
  r202: 'Expired card',
  r203: 'General decline of the card',
  r204: 'Insufficient funds in the account',
  r205: 'Stolen or lost card',
  r207: 'Issuing bank unavailable',
  r208: 'Inactive card or card not authorized for card-not-present transactions',
  r209: 'American Express Card Identifiction Digits (CID) did not match',
  r210: 'The card has reached the credit limit',
  r211: 'Invalid card verification number',
  r220: 'Generic Decline.',
  r221: "The customer matched an entry on the processor's negative file",
  r222: 'customer\'s account is frozen',
  r230: 'The authorization request was approved by the issuing bank but declined by CyberSource because it did not pass the card verification check',
  r231: 'Invalid account number',
  r232: 'The card type is not accepted by the payment processor',
  r233: 'General decline by the processor',
  r234: 'A problem exists with your CyberSource merchant configuration',
  r235: 'The requested amount exceeds the originally authorized amount',
  r236: 'Processor failure',
  r237: 'The authorization has already been reversed',
  r238: 'The authorization has already been captured',
  r239: 'The requested transaction amount must match the previous transaction amount',
  r240: 'The card type sent is invalid or does not correlate with the credit card number',
  r241: 'The request ID is invalid',
  r242: 'You requested a capture, but there is no corresponding, unused authorization record.',
  r243: 'The transaction has already been settled or reversed',
  r244: 'The bank account number failed the validation check',
  r246: 'The capture or credit is not voidable because the capture or credit information has already been submitted to your processor',
  r247: 'You requested a credit for a capture that was previously voided',
  r248: 'The boleto request was declined by your processor.',
  r250: 'The request was received, but a time-out occurred with the payment processor',
  r251: 'The Pinless Debit card\'s use frequency or maximum amount per use has been exceeded.',
  r254: 'Your CyberSource account is prohibited from processing stand-alone refunds',
  r255: 'Your CyberSource account is not configured to process the service in the country you specified',
  r400: 'Soft Decline - Fraud score exceeds threshold.',
  r450: 'Apartment number missing or not found.',
  r451: 'Insufficient address information.',
  r452: 'House/Box number not found on street.',
  r453: 'Multiple address matches were found.',
  r454: 'P.O. Box identifier not found or out of range.',
  r455: 'Route service identifier not found or out of range.',
  r456: 'Street name not found in Postal code.',
  r457: 'Postal code not found in database.',
  r458: 'Unable to verify or correct address.',
  r459: 'Multiple addres matches were found (international)',
  r460: 'Address match not found (no reason given)',
  r461: 'Unsupported character set',
  r475: 'The cardholder is enrolled in Payer Authentication. Please authenticate the cardholder before continuing with the transaction.',
  r476: 'Encountered a Payer Authentication problem. Payer could not be authenticated.',
  r478: 'Strong customer authentication (SCA) is required for this transaction.',
  r480: 'The order is marked for review by Decision Manager',
  r481: 'The order has been rejected by Decision Manager',
  r490: 'Your aggregator or acquirer is not accepting transactions from you at this time.',
  r491: 'Your aggregator or acquirer is not accepting this transaction.',
  r520: 'Soft Decline - The authorization request was approved by the issuing bank but declined by CyberSource based on your Smart Authorization settings.',
  r700: 'The customer matched the Denied Parties List',
  r701: 'Export bill_country/ship_country match',
  r702: 'Export email_country match',
  r703: 'Export hostname_country/ip_country match'
}
@@wallet_payment_solution =
{
  apple_pay: '001',
  google_pay: '012'
}

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?, #test?

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ CyberSourceGateway

These are the options that can be used when creating a new CyberSource Gateway object.

:login => your username

:password => the transaction key you generated in the Business Center

:test => true sets the gateway to test mode

:vat_reg_number => your VAT registration number

:nexus => “WI CA QC” sets the states/provinces where you have a physical

presence for tax purposes

:ignore_avs => true don’t want to use AVS so continue processing even

if AVS would have failed

:ignore_cvv => true don’t want to use CVV so continue processing even

if CVV would have failed


173
174
175
176
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 173

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

Instance Method Details

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



213
214
215
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 213

def adjust(money, authorization, options = {})
  commit(build_adjust_request(money, authorization, options), :adjust, money, options)
end

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



178
179
180
181
182
183
184
185
186
187
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 178

def authorize(money, payment_method, options = {})
  if valid_payment_method?(payment_method, options)
    setup_address_hash(options)
    commit(build_auth_request(money, payment_method, options), :authorize, money, options)
  else
    # this is for NetworkToken, ApplePay or GooglePay brands that aren't supported at CyberSource
    payment_type = payment_method.source.to_s.gsub('_', ' ').titleize.gsub(' ', '')
    Response.new(false, "#{card_brand(payment_method).capitalize} is not supported by #{payment_type} at CyberSource, check https://developer.cybersource.com/docs/cybs/en-us/payments/developer/all/rest/payments/CreatingOnlineAuth/CreatingAuthReqPNT.html")
  end
end

#calculate_tax(creditcard, options) ⇒ Object

CyberSource requires that you provide line item information for tax calculations. If you do not have prices for each item or want to simplify the situation then pass in one fake line item that costs the subtotal of the order

The line_item hash goes in the options hash and should look like

:line_items => [
  {
    :declared_value => '1',
    :quantity => '2',
    :code => 'default',
    :description => 'Giant Walrus',
    :sku => 'WA323232323232323'
  },
  {
    :declared_value => '6',
    :quantity => '1',
    :code => 'default',
    :description => 'Marble Snowcone',
    :sku => 'FAKE1232132113123'
  }
]

This functionality is only supported by this particular gateway may be changed at any time



290
291
292
293
294
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 290

def calculate_tax(creditcard, options)
  requires!(options, :line_items)
  setup_address_hash(options)
  commit(build_tax_calculation_request(creditcard, options), :calculate_tax, nil, options)
end

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



189
190
191
192
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 189

def capture(money, authorization, options = {})
  setup_address_hash(options)
  commit(build_capture_request(money, authorization, options), :capture, money, options)
end

#credit(money, creditcard_or_reference, options = {}) ⇒ Object

Adds credit to a card or subscription (stand alone credit).



226
227
228
229
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 226

def credit(money, creditcard_or_reference, options = {})
  setup_address_hash(options)
  commit(build_credit_request(money, creditcard_or_reference, options), :credit, money, options)
end

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



194
195
196
197
198
199
200
201
202
203
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 194

def purchase(money, payment_method, options = {})
  if valid_payment_method?(payment_method, options)
    setup_address_hash(options)
    commit(build_purchase_request(money, payment_method, options), :purchase, money, options)
  else
    # this is for NetworkToken, ApplePay or GooglePay brands that aren't supported at CyberSource
    payment_type = payment_method.source.to_s.gsub('_', ' ').titleize.gsub(' ', '')
    Response.new(false, "#{card_brand(payment_method).capitalize} is not supported by #{payment_type} at CyberSource, check https://developer.cybersource.com/docs/cybs/en-us/payments/developer/all/rest/payments/CreatingOnlineAuth/CreatingAuthReqPNT.html")
  end
end

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



209
210
211
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 209

def refund(money, identification, options = {})
  commit(build_refund_request(money, identification, options), :refund, money, options)
end

#retrieve(reference, options = {}) ⇒ Object

Retrieves a customer subscription/profile



259
260
261
262
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 259

def retrieve(reference, options = {})
  requires!(options, :order_id)
  commit(build_retrieve_subscription_request(reference, options), :retrieve, nil, options)
end

#scrub(transcript) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 300

def scrub(transcript)
  transcript.
    gsub(%r((<wsse:Password [^>]*>)[^<]*(</wsse:Password>))i, '\1[FILTERED]\2').
    gsub(%r((<accountNumber>)[^<]*(</accountNumber>))i, '\1[FILTERED]\2').
    gsub(%r((<cvNumber>)[^<]*(</cvNumber>))i, '\1[FILTERED]\2').
    gsub(%r((<cavv>)[^<]*(</cavv>))i, '\1[FILTERED]\2').
    gsub(%r((<xid>)[^<]*(</xid>))i, '\1[FILTERED]\2').
    gsub(%r((<networkTokenCryptogram>)[^<]*(</networkTokenCryptogram>))i, '\1[FILTERED]\2').
    gsub(%r((<requestorID>)[^<]*(</requestorID>))i, '\1[FILTERED]\2').
    gsub(%r((<authenticationData>)[^<]*(</authenticationData>))i, '\1[FILTERED]\2')
end

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

Stores a customer subscription/profile with type “on-demand”. To charge the card while creating a profile, pass options => money



234
235
236
237
238
239
240
241
242
243
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 234

def store(payment_method, options = {})
  if valid_payment_method?(payment_method, options)
    setup_address_hash(options)
    commit(build_create_subscription_request(payment_method, options), :store, nil, options)
  else
    # this is for NetworkToken, ApplePay or GooglePay brands that aren't supported at CyberSource
    payment_type = payment_method.source.to_s.gsub('_', ' ').titleize.gsub(' ', '')
    Response.new(false, "#{card_brand(payment_method).capitalize} is not supported by #{payment_type} at CyberSource, check https://developer.cybersource.com/docs/cybs/en-us/payments/developer/all/rest/payments/CreatingOnlineAuth/CreatingAuthReqPNT.html")
  end
end

#supports_network_tokenization?Boolean

Returns:

  • (Boolean)


312
313
314
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 312

def supports_network_tokenization?
  true
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


296
297
298
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 296

def supports_scrubbing?
  true
end

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

Removes a customer subscription/profile



253
254
255
256
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 253

def unstore(reference, options = {})
  requires!(options, :order_id)
  commit(build_delete_subscription_request(reference, options), :unstore, nil, options)
end

#update(reference, creditcard, options = {}) ⇒ Object

Updates a customer subscription/profile



246
247
248
249
250
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 246

def update(reference, creditcard, options = {})
  requires!(options, :order_id)
  setup_address_hash(options)
  commit(build_update_subscription_request(reference, creditcard, options), :update, nil, options)
end

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



217
218
219
220
221
222
223
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 217

def verify(payment, options = {})
  amount = eligible_for_zero_auth?(payment, options) ? 0 : 100
  MultiResponse.run(:use_first_response) do |r|
    r.process { authorize(amount, payment, options) }
    r.process(:ignore_result) { void(r.authorization, options) } unless amount == 0
  end
end

#verify_credentialsObject



316
317
318
319
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 316

def verify_credentials
  response = void('0')
  response.params['reasonCode'] == '102'
end

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



205
206
207
# File 'lib/active_merchant/billing/gateways/cyber_source.rb', line 205

def void(identification, options = {})
  commit(build_void_request(identification, options), :void, nil, options)
end