Skip to content

Commit

Permalink
Rapyd: Additional Fields
Browse files Browse the repository at this point in the history
Add support for:
* `complete_payment_url`
* `error_payment_url`
* `description`
* `statement_descriptor`

These fields are subfields of the `payment` object

CE-2606

Unit: 18 tests, 76 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote: 23 tests, 65 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
naashton committed May 23, 2022
1 parent 62aef70 commit 784aedc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/active_merchant/billing/gateways/rapyd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def purchase(money, payment, options = {})
add_address(post, payment, options)
add_metadata(post, options)
add_ewallet(post, options)
add_payment_fields(post, options)
post[:capture] = true if payment_is_card?(options)

if payment_is_ach?(options)
Expand All @@ -49,6 +50,7 @@ def authorize(money, payment, options = {})
add_address(post, payment, options)
add_metadata(post, options)
add_ewallet(post, options)
add_payment_fields(post, options)
post[:capture] = false

commit(:post, 'payments', post)
Expand Down Expand Up @@ -181,6 +183,15 @@ def add_ewallet(post, options)
post[:ewallet_id] = options[:ewallet_id] if options[:ewallet_id]
end

def add_payment_fields(post, options)
post[:payment] = {}

post[:payment][:complete_payment_url] = options[:complete_payment_url] if options[:complete_payment_url]
post[:payment][:error_payment_url] = options[:error_payment_url] if options[:error_payment_url]
post[:payment][:description] = options[:description] if options[:description]
post[:payment][:statement_descriptor] = options[:statement_descriptor] if options[:statement_descriptor]
end

def parse(body)
return {} if body.empty? || body.nil?

Expand Down
8 changes: 6 additions & 2 deletions test/remote/gateways/remote_rapyd_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ class RemoteRapydTest < Test::Unit::TestCase
def setup
@gateway = RapydGateway.new(fixtures(:rapyd))

@amount = 100
@amount = 100000
@credit_card = credit_card('4111111111111111', first_name: 'Ryan', last_name: 'Reynolds', month: '12', year: '2035', verification_value: '345')
@declined_card = credit_card('4111111111111105')
@check = check
@options = {
pm_type: 'us_visa_card',
currency: 'USD'
currency: 'USD',
complete_payment_url: 'www.google.com',
error_payment_url: 'www.google.com',
description: 'Describe this transaction',
statement_descriptor: 'Statement Descriptor'
}
@ach_options = {
pm_type: 'us_ach_bank',
Expand Down
19 changes: 18 additions & 1 deletion test/unit/gateways/rapyd_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ def setup

@options = {
pm_type: 'in_amex_card',
currency: 'USD'
currency: 'USD',
complete_payment_url: 'www.google.com',
error_payment_url: 'www.google.com',
description: 'Describe this transaction',
statement_descriptor: 'Statement Descriptor'
}

@metadata = {
Expand Down Expand Up @@ -57,6 +61,19 @@ def test_successful_purchase_with_options
assert_equal @metadata, response.params['data']['metadata'].deep_transform_keys(&:to_sym)
end

def test_successful_purchase_with_payment_options
response = stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, @credit_card, @options)
end.check_request do |_method, _endpoint, data, _headers|
assert_match(/"complete_payment_url":"www.google.com"/, data)
assert_match(/"error_payment_url":"www.google.com"/, data)
assert_match(/"description":"Describe this transaction"/, data)
assert_match(/"statement_descriptor":"Statement Descriptor"/, data)
end.respond_with(successful_authorize_response)

assert_success response
end

def test_failed_purchase
@gateway.expects(:ssl_request).returns(failed_purchase_response)

Expand Down

0 comments on commit 784aedc

Please sign in to comment.