diff --git a/lib/active_merchant/billing/gateways/airwallex.rb b/lib/active_merchant/billing/gateways/airwallex.rb index 6bcbc3c2b93..8b972de7c79 100644 --- a/lib/active_merchant/billing/gateways/airwallex.rb +++ b/lib/active_merchant/billing/gateways/airwallex.rb @@ -168,6 +168,7 @@ def create_payment_intent(money, options = {}) post[:merchant_order_id] = merchant_order_id(options) add_referrer_data(post) add_descriptor(post, options) + add_metadata(post, options) post['payment_method_options'] = { 'card' => { 'risk_control' => { 'three_ds_action' => 'SKIP_3DS' } } } if options[:skip_3ds] response = commit(:setup, post) @@ -176,6 +177,10 @@ def create_payment_intent(money, options = {}) response.params['id'] end + def add_metadata(post, options) + post[:metadata] = options[:metadata] if options[:metadata] + end + def add_billing(post, card, options = {}) return unless has_name_info?(card) diff --git a/test/unit/gateways/airwallex_test.rb b/test/unit/gateways/airwallex_test.rb index e66dbb3d584..939f1477227 100644 --- a/test/unit/gateways/airwallex_test.rb +++ b/test/unit/gateways/airwallex_test.rb @@ -308,6 +308,15 @@ def test_purchase_passes_referrer_data end.respond_with(successful_purchase_response) end + def test_purchase_passes_metadata + stub_comms do + @gateway.purchase(@amount, @credit_card, @options.merge(metadata: { some: 'value' })) + end.check_request do |_endpoint, data, _headers| + # only look for referrer data on the create_payment_intent request + assert_match(/\"metadata\":{\"some\":\"value\"}/, data) if data.include?('_setup') + end.respond_with(successful_purchase_response) + end + def test_purchase_passes_descriptor stub_comms do @gateway.purchase(@amount, @credit_card, @options.merge(description: 'a simple test'))