Skip to content

Commit

Permalink
Merge pull request #53 from alitnk/fix/zarinpal-required-description
Browse files Browse the repository at this point in the history
fix: make `description` field required in zarinpal
  • Loading branch information
Keivan-sf authored Jul 31, 2023
2 parents 210474a + 8138e81 commit 47531c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/drivers/zarinpal/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface RequestPaymentReq {
/**
* توضیحات مربوط به تراکنش
*/
description?: string;
description: string;

/**
* صفحه بازگشت مشتري، پس از انجام عمل پرداخت
Expand Down Expand Up @@ -157,7 +157,11 @@ export const tConfig = t.intersection([

export type Config = t.TypeOf<typeof tConfig>;

export const tRequestOptions = t.intersection([t.partial({ mobile: t.string, email: t.string }), tBaseRequestOptions]);
export const tRequestOptions = t.intersection([
t.partial({ mobile: t.string, email: t.string }),
t.type({ description: t.string }),
tBaseRequestOptions,
]);

export type RequestOptions = t.TypeOf<typeof tRequestOptions>;

Expand Down
10 changes: 6 additions & 4 deletions test/drivers/zarinpal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ describe('Zarinpal Driver', () => {

const driver = getPaymentDriver<Zarinpal>('zarinpal', { merchantId: '2134' });

expect(typeof (await driver.requestPayment({ amount: 2000, callbackUrl: 'asd' })).url).toBe('string');
expect(typeof (await driver.requestPayment({ amount: 2000, callbackUrl: 'asd', description: 'test' })).url).toBe(
'string',
);
});

it('throws payment errors accordingly', async () => {
Expand All @@ -31,9 +33,9 @@ describe('Zarinpal Driver', () => {

const driver = getPaymentDriver<Zarinpal>('zarinpal', { merchantId: '2134' });

await expect(async () => await driver.requestPayment({ amount: 2000, callbackUrl: 'asd' })).rejects.toThrow(
RequestException,
);
await expect(
async () => await driver.requestPayment({ amount: 2000, callbackUrl: 'asd', description: 'test' }),
).rejects.toThrow(RequestException);
});

it('verifies the purchase correctly', async () => {
Expand Down

0 comments on commit 47531c4

Please sign in to comment.