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 CreditCardFormatting

#expdate, #format, #strftime_yyyymm

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.



45
46
47
48
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 45

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

Instance Method Details

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



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

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



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

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



74
75
76
77
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 74

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

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



50
51
52
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 50

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

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



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

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



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

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)


93
94
95
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 93

def supports_scrubbing?
  true
end

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



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

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



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

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