Class: ActiveMerchant::Billing::Shift4V2Gateway
Constant Summary
ActiveMerchant::Billing::SecurionPayGateway::STANDARD_ERROR_CODE_MAPPING
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
-
#add_amount(post, money, options, include_currency = false) ⇒ Object
-
#add_creditcard(post, payment_method, options) ⇒ Object
-
#add_stored_credentials(post, options) ⇒ Object
-
#bank_account_object(payment_method, options) ⇒ Object
-
#create_post_for_auth_or_purchase(money, payment, options) ⇒ Object
-
#credit(money, payment, options = {}) ⇒ Object
-
#get_account_type(check) ⇒ Object
-
#headers(options = {}) ⇒ Object
-
#json_error(raw_response) ⇒ Object
-
#scrub(transcript) ⇒ Object
-
#store(payment_method, options = {}) ⇒ Object
-
#unstore(reference, options = {}) ⇒ Object
-
#url_for_store(payment_method, options = {}) ⇒ Object
#authorize, #capture, #customer, #initialize, #purchase, #refund, #supports_scrubbing?, #verify, #void
Methods inherited from Gateway
#add_field_to_post_if_present, #add_fields_to_post_if_present, #card_brand, card_brand, #generate_unique_id, inherited, #initialize, #supported_countries, supported_countries, supported_countries=, supports?, #supports_network_tokenization?, #supports_scrubbing?, #test?
#expdate, #format, #strftime_yyyymm
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Instance Method Details
#add_amount(post, money, options, include_currency = false) ⇒ Object
78
79
80
81
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 78
def add_amount(post, money, options, include_currency = false)
super
post[:currency]&.upcase!
end
|
#add_creditcard(post, payment_method, options) ⇒ Object
83
84
85
86
87
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 83
def add_creditcard(post, payment_method, options)
return super unless payment_method.is_a?(Check)
post[:paymentMethod] = bank_account_object(payment_method, options)
end
|
#add_stored_credentials(post, options) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 46
def add_stored_credentials(post, options)
return unless options[:stored_credential].present?
initiator = options.dig(:stored_credential, :initiator)
reason_type = options.dig(:stored_credential, :reason_type)
post_type = {
%w[cardholder recurring] => 'first_recurring',
%w[merchant recurring] => 'subsequent_recurring',
%w[cardholder unscheduled] => 'customer_initiated',
%w[merchant installment] => 'merchant_initiated'
}[[initiator, reason_type]]
post[:type] = post_type if post_type
end
|
#bank_account_object(payment_method, options) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 89
def bank_account_object(payment_method, options)
{
type: :ach,
fraudCheckData: {
ipAddress: options[:ip],
email: options[:email]
}.compact,
billing: {
name: payment_method.name,
address: { country: options.dig(:billing_address, :country) }
}.compact,
ach: {
account: {
routingNumber: payment_method.routing_number,
accountNumber: payment_method.account_number,
accountType: get_account_type(payment_method)
},
verificationProvider: :external
}
}
end
|
#create_post_for_auth_or_purchase(money, payment, options) ⇒ Object
40
41
42
43
44
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 40
def create_post_for_auth_or_purchase(money, payment, options)
super.tap do |post|
add_stored_credentials(post, options)
end
end
|
#credit(money, payment, options = {}) ⇒ Object
9
10
11
12
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 9
def credit(money, payment, options = {})
post = create_post_for_auth_or_purchase(money, payment, options)
commit('credits', post, options)
end
|
#get_account_type(check) ⇒ Object
111
112
113
114
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 111
def get_account_type(check)
holder = (check.account_holder_type || '').match(/business/i) ? :corporate : :personal
"#{holder}_#{check.account_type}"
end
|
61
62
63
64
65
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 61
def (options = {})
super.tap do ||
['User-Agent'] = "Shift4/v2 ActiveMerchantBindings/#{ActiveMerchant::VERSION}"
end
end
|
#json_error(raw_response) ⇒ Object
74
75
76
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 74
def json_error(raw_response)
super(raw_response, 'Shift4 V2')
end
|
#scrub(transcript) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 67
def scrub(transcript)
super.
gsub(%r((card\[expMonth\]=)\d+), '\1[FILTERED]').
gsub(%r((card\[expYear\]=)\d+), '\1[FILTERED]').
gsub(%r((card\[cardholderName\]=)\w+[^ ]\w+), '\1[FILTERED]')
end
|
#store(payment_method, options = {}) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 14
def store(payment_method, options = {})
post = case payment_method
when CreditCard
cc = {}.tap { |card| add_creditcard(card, payment_method, options) }[:card]
options[:customer_id].blank? ? { email: options[:email], card: cc } : cc
when Check
bank_account_object(payment_method, options)
else
raise ArgumentError.new("Unhandled payment method #{payment_method.class}.")
end
commit url_for_store(payment_method, options), post, options
end
|
#unstore(reference, options = {}) ⇒ Object
36
37
38
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 36
def unstore(reference, options = {})
commit("customers/#{options[:customer_id]}/cards/#{reference}", nil, options, :delete)
end
|
#url_for_store(payment_method, options = {}) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/active_merchant/billing/gateways/shift4_v2.rb', line 28
def url_for_store(payment_method, options = {})
case payment_method
when CreditCard
options[:customer_id].blank? ? 'customers' : "customers/#{options[:customer_id]}/cards"
when Check then 'payment-methods'
end
end
|