Skip to content

Commit 96261cd

Browse files
committed
Paysafe: Add pending settlement support
Add support for detecting pending settlements and marking transactions as pending when any settlement has PENDING status. Remote: 37 tests, 107 assertions, 0 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications 97.2973% passed
1 parent 122496e commit 96261cd

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
* Normalize API Version for Plexo, Pin, Priority [adarsh-spreedly] #5517
203203
* Stripe PI: Update API version [almalee24] #5360
204204
* Airwallex: Add optional products array field [yunnydang] #5530
205+
* Paysafe: Add pending settlement support [sumit-sharmas] #5526
205206

206207
== Version 1.137.0 (August 2, 2024)
207208
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).

lib/active_merchant/billing/gateways/paysafe.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,8 @@ def commit(method, action, parameters, options)
372372
avs_result: AVSResult.new(code: response['avsResponse']),
373373
cvv_result: CVVResult.new(response['cvvVerification']),
374374
test: test?,
375-
error_code: success ? nil : error_code_from(response)
375+
error_code: success ? nil : error_code_from(response),
376+
pending: pending_from_settlements(response)
376377
)
377378
end
378379

@@ -393,6 +394,10 @@ def url(action, options = {})
393394
end
394395
end
395396

397+
def pending_from_settlements(response)
398+
response['settlements']&.any? { |settlement| settlement['status'] == 'PENDING' }
399+
end
400+
396401
def success_from(response)
397402
return false if response['status'] == 'FAILED' || response['error']
398403

test/remote/gateways/remote_paysafe_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,12 @@ def test_successful_credit
445445
assert_match 'PENDING', response.message
446446
end
447447

448+
def test_purchase_with_pending_settlement
449+
response = @gateway.purchase(@amount, @credit_card, @options)
450+
assert_success response
451+
assert response.pending
452+
end
453+
448454
def test_invalid_login
449455
gateway = PaysafeGateway.new(username: 'badbunny', password: 'carrotsrock', account_id: 'rejectstew')
450456

test/unit/gateways/paysafe_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ def test_successful_purchase
2727
assert response.test?
2828
end
2929

30+
def test_purchase_with_pending_settlement
31+
@gateway.expects(:ssl_request).returns(successful_purchase_response)
32+
33+
response = @gateway.purchase(@amount, @credit_card, @options)
34+
assert_success response
35+
36+
assert response.pending
37+
end
38+
39+
def test_purchase_with_completed_settlements
40+
@gateway.expects(:ssl_request).returns(purchase_response_with_completed_settlements)
41+
42+
response = @gateway.purchase(@amount, @credit_card, @options)
43+
assert_success response
44+
45+
assert !response.pending
46+
end
47+
3048
def test_successful_purchase_with_mastercard_3ds2
3149
mc_three_d_secure_2_options = {
3250
currency: 'EUR',
@@ -453,4 +471,8 @@ def successful_store_response
453471
def successful_credit_response
454472
'{"id":"b40c327e-92d7-4026-a043-be1f1b03c08a","merchantRefNum":"b0ca10f1ab6b782e6bf8a43e17ff41f8","txnTime":"2024-10-02T19:00:27Z","status":"PENDING","gatewayReconciliationId":"2309329680","amount":100,"card":{"type":"VI", "lastDigits":"0000", "cardExpiry":{"month":9, "year":2025}, "issuingCountry":"US"},"profile":{"firstName":"Longbob", "lastName":"Longsen", "email":"[email protected]"},"billingDetails":{"street":"456 My Street","street2":"Apt 1","city":"Ottawa","state":"ON","country":"CA","zip":"K1C2N6","phone":"(555)555-5555"},"currencyCode":"USD","merchantDescriptor":{"dynamicDescriptor":"Store Purchase"},"links":[{"rel":"self","href":"https://api.test.paysafe.com/cardpayments/v1/accounts/1002179730/standalonecredits/b40c327e-92d7-4026-a043-be1f1b03c08a"}]}'
455473
end
474+
475+
def purchase_response_with_completed_settlements
476+
'{"id":"cddbd29d-4983-4719-983a-c6a862895781","merchantRefNum":"c9b2ad852a1a37c1cc5c39b741be7484","txnTime":"2021-08-10T18:25:40Z","status":"COMPLETED","amount":100,"settleWithAuth":true,"preAuth":false,"availableToSettle":0,"card":{"type":"VI","lastDigits":"3670","cardExpiry":{"month":9,"year":2022}},"authCode":"544454","profile":{"firstName":"Longbob","lastName":"Longsen"},"billingDetails":{"street":"999 This Way Lane","city":"Hereville","state":"NC","country":"FR","zip":"98989","phone":"999-9999999"},"merchantDescriptor":{"dynamicDescriptor":"Store Purchase","phone":"999-8887777"},"visaAdditionalAuthData":{},"currencyCode":"EUR","avsResponse":"MATCH","cvvVerification":"MATCH","settlements":[{"id":"cddbd29d-4983-4719-983a-c6a862895781","merchantRefNum":"c9b2ad852a1a37c1cc5c39b741be7484","txnTime":"2021-08-10T18:25:40Z","status":"COMPLETED","amount":100,"availableToRefund":100,"links":[{"rel":"self","href":"https://api.test.paysafe.com/cardpayments/v1/accounts/1002158490/settlements/cddbd29d-4983-4719-983a-c6a862895781"}]}],"links":[{"rel":"settlement","href":"https://api.test.paysafe.com/cardpayments/v1/accounts/1002158490/settlements/cddbd29d-4983-4719-983a-c6a862895781"},{"rel":"self","href":"https://api.test.paysafe.com/cardpayments/v1/accounts/1002158490/auths/cddbd29d-4983-4719-983a-c6a862895781"}]}'
477+
end
456478
end

0 commit comments

Comments
 (0)