Skip to content

Commit dfc89c8

Browse files
committed
Support 3D Secure parameters for link type payments
1 parent 0cf42d4 commit dfc89c8

File tree

7 files changed

+113
-17
lines changed

7 files changed

+113
-17
lines changed

lib/active_merchant/billing/gateways/epsilon.rb

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,6 @@ module CreditType
2222
capture: 'sales_payment.cgi',
2323
}.freeze
2424

25-
RISK_BASE_AUTH_PARAMS_KEYS = %i[
26-
tds_flag billAddrCity billAddrCountry billAddrLine1 billAddrLine2 billAddrLine3
27-
billAddrPostCode billAddrState shipAddrCity shipAddrCountry shipAddrLine1 shipAddrLine2
28-
shipAddrLine3 shipAddrPostCode shipAddrState chAccAgeInd chAccChange
29-
chAccChangeIndchAccDate chAccPwdChange chAccPwChangeInd nbPurchaseAccount paymentAccAge
30-
paymentAccInd provisionAttemptsDay shipAddressUsage shipAddressUsageInd shipNameIndicator
31-
suspiciousAccActivity txnActivityDay txnActivityYear threeDSReqAuthData threeDSReqAuthMethod
32-
threeDSReqAuthTimestamp addrMatch cardholderName homePhone mobilePhone
33-
workPhone challengeInd deliveryEmailAddress deliveryTimeframe giftCardAmount
34-
giftCardCount preOrderDate preOrderPurchaseInd reorderItemsInd shipIndicator
35-
].freeze
36-
37-
THREE_D_SECURE_2_INDICATORS = [21, 22].freeze
38-
3925
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
4026

4127
def purchase(amount, credit_card, detail = {})
@@ -44,7 +30,7 @@ def purchase(amount, credit_card, detail = {})
4430
params = billing_params(amount, credit_card, detail)
4531

4632
if three_d_secure_2?(detail)
47-
params.merge!(detail.slice(*RISK_BASE_AUTH_PARAMS_KEYS).compact)
33+
params.merge!(detail.slice(*EpsilonRiskBaseAuthParams::KEYS).compact)
4834
end
4935

5036
commit(PATHS[:purchase], params)
@@ -73,7 +59,7 @@ def registered_purchase(amount, detail = {})
7359
params[:kari_flag] = detail[:capture] ? 2 : 1 if detail.has_key?(:capture)
7460

7561
if three_d_secure_2?(detail)
76-
params.merge!(detail.slice(*RISK_BASE_AUTH_PARAMS_KEYS).compact)
62+
params.merge!(detail.slice(*EpsilonRiskBaseAuthParams::KEYS).compact)
7763
end
7864

7965
commit(PATHS[:registered_purchase], params)
@@ -263,7 +249,7 @@ def billing_params(amount, payment_method, detail)
263249
end
264250

265251
def three_d_secure_2?(detail)
266-
THREE_D_SECURE_2_INDICATORS.include?(detail[:tds_flag])
252+
EpsilonRiskBaseAuthParams.three_d_secure_2?(detail[:tds_flag])
267253
end
268254
end
269255
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
module ActiveMerchant #:nodoc:
2+
module Billing #:nodoc:
3+
module EpsilonRiskBaseAuthParams
4+
KEYS = %i[
5+
tds_flag billAddrCity billAddrCountry billAddrLine1 billAddrLine2 billAddrLine3
6+
billAddrPostCode billAddrState shipAddrCity shipAddrCountry shipAddrLine1 shipAddrLine2
7+
shipAddrLine3 shipAddrPostCode shipAddrState chAccAgeInd chAccChange
8+
chAccChangeIndchAccDate chAccPwdChange chAccPwChangeInd nbPurchaseAccount paymentAccAge
9+
paymentAccInd provisionAttemptsDay shipAddressUsage shipAddressUsageInd shipNameIndicator
10+
suspiciousAccActivity txnActivityDay txnActivityYear threeDSReqAuthData threeDSReqAuthMethod
11+
threeDSReqAuthTimestamp addrMatch cardholderName homePhone mobilePhone
12+
workPhone challengeInd deliveryEmailAddress deliveryTimeframe giftCardAmount
13+
giftCardCount preOrderDate preOrderPurchaseInd reorderItemsInd shipIndicator
14+
].freeze
15+
16+
THREE_D_SECURE_2_INDICATORS = [21, 22].freeze
17+
18+
def three_d_secure_2?(tds_flag)
19+
THREE_D_SECURE_2_INDICATORS.include?(tds_flag)
20+
end
21+
22+
module_function :three_d_secure_2?
23+
end
24+
end
25+
end

lib/active_merchant/billing/gateways/epsilon_link_payment.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def purchase(amount, detail = {}, delivery_info_required = true)
3939
params[:memo2] = detail[:memo2] if detail.has_key?(:memo2)
4040
params[:user_tel] = detail[:user_tel] if detail.has_key?(:user_tel)
4141

42+
if three_d_secure_2?(detail)
43+
params.merge!(detail.slice(*EpsilonRiskBaseAuthParams::KEYS).compact)
44+
end
45+
4246
commit('receive_order3.cgi', params, RESPONSE_KEYS)
4347
end
4448

@@ -50,6 +54,12 @@ def void(order_number)
5054

5155
commit('cancel_payment.cgi', params)
5256
end
57+
58+
private
59+
60+
def three_d_secure_2?(detail)
61+
EpsilonRiskBaseAuthParams.three_d_secure_2?(detail[:tds_flag])
62+
end
5363
end
5464
end
5565
end

lib/active_merchant/epsilon.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require_relative 'billing/convenience_store'
66
require_relative 'billing/gateways/epsilon/epsilon_mission_code'
77
require_relative 'billing/gateways/epsilon/epsilon_process_code'
8+
require_relative 'billing/gateways/epsilon/epsilon_risk_base_auth_params'
89
require_relative 'billing/gateways/epsilon/epsilon_base'
910
require_relative 'billing/gateways/epsilon'
1011
require_relative 'billing/gateways/epsilon_convenience_store'

test/fixtures/vcr_cassettes/epsilon_link_type_with_3d_secure.yml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/remote/gateways/remote_epsilon_link_payment_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ def test_epsilon_link_type_purchase_fail
3333
end
3434
end
3535

36+
def test_epsilon_link_type_with_3d_secure
37+
ActiveMerchant::Billing::Base.stub(:mode, :production) do
38+
VCR.use_cassette(:epsilon_link_type_with_3d_secure) do
39+
response = gateway.purchase(10000, valid_epsilon_link_type_purchase_detail_for_3d_secure, false)
40+
41+
pp response
42+
end
43+
end
44+
end
45+
3646
def test_epsilon_link_type_void_successfull
3747
VCR.use_cassette(:epsilon_link_type_void_successfull) do
3848
# あらかじめ課金済ステータスの受注がイプシロン側にないと取り消しができないため、課金済の受注をイプシロン側で作成しておいた。

test/test_helper.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,22 @@ def valid_epsilon_link_type_not_sending_delivery_information_purchase_detail
295295
}
296296
end
297297

298+
def valid_epsilon_link_type_purchase_detail_for_3d_secure
299+
now = Time.now
300+
{
301+
user_id: "U#{Time.now.to_i}",
302+
user_name: '山田 太郎',
303+
user_email: 'yamada-taro@example.com',
304+
item_code: 'ITEM001',
305+
item_name: 'Greate Product',
306+
order_number: "O#{now.sec}#{now.usec}",
307+
st_code: '10000-0000-00000-00000-00000-00000-00000',
308+
memo1: 'memo1',
309+
memo2: 'memo2',
310+
tds_flag: 21
311+
}
312+
end
313+
298314
def invalid_epsilon_link_type_purchase_detail
299315
now = Time.now
300316
{

0 commit comments

Comments
 (0)