Skip to content

Commit

Permalink
SafeCharge: add card holder verification fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yunnydang committed Sep 9, 2024
1 parent 78d91b0 commit 25410f8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/active_merchant/billing/gateways/safe_charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def add_customer_details(post, payment, options)
post[:sg_Zip] = address[:zip] if address[:zip]
post[:sg_Country] = address[:country] if address[:country]
post[:sg_Phone] = address[:phone] if address[:phone]
post[:sg_middleName] = options[:middle_name] if options[:middle_name]
post[:sg_doCardHolderNameVerification] = options[:card_holder_verification] if options[:card_holder_verification]
end

post[:sg_Email] = options[:email]
Expand Down
7 changes: 7 additions & 0 deletions test/remote/gateways/remote_safe_charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ def test_successful_purchase
assert_equal 'Success', response.message
end

def test_successful_purchase_with_card_holder_verification
response = @gateway.purchase(@amount, @credit_card, @options.merge(middle_name: 'middle', card_holder_verification: 1))
assert_success response
assert_equal 'Success', response.message
assert_equal '', response.params['cardholdernameverification']
end

def test_successful_purchase_with_token
response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
Expand Down
15 changes: 15 additions & 0 deletions test/unit/gateways/safe_charge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ def test_successful_purchase_with_truthy_stored_credential_mode
assert purchase.test?
end

def test_successful_purchase_with_card_holder_verification
purchase = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(middle_name: 'middle', card_holder_verification: 1))
end.check_request do |_endpoint, data, _headers|
assert_match(/sg_middleName=middle/, data)
assert_match(/sg_doCardHolderNameVerification=1/, data)
end.respond_with(successful_purchase_response)

assert_success purchase
assert_equal '111951|101508189567|ZQBpAFAASABGAHAAVgBPAFUAMABiADMAewBtAGsAd' \
'AAvAFIAQQBrAGoAYwBxACoAXABHAEEAOgA3ACsAMgA4AD0AOABDAG4AbQAzAF' \
'UAbQBYAFIAMwA=|%02d|%d|1.00|USD' % [@credit_card.month, @credit_card.year.to_s[-2..-1]], purchase.authorization
assert purchase.test?
end

def test_successful_purchase_with_falsey_stored_credential_mode
purchase = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge(stored_credential_mode: false))
Expand Down

0 comments on commit 25410f8

Please sign in to comment.