Class: ActiveMerchant::Billing::CyberSourceRestGateway

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

Constant Summary collapse

CREDIT_CARD_CODES =
{
  american_express: '003',
  cartes_bancaires: '036',
  dankort: '034',
  diners_club: '005',
  discover: '004',
  elo: '054',
  jcb: '007',
  maestro: '042',
  master: '002',
  unionpay: '062',
  visa: '001',
  carnet: '002'
}
WALLET_PAYMENT_SOLUTION =
{
  apple_pay: '001',
  google_pay: '012'
}
NT_PAYMENT_SOLUTION =
{
  'master' => '014',
  'visa' => '015'
}

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 included from CyberSourceCommon

#address_names, #check_billing_field_value, #eligible_for_zero_auth?, #lookup_country_code

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 Versionable

#fetch_version, included

Methods included from CreditCardFormatting

#expdate, #format, #strftime_yyyymm, #strftime_yyyymmdd_last_day

Methods included from PostsData

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

Constructor Details

#initialize(options = {}) ⇒ CyberSourceRestGateway

Returns a new instance of CyberSourceRestGateway.



47
48
49
50
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 47

def initialize(options = {})
  requires!(options, :merchant_id, :public_key, :private_key)
  super
end

Instance Method Details

#authorize(money, payment, options = {}, capture = false) ⇒ Object



56
57
58
59
60
61
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 56

def authorize(money, payment, options = {}, capture = false)
  post = build_auth_request(money, payment, options)
  post[:processingInformation][:capture] = true if capture

  commit('payments', post, options)
end

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



63
64
65
66
67
68
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 63

def capture(money, authorization, options = {})
  payment = authorization.split('|').first
  post = build_reference_request(money, options)

  commit("payments/#{payment}/captures", post, options)
end

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



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

def credit(money, payment, options = {})
  post = build_credit_request(money, payment, options)
  commit('credits', post)
end

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



52
53
54
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 52

def purchase(money, payment, options = {})
  authorize(money, payment, options, true)
end

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



70
71
72
73
74
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 70

def refund(money, authorization, options = {})
  payment = authorization.split('|').first
  post = build_reference_request(money, options)
  commit("payments/#{payment}/refunds", post, options)
end

#scrub(transcript) ⇒ Object



99
100
101
102
103
104
105
106
107
108
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 99

def scrub(transcript)
  transcript.
    gsub(/(\\?"number\\?":\\?")\d+/, '\1[FILTERED]').
    gsub(/(\\?"routingNumber\\?":\\?")\d+/, '\1[FILTERED]').
    gsub(/(\\?"securityCode\\?":\\?")\d+/, '\1[FILTERED]').
    gsub(/(\\?"cryptogram\\?":\\?")[^<]+/, '\1[FILTERED]').
    gsub(/(signature=")[^"]*/, '\1[FILTERED]').
    gsub(/(keyid=")[^"]*/, '\1[FILTERED]').
    gsub(/(Digest: SHA-256=)[\w\/\+=]*/, '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 95

def supports_scrubbing?
  true
end

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



87
88
89
90
91
92
93
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 87

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

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



81
82
83
84
85
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 81

def void(authorization, options = {})
  payment, amount = authorization.split('|')
  post = build_void_request(options, amount)
  commit("payments/#{payment}/reversals", post)
end