Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/atxp-server/src/paymentServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
3 changes: 2 additions & 1 deletion packages/atxp-server/src/paymentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export class ATXPPaymentServer implements PaymentServer {

charge = async(chargeRequest: Charge): Promise<boolean> => {
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;
Expand Down