Class: ActiveMerchant::Billing::NuveiGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::NuveiGateway
show all
- Defined in:
- lib/active_merchant/billing/gateways/nuvei.rb
Constant Summary
collapse
- ENDPOINTS_MAPPING =
{
authenticate: '/getSessionToken',
purchase: '/payment',
capture: '/settleTransaction',
refund: '/refundTransaction',
void: '/voidTransaction',
general_credit: '/payout',
init_payment: '/initPayment'
}
- NETWORK_TOKENIZATION_CARD_MAPPING =
{
'apple_pay' => 'ApplePay',
'google_pay' => 'GooglePay'
}
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_account_funding_transaction(post, payment, options = {}) ⇒ Object
-
#add_stored_credentials(post, payment, options = {}) ⇒ Object
-
#add_user_details(post, options) ⇒ Object
-
#authorize(money, payment, options = {}, transaction_type = 'Auth') ⇒ Object
-
#capture(money, authorization, options = {}) ⇒ Object
-
#credit(money, payment, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ NuveiGateway
constructor
A new instance of NuveiGateway.
-
#mit?(stored_credential) ⇒ Boolean
-
#purchase(money, payment, options = {}) ⇒ Object
-
#refund(money, authorization, options = {}) ⇒ Object
-
#scrub(transcript) ⇒ Object
-
#send_payout_transaction(payment_key, post, payment, options = {}) ⇒ Object
-
#send_unreferenced_refund_transaction(post, payment, options = {}) ⇒ Object
-
#set_initiator_type(post, payment, options) ⇒ Object
-
#set_reason_type(post, options) ⇒ 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
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
#initialize(options = {}) ⇒ NuveiGateway
Returns a new instance of NuveiGateway.
30
31
32
33
34
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 30
def initialize(options = {})
requires!(options, :merchant_id, :merchant_site_id, :secret_key)
super
fetch_session_token unless session_token_valid?
end
|
Instance Method Details
#add_account_funding_transaction(post, payment, options = {}) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 155
def add_account_funding_transaction(post, payment, options = {})
return unless options[:is_aft]
recipient_details = {
firstName: options[:aft_recipient_first_name],
lastName: options[:aft_recipient_last_name]
}.compact
address_details = {
firstName: payment.first_name,
lastName: payment.last_name,
country: options.dig(:billing_address, :country),
address: options.dig(:billing_address, :address1),
city: options.dig(:billing_address, :city),
state: options.dig(:billing_address, :state)
}.compact
post[:billingAddress] ||= {}
post[:billingAddress].merge!(address_details)
post[:recipientDetails] = recipient_details unless recipient_details.empty?
add_user_details(post, options)
end
|
#add_stored_credentials(post, payment, options = {}) ⇒ Object
127
128
129
130
131
132
133
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 127
def add_stored_credentials(post, payment, options = {})
return unless options[:stored_credential]
post[:savePM] = options[:save_payment_method] || true
set_initiator_type(post, payment, options)
set_reason_type(post, options)
end
|
#add_user_details(post, options) ⇒ Object
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 178
def add_user_details(post, options)
return unless options[:user_details]&.is_a?(Hash)
user_details = options[:user_details]
post[:userDetails] = {}
post[:userDetails][:firstName] = user_details[:first_name] if user_details[:first_name]
post[:userDetails][:lastName] = user_details[:last_name] if user_details[:last_name]
post[:userDetails][:address] = user_details[:address] if user_details[:address]
post[:userDetails][:streetNumber] = user_details[:street_number] if user_details[:street_number]
post[:userDetails][:phone] = user_details[:phone] if user_details[:phone]
post[:userDetails][:zip] = user_details[:zip] if user_details[:zip]
post[:userDetails][:city] = user_details[:city] if user_details[:city]
post[:userDetails][:country] = user_details[:country] if user_details[:country]
post[:userDetails][:state] = user_details[:state] if user_details[:state]
post[:userDetails][:email] = user_details[:email] if user_details[:email]
post[:userDetails][:county] = user_details[:county] if user_details[:county]
post[:userDetails][:language] = user_details[:language] if user_details[:language]
post[:userDetails][:identification] = user_details[:identification] if user_details[:identification]
if user_details[:date_of_birth] && options[:is_aft]
post[:userDetails][:dateOfBirth] = user_details[:date_of_birth]
elsif user_details[:birth_date] && options[:is_payout]
post[:userDetails][:birthdate] = user_details[:birth_date]
end
end
|
#authorize(money, payment, options = {}, transaction_type = 'Auth') ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 36
def authorize(money, payment, options = {}, transaction_type = 'Auth')
post = { transactionType: transaction_type }
post[:savePM] = options[:save_payment_method] ? options[:save_payment_method].to_s : 'false'
build_post_data(post, options)
add_amount(post, money, options)
add_payment_method(post, payment, :paymentOption, options)
add_3ds_global(post, options)
add_address(post, payment, options)
add_customer_ip(post, options)
add_stored_credentials(post, payment, options)
add_account_funding_transaction(post, payment, options)
add_cardholder_name_verification(post, payment, transaction_type, options)
post[:userTokenId] = options[:user_token_id] if options[:user_token_id]
post[:isPartialApproval] = options[:is_partial_approval] ? 1 : 0
post[:authenticationOnlyType] = options[:authentication_only_type] if options[:authentication_only_type]
if options[:execute_threed]
execute_3ds_flow(post, money, payment, transaction_type, options)
else
commit(:purchase, post)
end
end
|
#capture(money, authorization, options = {}) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 65
def capture(money, authorization, options = {})
post = { relatedTransactionId: authorization }
build_post_data(post)
add_amount(post, money, options)
commit(:capture, post)
end
|
#credit(money, payment, options = {}) ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 102
def credit(money, payment, options = {})
post = { userTokenId: options[:user_token_id] }
payment_key = payment.is_a?(NetworkTokenizationCreditCard) ? :userPaymentOption : :cardData
build_post_data(post)
add_amount(post, money, options)
options[:is_payout] ? send_payout_transaction(payment_key, post, payment, options) : send_unreferenced_refund_transaction(post, payment, options)
end
|
#mit?(stored_credential) ⇒ Boolean
151
152
153
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 151
def mit?(stored_credential)
stored_credential[:reason_type] != 'unscheduled' && stored_credential[:initial_transaction] == false
end
|
#purchase(money, payment, options = {}) ⇒ Object
60
61
62
63
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 60
def purchase(money, payment, options = {})
fetch_session_token if payment.is_a?(String)
authorize(money, payment, options, 'Sale')
end
|
#refund(money, authorization, options = {}) ⇒ Object
74
75
76
77
78
79
80
81
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 74
def refund(money, authorization, options = {})
post = { relatedTransactionId: authorization }
build_post_data(post)
add_amount(post, money, options)
commit(:refund, post)
end
|
#scrub(transcript) ⇒ Object
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 229
def scrub(transcript)
transcript.
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
gsub(%r(("cardNumber\\?":\\?")[^"\\]*)i, '\1[FILTERED]').
gsub(%r(("CVV\\?":\\?")\d+), '\1[FILTERED]').
gsub(%r(("merchantId\\?":\\?")\d+), '\1[FILTERED]').
gsub(%r(("merchantSiteId\\?":\\?")\d+), '\1[FILTERED]').
gsub(%r(("merchantKey\\?":\\?")\d+), '\1[FILTERED]').
gsub(%r(("accountNumber\\?":\\?")\d+), '\1[FILTERED]').
gsub(%r(("cryptogram\\?":\\?")[^"\\]*)i, '\1[FILTERED]')
end
|
#send_payout_transaction(payment_key, post, payment, options = {}) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 110
def send_payout_transaction(payment_key, post, payment, options = {})
add_payment_method(post, payment, payment_key, options)
add_customer_ip(post, options)
url_details(post, options)
add_user_details(post, options)
commit(:general_credit, post.compact)
end
|
#send_unreferenced_refund_transaction(post, payment, options = {}) ⇒ Object
118
119
120
121
122
123
124
125
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 118
def send_unreferenced_refund_transaction(post, payment, options = {})
post[:paymentOption] = { userPaymentOptionId: options[:user_payment_option_id] } if options[:user_payment_option_id]
unless options[:user_payment_option_id]
add_payment_method(post, payment, :paymentOption, options)
post[:paymentOption][:card].slice!(:cardNumber, :cardHolderName, :expirationMonth, :expirationYear, :CVV)
end
commit(:refund, post.compact)
end
|
#set_initiator_type(post, payment, options) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 135
def set_initiator_type(post, payment, options)
stored_credential = options[:stored_credential]
return unless stored_credential
is_initial_transaction = stored_credential[:initial_transaction]
stored_credentials_mode = is_initial_transaction ? '0' : '1'
if payment.is_a?(CreditCard)
post[:paymentOption] ||= {}
post[:paymentOption][:card] ||= {}
post[:paymentOption][:card][:storedCredentials] ||= {}
post[:paymentOption][:card][:storedCredentials][:storedCredentialsMode] = stored_credentials_mode
end
post[:isRebilling] = options[:is_rebilling] ? '1' : '0' if mit?(options[:stored_credential])
end
|
#set_reason_type(post, options) ⇒ Object
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 205
def set_reason_type(post, options)
reason_type = options[:stored_credential][:reason_type]
case reason_type
when 'recurring'
reason_type = 'RECURRING'
when 'installment'
reason_type = 'INSTALLMENTS'
when 'unscheduled'
reason_type = 'ADDCARD'
end
unless reason_type == 'ADDCARD'
fetch_session_token
post[:relatedTransactionId] = options[:stored_credential][:network_transaction_id] if options[:stored_credential][:network_transaction_id]
end
post[:authenticationOnlyType] = reason_type
end
|
#store(credit_card, options = {}) ⇒ Object
97
98
99
100
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 97
def store(credit_card, options = {})
options[:save_payment_method] = true
authorize(0, credit_card, options)
end
|
#supports_scrubbing? ⇒ Boolean
225
226
227
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 225
def supports_scrubbing?
true
end
|
#verify(credit_card, options = {}) ⇒ Object
90
91
92
93
94
95
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 90
def verify(credit_card, options = {})
MultiResponse.run(:use_first_response) do |r|
r.process { authorize(0, credit_card, options) }
r.process(:ignore_result) { void(r.authorization, options) }
end
end
|
#void(authorization, options = {}) ⇒ Object
83
84
85
86
87
88
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 83
def void(authorization, options = {})
post = { relatedTransactionId: authorization }
build_post_data(post)
commit(:void, post)
end
|