Skip to content

Commit 9eee1af

Browse files
badjerclaude
andcommitted
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 <noreply@anthropic.com>
1 parent c503456 commit 9eee1af

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

packages/atxp-server/src/paymentServer.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ describe('ATXPPaymentServer', () => {
102102
expect(parsedBody.options).toBeDefined();
103103
});
104104

105+
it('should handle charge endpoint returning 202 status (async payment accepted)', async () => {
106+
const mock = fetchMock.createInstance();
107+
mock.post('https://auth.atxp.ai/charge', {
108+
status: 202,
109+
body: {
110+
success: true,
111+
pending: true,
112+
paymentRequestId: 'async-payment-123'
113+
}
114+
});
115+
116+
const oAuthDb = await createOAuthDbWithCredentials('https://auth.atxp.ai', 'test-client-id', 'test-client-secret');
117+
const server = new ATXPPaymentServer('https://auth.atxp.ai', TH.logger(), mock.fetchHandler, oAuthDb);
118+
119+
const result = await server.charge(TH.charge({
120+
sourceAccountId: 'solana:test-source',
121+
destinationAccountId: 'solana:test-destination'
122+
}));
123+
124+
// Verify the result indicates payment accepted (returns true)
125+
expect(result).toBe(true);
126+
});
127+
105128
it('should handle charge endpoint returning 402 status (payment required)', async () => {
106129
const mock = fetchMock.createInstance();
107130
mock.post('https://auth.atxp.ai/charge', {

packages/atxp-server/src/paymentServer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export class ATXPPaymentServer implements PaymentServer {
4242

4343
charge = async(chargeRequest: Charge): Promise<boolean> => {
4444
const chargeResponse = await this.makeRequest('POST', '/charge', chargeRequest);
45-
if (chargeResponse.status === 200) {
45+
// 200 = synchronous success, 202 = accepted (async payment in progress)
46+
if (chargeResponse.status === 200 || chargeResponse.status === 202) {
4647
return true;
4748
} else if (chargeResponse.status === 402) {
4849
return false;

0 commit comments

Comments
 (0)