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 Nov 30, 2023
1 parent bab2f49 commit 7d653f4
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 @@ -69,6 +69,7 @@
* WorldPay: Accept GooglePay pan only [almalee24] #4943
* Braintree: Correct issue in v2 stored credentials [aenand] #4967
* Stripe Payment Intents: Add the card brand field [yunnydang] #4964
* Pin Payments: Add new 3DS params mentioned in Pin Payments docs [hudakh] #4720

== Version 1.135.0 (August 24, 2023)
* PaymentExpress: Correct endpoints [steveh] #4827
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 @@ -81,6 +81,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 @@ -178,10 +183,16 @@ def add_metadata(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 @@ -266,6 +277,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 @@ -63,6 +71,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 @@ -353,6 +359,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 7d653f4

Please # to comment.