Skip to content

Commit

Permalink
feat(api): add Simulate Return Payment endpoint (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Sep 12, 2023
1 parent 2b45234 commit e3b95c6
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 87
configured_endpoints: 88
2 changes: 2 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,15 @@ Types:
- <code><a href="./src/resources/payments.ts">Payment</a></code>
- <code><a href="./src/resources/payments.ts">PaymentCreateResponse</a></code>
- <code><a href="./src/resources/payments.ts">PaymentSimulateReleaseResponse</a></code>
- <code><a href="./src/resources/payments.ts">PaymentSimulateReturnResponse</a></code>

Methods:

- <code title="post /payments">client.payments.<a href="./src/resources/payments.ts">create</a>({ ...params }) -> PaymentCreateResponse</code>
- <code title="get /payments/{payment_token}">client.payments.<a href="./src/resources/payments.ts">retrieve</a>(paymentToken) -> Payment</code>
- <code title="get /payments">client.payments.<a href="./src/resources/payments.ts">list</a>({ ...params }) -> PaymentsCursorPage</code>
- <code title="post /simulate/payments/release">client.payments.<a href="./src/resources/payments.ts">simulateRelease</a>({ ...params }) -> PaymentSimulateReleaseResponse</code>
- <code title="post /simulate/payments/return">client.payments.<a href="./src/resources/payments.ts">simulateReturn</a>({ ...params }) -> PaymentSimulateReturnResponse</code>

# ThreeDS

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,12 @@ export namespace Lithic {
export import Payment = API.Payment;
export import PaymentCreateResponse = API.PaymentCreateResponse;
export import PaymentSimulateReleaseResponse = API.PaymentSimulateReleaseResponse;
export import PaymentSimulateReturnResponse = API.PaymentSimulateReturnResponse;
export import PaymentsCursorPage = API.PaymentsCursorPage;
export import PaymentCreateParams = API.PaymentCreateParams;
export import PaymentListParams = API.PaymentListParams;
export import PaymentSimulateReleaseParams = API.PaymentSimulateReleaseParams;
export import PaymentSimulateReturnParams = API.PaymentSimulateReturnParams;

export import ThreeDS = API.ThreeDS;

Expand Down
2 changes: 2 additions & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ export {
Payment,
PaymentCreateResponse,
PaymentSimulateReleaseResponse,
PaymentSimulateReturnResponse,
PaymentCreateParams,
PaymentListParams,
PaymentSimulateReleaseParams,
PaymentSimulateReturnParams,
PaymentsCursorPage,
Payments,
} from './payments';
Expand Down
26 changes: 26 additions & 0 deletions src/resources/payments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ export class Payments extends APIResource {
): Core.APIPromise<PaymentSimulateReleaseResponse> {
return this.post('/simulate/payments/release', { body, ...options });
}

/**
* Simulates a return of a Payment.
*/
simulateReturn(
body: PaymentSimulateReturnParams,
options?: Core.RequestOptions,
): Core.APIPromise<PaymentSimulateReturnResponse> {
return this.post('/simulate/payments/return', { body, ...options });
}
}

export class PaymentsCursorPage extends CursorPage<Payment> {}
Expand Down Expand Up @@ -91,6 +101,14 @@ export interface PaymentSimulateReleaseResponse {
transaction_event_token?: string;
}

export interface PaymentSimulateReturnResponse {
debugging_request_id?: string;

result?: 'APPROVED' | 'DECLINED';

transaction_event_token?: string;
}

export interface PaymentCreateParams {
amount: number;

Expand Down Expand Up @@ -129,12 +147,20 @@ export interface PaymentSimulateReleaseParams {
payment_token: string;
}

export interface PaymentSimulateReturnParams {
payment_token: string;

return_reason_code?: string;
}

export namespace Payments {
export import Payment = API.Payment;
export import PaymentCreateResponse = API.PaymentCreateResponse;
export import PaymentSimulateReleaseResponse = API.PaymentSimulateReleaseResponse;
export import PaymentSimulateReturnResponse = API.PaymentSimulateReturnResponse;
export type PaymentsCursorPage = _PaymentsCursorPage;
export import PaymentCreateParams = API.PaymentCreateParams;
export import PaymentListParams = API.PaymentListParams;
export import PaymentSimulateReleaseParams = API.PaymentSimulateReleaseParams;
export import PaymentSimulateReturnParams = API.PaymentSimulateReturnParams;
}
20 changes: 20 additions & 0 deletions tests/api-resources/payments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,24 @@ describe('resource payments', () => {
payment_token: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
});
});

test('simulateReturn: only required params', async () => {
const responsePromise = lithic.payments.simulateReturn({
payment_token: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
});
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('simulateReturn: required and optional params', async () => {
const response = await lithic.payments.simulateReturn({
payment_token: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
return_reason_code: 'string',
});
});
});

0 comments on commit e3b95c6

Please sign in to comment.