Skip to content

Commit

Permalink
Reach: remove raise exception when pymentMethod is not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
Heavyblade committed Dec 29, 2022
1 parent e40e1ee commit 7b973d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
4 changes: 1 addition & 3 deletions lib/active_merchant/billing/gateways/reach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ def verify(credit_card, options = {})
private

def build_checkout_request(amount, payment, options)
raise ArgumentError.new("Payment method #{payment.brand} is not supported, check https://docs.withreach.com/docs/credit-cards#technical-considerations") if PAYMENT_METHOD_MAP[payment.brand.to_sym].blank?

{
MerchantId: @options[:merchant_id],
ReferenceId: options[:order_id],
ConsumerCurrency: options[:currency] || currency(options[:amount]),
Capture: options[:capture] || false,
PaymentMethod: PAYMENT_METHOD_MAP[payment.brand.to_sym],
PaymentMethod: PAYMENT_METHOD_MAP.fetch(payment.brand.to_sym, 'unsupported'),
Items: [
Sku: options[:item_sku] || SecureRandom.alphanumeric,
ConsumerPrice: amount,
Expand Down
7 changes: 7 additions & 0 deletions test/remote/gateways/remote_reach_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def test_failed_authorize
assert_equal 'Invalid ConsumerCurrency', response.message
end

def test_failed_authorize_with_not_supported_payment_method
response = @gateway.authorize(@amount, @not_supported_cc, @options)

assert_failure response
assert_equal 'PaymentMethodUnsupported', response.error_code
end

def test_successful_purchase
response = @gateway.purchase(@amount, @credit_card, @options)

Expand Down
30 changes: 15 additions & 15 deletions test/unit/gateways/reach_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,27 @@ def test_stored_credential_with_no_store_credential_parameters
end

def test_stored_credential_with_wrong_combination_stored_credential_paramaters
@options[:stored_credential] = { initiator: 'merchant', initial_transaction: true, reason_type: 'unschedule' }
e = assert_raise ArgumentError do
@options[:stored_credential] = { initiator: 'merchant', initial_transaction: true, reason_type: 'unscheduled' }
@gateway.expects(:get_network_payment_reference).returns(stub(message: 'abc123', "success?": true))

stub_comms do
@gateway.purchase(@amount, @credit_card, @options)
end
assert_equal e.message, 'Unexpected combination of stored credential fields'
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(URI.decode_www_form(data)[0][1])
assert_empty request['PaymentModel']
end.respond_with(successful_purchase_response)
end

def test_stored_credential_with_at_lest_one_stored_credential_paramaters_nil
@options[:stored_credential] = { initiator: 'merchant', initial_transaction: true, reason_type: nil }
e = assert_raise ArgumentError do
@gateway.expects(:get_network_payment_reference).returns(stub(message: 'abc123', "success?": true))

stub_comms do
@gateway.purchase(@amount, @credit_card, @options)
end
assert_equal e.message, 'Unexpected combination of stored credential fields'
end.check_request do |_endpoint, data, _headers|
request = JSON.parse(URI.decode_www_form(data)[0][1])
assert_empty request['PaymentModel']
end.respond_with(successful_purchase_response)
end

def test_scrub
Expand All @@ -185,14 +193,6 @@ def test_scrub
assert_equal @gateway.scrub(pre_scrubbed), post_scrubbed
end

def test_raises_exceptio_when_card_brand_is_not_allowed
error = assert_raises(ArgumentError) do
@credit_card.brand = 'alelo'
@gateway.authorize(@amount, @credit_card, @options)
end
assert_equal 'Payment method alelo is not supported, check https://docs.withreach.com/docs/credit-cards#technical-considerations', error.message
end

private

def successful_purchase_response
Expand Down

0 comments on commit 7b973d9

Please sign in to comment.