Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airwallex: update return_url #4525

Merged
merged 1 commit into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/active_merchant/billing/gateways/airwallex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@ def initialize(options = {})
end

def purchase(money, card, options = {})
requires!(options, :return_url)

payment_intent_id = create_payment_intent(money, options)
post = {
'request_id' => request_id(options),
'merchant_order_id' => merchant_order_id(options),
'return_url' => options[:return_url]
'merchant_order_id' => merchant_order_id(options)
}
add_card(post, card, options)
add_descriptor(post, options)
add_stored_credential(post, options)
add_return_url(post, options)
post['payment_method_options'] = { 'card' => { 'auto_capture' => false } } if authorization_only?(options)

add_three_ds(post, options)
Expand Down Expand Up @@ -121,6 +119,10 @@ def merchant_order_id(options)
options[:merchant_order_id] || options[:order_id] || generate_uuid
end

def add_return_url(post, options)
post[:return_url] = options[:return_url] if options[:return_url]
end

def generate_uuid
SecureRandom.uuid
end
Expand Down
25 changes: 13 additions & 12 deletions test/unit/gateways/airwallex_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ def setup
@declined_amount = 8014

@options = {
billing_address: address,
return_url: 'https://example.com'
billing_address: address
}

@stored_credential_cit_options = { initial_transaction: true, initiator: 'cardholder', reason_type: 'recurring', network_transaction_id: nil }
Expand Down Expand Up @@ -52,12 +51,6 @@ def test_failed_purchase_with_declined_card
assert_equal 'The card issuer declined this transaction. Please refer to the original response code.', response.message
end

def test_purchase_without_return_url_raises_error
assert_raise ArgumentError do
@gateway.purchase(@amount, @credit_card, {})
end
end

def test_successful_authorize
@gateway.expects(:ssl_post).times(2).returns(successful_authorize_response)

Expand All @@ -77,10 +70,18 @@ def test_failed_authorize_with_declined_card
assert_equal 'The card issuer declined this transaction. Please refer to the original response code.', response.message
end

def test_authorize_without_return_url_raises_error
assert_raise ArgumentError do
@gateway.authorize(@amount, @credit_card, { auto_capture: false })
end
def test_successful_authorize_with_return_url
return_url = 'https://example.com'

response = stub_comms do
@gateway.authorize(@amount, @credit_card, @options.merge(return_url: return_url))
end.check_request do |endpoint, data, _headers|
assert_match(/\"return_url\":\"https:\/\/example.com\"/, data) unless endpoint == setup_endpoint
end.respond_with(successful_authorize_response)

assert_success response
assert response.test?
assert_equal 'AUTHORIZED', response.message
end

def test_successful_authorize_with_3ds_v1_options
Expand Down