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?
#fetch_version, included
#expdate, #format, #strftime_yyyymm, #strftime_yyyymmdd_last_day
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.
26
27
28
29
30
31
32
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 26
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 50
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
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 66
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 34
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 80
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
130
131
132
133
134
135
136
137
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 130
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
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 139
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
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 115
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
126
127
128
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 126
def supports_scrubbing?
true
end
|
#verify(credit_card, options = {}) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 102
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
97
98
99
100
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 97
def void(authorization, options = {})
options[:invoice] = get_invoice(authorization)
commit('invoice', {}, options)
end
|