Skip to content

Commit

Permalink
Commerce Hub - Add a couple of GSFs (#4786)
Browse files Browse the repository at this point in the history
Description
-------------------------
Add:
physical_goods_indicator maps to physicalGoodsIndicator inside of transactionDetails
scheme_reference_transaction_id maps to schemeReferenceTransactionId inside of storedCredentials

SER-501

Unit test
-------------------------
Finished in 33.616793 seconds.

5511 tests, 77405 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote test
-------------------------
163.94 tests/s, 2302.57 assertions/s

Rubocop
-------------------------
Inspecting 760 files
760 files inspected, no offenses detected

Co-authored-by: Luis <sinourain+endava@gmail.com>
Co-authored-by: Nick Ashton <nashton@gmail.com>
  • Loading branch information
3 people committed Jun 26, 2023
1 parent aeaa33c commit 34c2caa
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

== HEAD
* Stripe Payment Intents: Add support for new card on file field [aenand] #4807
* Commerce Hub: Add `physicalGoodsIndicator` and `schemeReferenceTransactionId` GSFs [sinourain] #4786

== Version 1.131.0 (June 21, 2023)
* Redsys: Add supported countries [jcreiff] #4811
Expand Down
8 changes: 6 additions & 2 deletions lib/active_merchant/billing/gateways/commerce_hub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def add_transaction_interaction(post, options)
end

def add_transaction_details(post, options, action = nil)
details = { captureFlag: options[:capture_flag], createToken: options[:create_token] }
details = {
captureFlag: options[:capture_flag],
createToken: options[:create_token],
physicalGoodsIndicator: [true, 'true'].include?(options[:physical_goods_indicator])
}

if options[:order_id].present? && action == 'sale'
details[:merchantOrderId] = options[:order_id]
Expand Down Expand Up @@ -214,7 +218,7 @@ def add_stored_credentials(post, options)
post[:storedCredentials][:sequence] = stored_credential[:initial_transaction] ? 'FIRST' : 'SUBSEQUENT'
post[:storedCredentials][:initiator] = stored_credential[:initiator] == 'merchant' ? 'MERCHANT' : 'CARD_HOLDER'
post[:storedCredentials][:scheduled] = SCHEDULED_REASON_TYPES.include?(stored_credential[:reason_type])
post[:storedCredentials][:schemeReferenceTransactionId] = stored_credential[:network_transaction_id] if stored_credential[:network_transaction_id]
post[:storedCredentials][:schemeReferenceTransactionId] = options[:scheme_reference_transaction_id] || stored_credential[:network_transaction_id]
end

def add_credit_card(source, payment, options)
Expand Down
14 changes: 11 additions & 3 deletions test/remote/gateways/remote_commerce_hub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def test_successful_purchase
assert_equal 'Approved', response.message
end

def test_successful_purchase_whit_physical_goods_indicator
@options[:physical_goods_indicator] = true
response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert_equal 'Approved', response.message
assert response.params['transactionDetails']['physicalGoodsIndicator']
end

def test_successful_purchase_with_gsf_mit
@options[:data_entry_source] = 'ELECTRONIC_PAYMENT_TERMINAL'
@options[:pos_entry_mode] = 'CONTACTLESS'
Expand Down Expand Up @@ -109,7 +117,7 @@ def test_successful_purchase_with_stored_credential_framework
def test_failed_purchase
response = @gateway.purchase(@amount, @declined_card, @options)
assert_failure response
assert_equal 'Unable to assign card to brand: Invalid', response.message
assert_match 'Unable to assign card to brand: Invalid', response.message
assert_equal '104', response.error_code
end

Expand All @@ -131,7 +139,7 @@ def test_successful_authorize
def test_failed_authorize
response = @gateway.authorize(@amount, @declined_card, @options)
assert_failure response
assert_equal 'Unable to assign card to brand: Invalid', response.message
assert_match 'Unable to assign card to brand: Invalid', response.message
end

def test_successful_authorize_and_void
Expand Down Expand Up @@ -235,7 +243,7 @@ def test_successful_purchase_with_apple_pay
def test_failed_purchase_with_declined_apple_pay
response = @gateway.purchase(@amount, @declined_apple_pay, @options)
assert_failure response
assert_equal 'Unable to assign card to brand: Invalid', response.message
assert_match 'Unable to assign card to brand: Invalid', response.message
end

def test_transcript_scrubbing
Expand Down
15 changes: 15 additions & 0 deletions test/unit/gateways/commerce_hub_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,21 @@ def test_successful_purchase_mit_with_gsf
assert_success response
end

def test_successful_purchase_with_gsf_scheme_reference_transaction_id
@options = stored_credential_options(:cardholder, :unscheduled, :initial)
@options[:physical_goods_indicator] = true
@options[:scheme_reference_transaction_id] = '12345'
response = stub_comms do
@gateway.purchase(@amount, @credit_card, @options)
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(data)
assert_equal request['storedCredentials']['schemeReferenceTransactionId'], '12345'
assert_equal request['transactionDetails']['physicalGoodsIndicator'], true
end.respond_with(successful_purchase_response)

assert_success response
end

def stored_credential_options(*args, ntid: nil)
{
order_id: '#1001',
Expand Down

0 comments on commit 34c2caa

Please sign in to comment.