From a2cdc05d4e4f19f9570453996085831b116c4282 Mon Sep 17 00:00:00 2001 From: bdj Date: Wed, 14 Jan 2026 10:35:43 -0800 Subject: [PATCH] feat: Handle 202 Accepted from /charge endpoint The auth service now returns HTTP 202 for async payments that are accepted but still processing. This change treats 202 the same as 200 (success). - 200 = synchronous payment completed - 202 = async payment accepted (balance checked, executing in background) Co-Authored-By: Claude Opus 4.5 --- .../atxp-server/src/paymentServer.test.ts | 23 +++++++++++++++++++ packages/atxp-server/src/paymentServer.ts | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/atxp-server/src/paymentServer.test.ts b/packages/atxp-server/src/paymentServer.test.ts index cecea49..f52e8f6 100644 --- a/packages/atxp-server/src/paymentServer.test.ts +++ b/packages/atxp-server/src/paymentServer.test.ts @@ -102,6 +102,29 @@ describe('ATXPPaymentServer', () => { expect(parsedBody.options).toBeDefined(); }); + it('should handle charge endpoint returning 202 status (async payment accepted)', async () => { + const mock = fetchMock.createInstance(); + mock.post('https://auth.atxp.ai/charge', { + status: 202, + body: { + success: true, + pending: true, + paymentRequestId: 'async-payment-123' + } + }); + + const oAuthDb = await createOAuthDbWithCredentials('https://auth.atxp.ai', 'test-client-id', 'test-client-secret'); + const server = new ATXPPaymentServer('https://auth.atxp.ai', TH.logger(), mock.fetchHandler, oAuthDb); + + const result = await server.charge(TH.charge({ + sourceAccountId: 'solana:test-source', + destinationAccountId: 'solana:test-destination' + })); + + // Verify the result indicates payment accepted (returns true) + expect(result).toBe(true); + }); + it('should handle charge endpoint returning 402 status (payment required)', async () => { const mock = fetchMock.createInstance(); mock.post('https://auth.atxp.ai/charge', { diff --git a/packages/atxp-server/src/paymentServer.ts b/packages/atxp-server/src/paymentServer.ts index 7c41dd7..d28459b 100644 --- a/packages/atxp-server/src/paymentServer.ts +++ b/packages/atxp-server/src/paymentServer.ts @@ -42,7 +42,8 @@ export class ATXPPaymentServer implements PaymentServer { charge = async(chargeRequest: Charge): Promise => { const chargeResponse = await this.makeRequest('POST', '/charge', chargeRequest); - if (chargeResponse.status === 200) { + // 200 = synchronous success, 202 = accepted (async payment in progress) + if (chargeResponse.status === 200 || chargeResponse.status === 202) { return true; } else if (chargeResponse.status === 402) { return false;