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
-
#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.
-
#purchase(money, payment, options = {}) ⇒ Object
-
#refund(money, authorization, options = {}) ⇒ Object
-
#scrub(transcript) ⇒ 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?
#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
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 130
def add_account_funding_transaction(post, payment, options = {})
return unless options[:is_aft]
recipient_details = {
firstName: payment.first_name,
lastName: payment.last_name,
country: options.dig(:billing_address, :country)
}.compact
post[:recipientDetails] = recipient_details unless recipient_details.empty?
end
|
#add_stored_credentials(post, payment, options = {}) ⇒ Object
112
113
114
115
116
117
118
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 112
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
|
#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
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 36
def authorize(money, payment, options = {}, transaction_type = 'Auth')
post = { transactionType: transaction_type, savePM: false }
build_post_data(post)
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
64
65
66
67
68
69
70
71
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 64
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
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 100
def credit(money, payment, options = {})
post = { userTokenId: options[:user_token_id] }
build_post_data(post)
add_amount(post, money, options)
add_payment_method(post, payment, :cardData, options)
add_address(post, payment, options)
add_customer_ip(post, options)
commit(:general_credit, post.compact)
end
|
#purchase(money, payment, options = {}) ⇒ Object
59
60
61
62
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 59
def purchase(money, payment, options = {})
fetch_session_token if payment.is_a?(String)
authorize(money, payment, options, 'Sale')
end
|
#refund(money, authorization, options = {}) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 73
def refund(money, authorization, options = {})
post = { relatedTransactionId: authorization }
build_post_data(post)
add_amount(post, money, options)
commit(:refund, post)
end
|
#scrub(transcript) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 166
def scrub(transcript)
transcript.
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
gsub(%r(("cardNumber\\?":\\?")[^"\\]*)i, '\1[FILTERED]').
gsub(%r(("cardCvv\\?":\\?")\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
|
#set_initiator_type(post, payment, options) ⇒ Object
120
121
122
123
124
125
126
127
128
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 120
def set_initiator_type(post, payment, options)
is_initial_transaction = options[:stored_credential][:initial_transaction]
stored_credentials_mode = is_initial_transaction ? '0' : '1'
post[:storedCredentials] = {
storedCredentialsMode: stored_credentials_mode
}
post[:isRebilling] = stored_credentials_mode
end
|
#set_reason_type(post, options) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 142
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
96
97
98
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 96
def store(credit_card, options = {})
authorize(0, credit_card, options)
end
|
#supports_scrubbing? ⇒ Boolean
162
163
164
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 162
def supports_scrubbing?
true
end
|
#verify(credit_card, options = {}) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 89
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
82
83
84
85
86
87
|
# File 'lib/active_merchant/billing/gateways/nuvei.rb', line 82
def void(authorization, options = {})
post = { relatedTransactionId: authorization }
build_post_data(post)
commit(:void, post)
end
|