Skip to content

Commit

Permalink
Rapyd: Add fields and update stored credential method
Browse files Browse the repository at this point in the history
Local:
5588 tests, 77761 assertions, 0 failures, 19 errors, 0 pendings, 0 omissions, 0 notifications
99.66% passed

Unit:
27 tests, 137 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote:
34 tests, 95 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
yunnydang committed Sep 6, 2023
1 parent 2eeb3ab commit f2b2fcb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* TNS: Use the specified order_id in request if available [yunnydang] #4880
* Cybersource: Support recurring apple pay [aenand] #4874
* Verve BIN ranges and add card type to Rapyd gateway [jherreraa] #4875
* Rapyd: Add network_reference_id, initiation_type, and update stored credential method [yunnydang] #4877

== Version 1.135.0 (August 24, 2023)
* PaymentExpress: Correct endpoints [steveh] #4827
Expand Down
18 changes: 15 additions & 3 deletions lib/active_merchant/billing/gateways/rapyd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,22 @@ def add_payment(post, payment, options)
end

def add_stored_credential(post, options)
return unless stored_credential = options[:stored_credential]
add_network_reference_id(post, options)
add_initiation_type(post, options)
end

def add_network_reference_id(post, options)
return unless options[:stored_credential] || options[:network_transaction_id]

network_transaction_id = options[:network_transaction_id] || options[:stored_credential][:network_transaction_id]
post[:payment_method][:fields][:network_reference_id] = network_transaction_id if network_transaction_id
end

def add_initiation_type(post, options)
return unless options[:stored_credential] || options[:initiation_type]

post[:payment_method][:fields][:network_reference_id] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id]
post[:initiation_type] = stored_credential[:reason_type] if stored_credential[:reason_type]
initiation_type = options[:initiation_type] || options[:stored_credential][:reason_type]
post[:initiation_type] = initiation_type if initiation_type
end

def add_creditcard(post, payment, options)
Expand Down
31 changes: 26 additions & 5 deletions test/remote/gateways/remote_rapyd_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ def setup
billing_address: address(name: 'Jim Reynolds'),
order_id: '987654321'
}
@stored_credential_options = {
pm_type: 'gb_visa_card',
currency: 'GBP',
complete_payment_url: 'https://www.rapyd.net/platform/collect/online/',
error_payment_url: 'https://www.rapyd.net/platform/collect/online/',
description: 'Describe this transaction',
statement_descriptor: 'Statement Descriptor',
email: '[email protected]',
billing_address: address(name: 'Jim Reynolds'),
order_id: '987654321'
}
@ach_options = {
pm_type: 'us_ach_bank',
currency: 'USD',
Expand Down Expand Up @@ -81,15 +92,25 @@ def test_success_purchase_without_address_object_customer
end

def test_successful_subsequent_purchase_with_stored_credential
@options[:currency] = 'GBP'
@options[:pm_type] = 'gb_visa_card'
@options[:complete_payment_url] = 'https://www.rapyd.net/platform/collect/online/'
@options[:error_payment_url] = 'https://www.rapyd.net/platform/collect/online/'
# Rapyd requires a random int between 10 and 15 digits for NTID
response = @gateway.purchase(15000, @credit_card, @stored_credential_options.merge(stored_credential: { network_transaction_id: rand.to_s[2..11], reason_type: 'recurring' }))
assert_success response
assert_equal 'SUCCESS', response.message
end

def test_successful_purchase_with_network_transaction_id_and_initiation_type_fields
# Rapyd requires a random int between 10 and 15 digits for NTID
response = @gateway.purchase(15000, @credit_card, @stored_credential_options.merge(network_transaction_id: rand.to_s[2..11], initiation_type: 'customer_present'))
assert_success response
assert_equal 'SUCCESS', response.message
end

def test_successful_purchase_with_network_transaction_id_and_initiation_type_fields_along_with_stored_credentials
# Rapyd requires a random int between 10 and 15 digits for NTID
response = @gateway.purchase(15000, @credit_card, @options.merge({ stored_credential: { network_transaction_id: rand.to_s[2..11], reason_type: 'recurring' } }))
response = @gateway.purchase(15000, @credit_card, @stored_credential_options.merge(stored_credential: { network_transaction_id: rand.to_s[2..11], reason_type: 'recurring' }, network_transaction_id: rand.to_s[2..11], initiation_type: 'customer_present'))
assert_success response
assert_equal 'SUCCESS', response.message
assert_equal 'customer_present', response.params['data']['initiation_type']
end

def test_successful_purchase_with_address
Expand Down
13 changes: 13 additions & 0 deletions test/unit/gateways/rapyd_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ def test_successful_purchase_with_stored_credential
end.respond_with(successful_purchase_response)
end

def test_successful_purchase_with_network_transaction_id_and_initiation_type_fields
@options[:network_transaction_id] = '54321'
@options[:initiation_type] = 'customer_present'

stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, @credit_card, @options)
end.check_request do |_method, _endpoint, data, _headers|
request = JSON.parse(data)
assert_equal request['payment_method']['fields']['network_reference_id'], @options[:network_transaction_id]
assert_equal request['initiation_type'], @options[:initiation_type]
end.respond_with(successful_purchase_response)
end

def test_successful_purchase_with_3ds_gateway_specific
@options[:three_d_secure] = {
required: true,
Expand Down

0 comments on commit f2b2fcb

Please sign in to comment.