Class: ActiveMerchant::Billing::SafeChargeGateway

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

Constant Summary collapse

VERSION =
'4.1.0'

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?, #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 = {}) ⇒ SafeChargeGateway

Returns a new instance of SafeChargeGateway.



18
19
20
21
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 18

def initialize(options={})
  requires!(options, :client_login_id, :client_password)
  super
end

Instance Method Details

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



34
35
36
37
38
39
40
41
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 34

def authorize(money, payment, options={})
  post = {}
  add_transaction_data('Auth', post, money, options)
  add_payment(post, payment, options)
  add_customer_details(post, payment, options)

  commit(post)
end

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



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 43

def capture(money, authorization, options={})
  post = {}
  auth, transaction_id, token, exp_month, exp_year, _, original_currency = authorization.split('|')
  add_transaction_data('Settle', post, money, options.merge!({currency: original_currency}))
  post[:sg_AuthCode] = auth
  post[:sg_TransactionID] = transaction_id
  post[:sg_CCToken] = token
  post[:sg_ExpMonth] = exp_month
  post[:sg_ExpYear] = exp_year

  commit(post)
end

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



70
71
72
73
74
75
76
77
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 70

def credit(money, payment, options={})
  post = {}
  add_payment(post, payment, options)
  add_transaction_data('Credit', post, money, options)
  post[:sg_CreditType] = 1

  commit(post)
end

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



23
24
25
26
27
28
29
30
31
32
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 23

def purchase(money, payment, options={})
  post = {}
  post[:sg_APIType] = 1 if options[:three_d_secure]
  trans_type = options[:three_d_secure] ? 'Sale3D' : 'Sale'
  add_transaction_data(trans_type, post, money, options)
  add_payment(post, payment, options)
  add_customer_details(post, payment, options)

  commit(post)
end

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



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 56

def refund(money, authorization, options={})
  post = {}
  auth, transaction_id, token, exp_month, exp_year, _, original_currency = authorization.split('|')
  add_transaction_data('Credit', post, money, options.merge!({currency: original_currency}))
  post[:sg_CreditType] = 2
  post[:sg_AuthCode] = auth
  post[:sg_TransactionID] = transaction_id
  post[:sg_CCToken] = token
  post[:sg_ExpMonth] = exp_month
  post[:sg_ExpYear] = exp_year

  commit(post)
end

#scrub(transcript) ⇒ Object



104
105
106
107
108
109
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 104

def scrub(transcript)
  transcript.
    gsub(%r((sg_ClientPassword=)[^&]+(&?)), '\1[FILTERED]\2').
    gsub(%r((sg_CardNumber=)[^&]+(&?)), '\1[FILTERED]\2').
    gsub(%r((sg_CVV2=)\d+), '\1[FILTERED]')
end

#supports_scrubbing?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 100

def supports_scrubbing?
  true
end

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



93
94
95
96
97
98
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 93

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

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



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 79

def void(authorization, options={})
  post = {}
  auth, transaction_id, token, exp_month, exp_year, original_amount, original_currency = authorization.split('|')
  add_transaction_data('Void', post, (original_amount.to_f * 100), options.merge!({currency: original_currency}))
  post[:sg_CreditType] = 2
  post[:sg_AuthCode] = auth
  post[:sg_TransactionID] = transaction_id
  post[:sg_CCToken] = token
  post[:sg_ExpMonth] = exp_month
  post[:sg_ExpYear] = exp_year

  commit(post)
end