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'
}
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 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

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.



39
40
41
42
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 39

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

Instance Method Details

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



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

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



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

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



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

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

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



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

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

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



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

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



91
92
93
94
95
96
97
98
99
# File 'lib/active_merchant/billing/gateways/cyber_source_rest.rb', line 91

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

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


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

def supports_scrubbing?
  true
end

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



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

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



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

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