Class: ActiveMerchant::Billing::WorldpayGateway
- Inherits:
-
Gateway
- Object
- Gateway
- ActiveMerchant::Billing::WorldpayGateway
show all
- Defined in:
- lib/active_merchant/billing/gateways/worldpay.rb
Constant Summary
collapse
- NETWORK_TOKEN_TYPE =
{
apple_pay: 'APPLEPAY',
google_pay: 'GOOGLEPAY',
network_token: 'NETWORKTOKEN'
}
- AVS_CODE_MAP =
{
'A' => 'M', 'B' => 'P', 'C' => 'Z', 'D' => 'B', 'E' => 'I', 'F' => 'A', 'G' => 'C', 'H' => 'I', 'I' => 'C', 'J' => 'C' }
- CVC_CODE_MAP =
{
'A' => 'M', 'B' => 'P', 'C' => 'P', 'D' => 'N' }
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
-
#credit(money, payment_method, options = {}) ⇒ Object
Credits only function on a Merchant ID/login/profile flagged for Payouts aka Credit Fund Transfers (CFT), whereas normal purchases, refunds, and other transactions should be performed on a normal eCom-flagged merchant ID.
-
#initialize(options = {}) ⇒ WorldpayGateway
constructor
A new instance of WorldpayGateway.
-
#inquire(authorization, options = {}) ⇒ Object
-
#purchase(money, payment_method, options = {}) ⇒ Object
-
#refund(money, authorization, options = {}) ⇒ Object
-
#scrub(transcript) ⇒ Object
-
#store(credit_card, options = {}) ⇒ Object
-
#supports_network_tokenization? ⇒ Boolean
-
#supports_scrubbing ⇒ Object
-
#verify(payment_method, 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_scrubbing?, #test?
#expdate, #format, #strftime_yyyymm
Methods included from PostsData
included, #raw_ssl_request, #ssl_get, #ssl_post, #ssl_request
Constructor Details
Returns a new instance of WorldpayGateway.
51
52
53
54
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 51
def initialize(options = {})
requires!(options, :login, :password)
super
end
|
Instance Method Details
#authorize(money, payment_method, options = {}) ⇒ Object
63
64
65
66
67
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 63
def authorize(money, payment_method, options = {})
requires!(options, :order_id)
payment_details = payment_details(payment_method, options)
authorize_request(money, payment_method, payment_details.merge(options))
end
|
#capture(money, authorization, options = {}) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 69
def capture(money, authorization, options = {})
authorization = order_id_from_authorization(authorization.to_s)
MultiResponse.run do |r|
r.process { inquire_request(authorization, options, 'AUTHORISED', 'CAPTURED') } unless options[:authorization_validated]
if r.params
authorization_currency = r.params['amount_currency_code']
options = options.merge(currency: authorization_currency) if authorization_currency.present?
end
r.process { capture_request(money, authorization, options) }
end
end
|
#credit(money, payment_method, options = {}) ⇒ Object
Credits only function on a Merchant ID/login/profile flagged for Payouts
aka Credit Fund Transfers (CFT), whereas normal purchases, refunds,
and other transactions should be performed on a normal eCom-flagged
merchant ID.
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 110
def credit(money, payment_method, options = {})
payment_details = payment_details(payment_method, options)
if options[:fast_fund_credit]
fast_fund_credit_request(money, payment_method, payment_details.merge(credit: true, **options))
elsif options[:account_funding_transaction]
aft_request(money, payment_method, payment_details.merge(**options))
else
credit_request(money, payment_method, payment_details.merge(credit: true, **options))
end
end
|
#inquire(authorization, options = {}) ⇒ Object
134
135
136
137
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 134
def inquire(authorization, options = {})
order_id = order_id_from_authorization(authorization.to_s) || options[:order_id]
commit('direct_inquiry', build_order_inquiry_request(order_id, options), :ok, options)
end
|
#purchase(money, payment_method, options = {}) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 56
def purchase(money, payment_method, options = {})
MultiResponse.run do |r|
r.process { authorize(money, payment_method, options) }
r.process { capture(money, r.authorization, options.merge(authorization_validated: true)) } unless options[:skip_capture]
end
end
|
#refund(money, authorization, options = {}) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 89
def refund(money, authorization, options = {})
authorization = order_id_from_authorization(authorization.to_s)
success_criteria = %w(CAPTURED SETTLED SETTLED_BY_MERCHANT SENT_FOR_REFUND)
success_criteria.push('AUTHORIZED') if options[:cancel_or_refund]
response = MultiResponse.run do |r|
r.process { inquire_request(authorization, options, *success_criteria) } unless options[:authorization_validated]
r.process { refund_request(money, authorization, options) }
end
if !response.success? && options[:force_full_refund_if_unsettled] &&
response.params['last_event'] == 'AUTHORISED'
void(authorization, options)
else
response
end
end
|
#scrub(transcript) ⇒ Object
147
148
149
150
151
152
153
154
155
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 147
def scrub(transcript)
transcript.
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
gsub(%r((<cardNumber>)\d+(</cardNumber>)), '\1[FILTERED]\2').
gsub(%r((<cvc>)[^<]+(</cvc>)), '\1[FILTERED]\2').
gsub(%r((<tokenNumber>)\d+(</tokenNumber>)), '\1[FILTERED]\2').
gsub(%r((<cryptogram>)[^<]+(</cryptogram>)), '\1[FILTERED]\2').
gsub(%r((<accountReference accountType="\w+">)\d+(<\/accountReference>)), '\1[FILTERED]\2')
end
|
#store(credit_card, options = {}) ⇒ Object
129
130
131
132
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 129
def store(credit_card, options = {})
requires!(options, :customer)
store_request(credit_card, options)
end
|
#supports_network_tokenization? ⇒ Boolean
143
144
145
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 143
def supports_network_tokenization?
true
end
|
#supports_scrubbing ⇒ Object
139
140
141
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 139
def supports_scrubbing
true
end
|
#verify(payment_method, options = {}) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 121
def verify(payment_method, options = {})
amount = (eligible_for_0_auth?(payment_method, options) ? 0 : 100)
MultiResponse.run(:use_first_response) do |r|
r.process { authorize(amount, payment_method, options) }
r.process(:ignore_result) { void(r.authorization, options.merge(authorization_validated: true)) }
end
end
|
#void(authorization, options = {}) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/active_merchant/billing/gateways/worldpay.rb', line 81
def void(authorization, options = {})
authorization = order_id_from_authorization(authorization.to_s)
MultiResponse.run do |r|
r.process { inquire_request(authorization, options, 'AUTHORISED') } unless options[:authorization_validated]
r.process { cancel_request(authorization, options) }
end
end
|