Skip to content

Commit

Permalink
Rapyd: Zero Dollar Auth
Browse files Browse the repository at this point in the history
Add support for $0 auth (verify). In order to successfully pass a $0
verify, the value much be an int.

CE-2618

Unit: 16 tests, 65 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

Remote: 23 tests, 65 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
naashton committed May 23, 2022
1 parent 3e82573 commit 9f51b76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
10 changes: 2 additions & 8 deletions lib/active_merchant/billing/gateways/rapyd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,8 @@ def void(authorization, options = {})
commit(:delete, "payments/#{authorization}", post)
end

# Gateway returns an error if trying to run a $0 auth as invalid payment amount
# Gateway does not support void on a card transaction and refunds can only be done on completed transactions
# (such as a purchase). Authorize transactions are considered 'active' and not 'complete' until they are captured.
def verify(credit_card, options = {})
MultiResponse.run do |r|
r.process { purchase(100, credit_card, options) }
r.process { refund(100, r.authorization, options) }
end
authorize(0, credit_card, options)
end

def supports_scrubbing?
Expand Down Expand Up @@ -123,7 +117,7 @@ def add_address(post, creditcard, options)
end

def add_invoice(post, money, options)
post[:amount] = amount(money).to_f.to_s
post[:amount] = money.zero? ? 0 : amount(money).to_f.to_s
post[:currency] = (options[:currency] || currency(money))
end

Expand Down
16 changes: 7 additions & 9 deletions test/unit/gateways/rapyd_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,13 @@ def test_failed_void
end

def test_successful_verify
@gateway.expects(:ssl_request).twice.returns(successful_authorize_response, successful_void_response)
@gateway.expects(:ssl_request).returns(successful_verify_response)

response = @gateway.verify(@credit_card, @options)
assert_success response
assert_equal 'SUCCESS', response.message
end

def test_successful_verify_with_failed_void
@gateway.expects(:ssl_request).twice.returns(successful_authorize_response, failed_void_response)

response = @gateway.verify(@credit_card, @options)
assert_failure response
assert_equal 'UNAUTHORIZED_API_CALL', response.message
end

def test_failed_verify
@gateway.expects(:ssl_request).returns(failed_authorize_response)

Expand Down Expand Up @@ -304,4 +296,10 @@ def failed_void_response
{"status":{"error_code":"UNAUTHORIZED_API_CALL","status":"ERROR","message":"","response_code":"UNAUTHORIZED_API_CALL","operation_id":"12e59804-b742-44eb-aa49-4b722629faa8"}}
)
end

def successful_verify_response
%(
{"status":{"error_code":"","status":"SUCCESS","message":"","response_code":"","operation_id":"27385814-fc69-46fc-bbcc-2a5e0aac442d"},"data":{"id":"payment_2736748fec92a96c7c1280f7e46e2876","amount":0,"original_amount":0,"is_partial":false,"currency_code":"USD","country_code":"US","status":"ACT","description":"","merchant_reference_id":"","customer_token":"cus_c99aab5dae41102b0bb4276ab32e7777","payment_method":"card_5a07af7ff5c038eef4802ffb200fffa6","payment_method_data":{"id":"card_5a07af7ff5c038eef4802ffb200fffa6","type":"us_visa_card","category":"card","metadata":null,"image":"","webhook_url":"","supporting_documentation":"","next_action":"3d_verification","name":"Ryan Reynolds","last4":"1111","acs_check":"unchecked","cvv_check":"unchecked","bin_details":{"type":null,"brand":null,"level":null,"country":null,"bin_number":"411111"},"expiration_year":"35","expiration_month":"12","fingerprint_token":"ocfp_eb9edd24a3f3f59651aee0bd3d16201e"},"expiration":1653942478,"captured":false,"refunded":false,"refunded_amount":0,"receipt_email":"","redirect_url":"https://sandboxcheckout.rapyd.net/3ds-payment?token=payment_2736748fec92a96c7c1280f7e46e2876","complete_payment_url":"","error_payment_url":"","receipt_number":"","flow_type":"","address":null,"statement_descriptor":"N/A","transaction_id":"","created_at":1653337678,"metadata":{},"failure_code":"","failure_message":"","paid":false,"paid_at":0,"dispute":null,"refunds":null,"order":null,"outcome":null,"visual_codes":{},"textual_codes":{},"instructions":[],"ewallet_id":null,"ewallets":[],"payment_method_options":{},"payment_method_type":"us_visa_card","payment_method_type_category":"card","fx_rate":1,"merchant_requested_currency":null,"merchant_requested_amount":null,"fixed_side":"","payment_fees":null,"invoice":"","escrow":null,"group_payment":"","cancel_reason":null,"initiation_type":"customer_present","mid":"","next_action":"3d_verification","error_code":"","remitter_information":{}}}
)
end
end

0 comments on commit 9f51b76

Please sign in to comment.