Class: ActiveMerchant::Billing::SafeChargeGateway

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

Constant Summary collapse

VERSION =
'4.0.4'

Constants inherited from Gateway

Gateway::CREDIT_DEPRECATION_MESSAGE, Gateway::DEBIT_CARDS, Gateway::RECURRING_DEPRECATION_MESSAGE, Gateway::STANDARD_ERROR_CODE

Instance Attribute Summary

Attributes inherited from Gateway

#options

Instance Method Summary collapse

Methods inherited from Gateway

#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



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

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

  commit(post)
end

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



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

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



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

def credit(money, payment, options={})
  post = {}
  add_payment(post, payment)
  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
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 23

def purchase(money, payment, options={})
  post = {}
  add_transaction_data("Sale", post, money, options)
  add_payment(post, payment)
  add_customer_details(post, payment, options)

  commit(post)
end

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



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

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



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

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)


98
99
100
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 98

def supports_scrubbing?
  true
end

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



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

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



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

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