Skip to content

Commit

Permalink
Pin: Add new 3DS params mentioned in Pin Payments docs
Browse files Browse the repository at this point in the history
  • Loading branch information
huda-kh authored and AMHOL committed Jun 24, 2024
1 parent d31c20c commit 4de3c00
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Braintree: Update card verfification payload if billing address fields are not present [yunnydang] #5142
* DLocal: Update the phone and ip fields [yunnydang] #5143
* CheckoutV2: Add support for risk data fields [yunnydang] #5147
* Pin Payments: Add new 3DS params mentioned in Pin Payments docs [hudakh] #4720

== Version 1.136.0 (June 3, 2024)
* Shift4V2: Add new gateway based on SecurionPay adapter [heavyblade] #4860
Expand Down
21 changes: 17 additions & 4 deletions lib/active_merchant/billing/gateways/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def void(token, options = {})
commit(:put, "charges/#{CGI.escape(token)}/void", {}, options)
end

# Verify a previously authorized charge.
def verify_3ds(session_token, options = {})
commit(:get, "/charges/verify?session_token=#{session_token}", nil, options)
end

# Updates the credit card for the customer.
def update(token, creditcard, options = {})
post = {}
Expand Down Expand Up @@ -183,10 +188,16 @@ def add_platform_adjustment(post, options)
def add_3ds(post, options)
if options[:three_d_secure]
post[:three_d_secure] = {}
post[:three_d_secure][:version] = options[:three_d_secure][:version] if options[:three_d_secure][:version]
post[:three_d_secure][:eci] = options[:three_d_secure][:eci] if options[:three_d_secure][:eci]
post[:three_d_secure][:cavv] = options[:three_d_secure][:cavv] if options[:three_d_secure][:cavv]
post[:three_d_secure][:transaction_id] = options[:three_d_secure][:ds_transaction_id] || options[:three_d_secure][:xid]
if options[:three_d_secure][:enabled]
post[:three_d_secure][:enabled] = true
post[:three_d_secure][:fallback_ok] = options[:three_d_secure][:fallback_ok] unless options[:three_d_secure][:fallback_ok].nil?
post[:three_d_secure][:callback_url] = options[:three_d_secure][:callback_url] if options[:three_d_secure][:callback_url]
else
post[:three_d_secure][:version] = options[:three_d_secure][:version] if options[:three_d_secure][:version]
post[:three_d_secure][:eci] = options[:three_d_secure][:eci] if options[:three_d_secure][:eci]
post[:three_d_secure][:cavv] = options[:three_d_secure][:cavv] if options[:three_d_secure][:cavv]
post[:three_d_secure][:transaction_id] = options[:three_d_secure][:ds_transaction_id] || options[:three_d_secure][:xid]
end
end
end

Expand Down Expand Up @@ -271,6 +282,8 @@ def parse(body)
end

def post_data(parameters = {})
return nil unless parameters

parameters.to_json
end
end
Expand Down
20 changes: 19 additions & 1 deletion test/remote/gateways/remote_pin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ def setup
description: "Store Purchase #{DateTime.now.to_i}"
}

@additional_options_3ds = @options.merge(
@additional_options_3ds_passthrough = @options.merge(
three_d_secure: {
version: '1.0.2',
eci: '06',
cavv: 'AgAAAAAAAIR8CQrXcIhbQAAAAAA',
xid: 'MDAwMDAwMDAwMDAwMDAwMzIyNzY='
}
)

@additional_options_3ds = @options.merge(
three_d_secure: {
enabled: true,
fallback_ok: true,
callback_url: 'https://yoursite.com/authentication_complete'
}
)
end

def test_successful_purchase
Expand Down Expand Up @@ -77,6 +85,16 @@ def test_successful_authorize_and_capture
end

def test_successful_authorize_and_capture_with_passthrough_3ds
authorization = @gateway.authorize(@amount, @credit_card, @additional_options_3ds_passthrough)
assert_success authorization
assert_equal false, authorization.params['response']['captured']

response = @gateway.capture(@amount, authorization.authorization, @options)
assert_success response
assert_equal true, response.params['response']['captured']
end

def test_successful_authorize_and_capture_with_3ds
authorization = @gateway.authorize(@amount, @credit_card, @additional_options_3ds)
assert_success authorization
assert_equal false, authorization.params['response']['captured']
Expand Down
14 changes: 14 additions & 0 deletions test/unit/gateways/pin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def setup
ip: '127.0.0.1'
}

@three_d_secure = {
enabled: true,
fallback_ok: true,
callback_url: 'https://yoursite.com/authentication_complete'
}

@three_d_secure_v1 = {
version: '1.0.2',
eci: '05',
Expand Down Expand Up @@ -367,6 +373,14 @@ def test_add_creditcard_with_customer_token
assert_false post.has_key?(:card)
end

def test_add_3ds
post = {}
@gateway.send(:add_3ds, post, @options.merge(three_d_secure: @three_d_secure))
assert_equal true, post[:three_d_secure][:enabled]
assert_equal true, post[:three_d_secure][:fallback_ok]
assert_equal 'https://yoursite.com/authentication_complete', post[:three_d_secure][:callback_url]
end

def test_add_3ds_v1
post = {}
@gateway.send(:add_3ds, post, @options.merge(three_d_secure: @three_d_secure_v1))
Expand Down

0 comments on commit 4de3c00

Please # to comment.