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



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

def authorize(money, payment, options = {})
  post = {}

  add_external_mpi_data(post, options) if options[:three_d_secure]&.is_a?(Hash)
  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



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

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



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

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
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 23

def purchase(money, payment, options = {})
  post = {}

  # Determine if 3DS is requested, or there is standard external MPI data
  if options[:three_d_secure]
    if options[:three_d_secure].is_a?(Hash)
      add_external_mpi_data(post, options)
    else
      post[:sg_APIType] = 1
      trans_type = 'Sale3D'
    end
  end

  trans_type ||= '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



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

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



119
120
121
122
123
124
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 119

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)


115
116
117
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 115

def supports_scrubbing?
  true
end

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



108
109
110
111
112
113
# File 'lib/active_merchant/billing/gateways/safe_charge.rb', line 108

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



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

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