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'
}
- STANDARD_ERROR_CODE_MAPPING =
{
'incorrect_number' => STANDARD_ERROR_CODE[:incorrect_number],
'invalid_number' => STANDARD_ERROR_CODE[:invalid_number],
'invalid_expiry_month' => STANDARD_ERROR_CODE[:invalid_expiry_date],
'invalid_expiry_year' => STANDARD_ERROR_CODE[:invalid_expiry_date],
'invalid_cvc' => STANDARD_ERROR_CODE[:invalid_cvc],
'expired_card' => STANDARD_ERROR_CODE[:expired_card],
'insufficient_funds' => STANDARD_ERROR_CODE[:card_declined],
'incorrect_cvc' => STANDARD_ERROR_CODE[:incorrect_cvc],
'incorrect_zip' => STANDARD_ERROR_CODE[:incorrect_zip],
'card_declined' => STANDARD_ERROR_CODE[:card_declined],
'processing_error' => STANDARD_ERROR_CODE[:processing_error],
'lost_or_stolen' => STANDARD_ERROR_CODE[:card_declined],
'suspected_fraud' => STANDARD_ERROR_CODE[:card_declined],
'expired_token' => STANDARD_ERROR_CODE[:card_declined]
}
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
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.
40
41
42
43
44
45
46
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 40
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 64
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
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 80
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
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 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 94
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
144
145
146
147
148
149
150
151
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 144
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
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 153
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
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 129
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
140
141
142
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 140
def supports_scrubbing?
true
end
|
#verify(credit_card, options = {}) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 116
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
111
112
113
114
|
# File 'lib/active_merchant/billing/gateways/shift4.rb', line 111
def void(authorization, options = {})
options[:invoice] = get_invoice(authorization)
commit('invoice', {}, options)
end
|