Class: ActiveMerchant::Billing::Shift4Gateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::Shift4Gateway
show all
- Defined in:
- lib/active_merchant/billing/gateways/shift4.rb
Constant Summary
collapse
- RECURRING_TYPE_TRANSACTIONS =
%w(recurring installment)
- TRANSACTIONS_WITHOUT_RESPONSE_CODE =
%w(accesstoken add)
- SUCCESS_TRANSACTION_STATUS =
%w(A)
- DISALLOWED_ENTRY_MODE_ACTIONS =
%w(capture refund add verify)
- URL_POSTFIX_MAPPING =
{
'accesstoken' => 'credentials',
'add' => 'tokens',
'verify' => 'cards'
}
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
-
#authorize(money, payment_method, options = {}) ⇒ Object
-
#capture(money, authorization, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Shift4Gateway
constructor
A new instance of Shift4Gateway.
-
#purchase(money, payment_method, options = {}) ⇒ Object
-
#refund(money, payment_method, options = {}) ⇒ Object
(also: #credit)
-
#scrub(transcript) ⇒ Object
-
#setup_access_token ⇒ Object
-
#store(credit_card, options = {}) ⇒ Object
-
#supports_scrubbing? ⇒ Boolean
-
#verify(credit_card, options = {}) ⇒ Object
-
#void(authorization, options = {}) ⇒ Object
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?
#expdate, #format, #strftime_yyyymm
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
#initialize(options = {}) ⇒ Shift4Gateway
Returns a new instance of Shift4Gateway.
24
25
26
27
28
29
30
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 24
def initialize(options = {})
requires!(options, :client_guid, :auth_token)
@client_guid = options[:client_guid]
@auth_token = options[:auth_token]
@access_token = options[:access_token]
super
end
|
Instance Method Details
#authorize(money, payment_method, options = {}) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 48
def authorize(money, payment_method, options = {})
post = {}
action = 'authorization'
payment_method = get_card_token(payment_method) if payment_method.is_a?(String)
add_datetime(post, options)
add_invoice(post, money, options)
add_clerk(post, options)
add_transaction(post, options)
add_card(action, post, payment_method, options)
add_card_present(post, options)
add_customer(post, payment_method, options)
commit(action, post, options)
end
|
#capture(money, authorization, options = {}) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 64
def capture(money, authorization, options = {})
post = {}
action = 'capture'
options[:invoice] = get_invoice(authorization)
add_datetime(post, options)
add_invoice(post, money, options)
add_clerk(post, options)
add_transaction(post, options)
add_card(action, post, get_card_token(authorization), options)
commit(action, post, options)
end
|
#purchase(money, payment_method, options = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 32
def purchase(money, payment_method, options = {})
post = {}
action = 'sale'
payment_method = get_card_token(payment_method) if payment_method.is_a?(String)
add_datetime(post, options)
add_invoice(post, money, options)
add_clerk(post, options)
add_transaction(post, options)
add_card(action, post, payment_method, options)
add_card_present(post, options)
add_customer(post, payment_method, options)
commit(action, post, options)
end
|
#refund(money, payment_method, options = {}) ⇒ Object
Also known as:
credit
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 78
def refund(money, payment_method, options = {})
post = {}
action = 'refund'
add_datetime(post, options)
add_invoice(post, money, options)
add_clerk(post, options)
add_transaction(post, options)
card_token = payment_method.is_a?(CreditCard) ? get_card_token(payment_method) : payment_method
add_card(action, post, card_token, options)
add_card_present(post, options)
commit(action, post, options)
end
|
#scrub(transcript) ⇒ Object
128
129
130
131
132
133
134
135
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 128
def scrub(transcript)
transcript.
gsub(%r(("Number\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("expirationDate\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("FirstName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("LastName\\?"\s*:\s*\\?")[^"]*)i, '\1[FILTERED]').
gsub(%r(("securityCode\\?":{\\?"\w+\\?":\d+,\\?"value\\?":\\?")\d*)i, '\1[FILTERED]')
end
|
#setup_access_token ⇒ Object
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 137
def setup_access_token
post = {}
add_credentials(post, options)
add_datetime(post, options)
response = commit('accesstoken', post, ('accesstoken', options))
raise OAuthResponseError.new(response, response.params.fetch('result', [{}]).first.dig('error', 'longText')) unless response.success?
response.params['result'].first['credential']['accessToken']
end
|
#store(credit_card, options = {}) ⇒ Object
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 113
def store(credit_card, options = {})
post = {}
action = 'add'
add_datetime(post, options)
add_card(action, post, credit_card, options)
add_customer(post, credit_card, options)
commit(action, post, options)
end
|
#supports_scrubbing? ⇒ Boolean
124
125
126
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 124
def supports_scrubbing?
true
end
|
#verify(credit_card, options = {}) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 100
def verify(credit_card, options = {})
post = {}
action = 'verify'
post[:transaction] = {}
add_datetime(post, options)
add_card(action, post, credit_card, options)
add_customer(post, credit_card, options)
add_card_on_file(post[:transaction], options)
commit(action, post, options)
end
|
#void(authorization, options = {}) ⇒ Object
95
96
97
98
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 95
def void(authorization, options = {})
options[:invoice] = get_invoice(authorization)
commit('invoice', {}, options)
end
|