Skip to content

Commit

Permalink
chore: PR feedback + run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
GusRuss89 committed Apr 24, 2023
1 parent 3562674 commit a99cac4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/subscriptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ describe('subscription methods', () => {
test('resolves on successful request using options', async () => {
const expectedBodyOptions = {
...expectedBody,
subscription_id: SUBSCRIPTION_ID
}
subscription_id: SUBSCRIPTION_ID,
};
const body = {
success: true,
response: [
Expand Down
47 changes: 28 additions & 19 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,24 @@ s * @example
* Legacy usage for backwards compatibility: pass planID as a number instead of options object
* const payments = await client.getSubscriptionPayments(123);
*/
getSubscriptionPayments(options?: number | {
planID?: number;
subscriptionID?: number;
isPaid?: boolean;
from?: Date;
to?: Date;
isOneOffCharge?: boolean;
}) {
const opts = (typeof options === 'number') ? { planID: options } : options;
getSubscriptionPayments(
options?:
| number
| {
planID?: number;
subscriptionID?: number;
isPaid?: boolean;
from?: Date;
to?: Date;
isOneOffCharge?: boolean;
}

Check failure on line 152 in src/sdk.ts

View workflow job for this annotation

GitHub Actions / Node.js 14

Mixed spaces and tabs

Check failure on line 152 in src/sdk.ts

View workflow job for this annotation

GitHub Actions / Node.js 16

Mixed spaces and tabs

Check failure on line 152 in src/sdk.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Mixed spaces and tabs
) {
if (typeof options === 'number') {
console.warn(
'Passing planID as a number is deprecated, please use an options object instead'
);
}
const opts = typeof options === 'number' ? { planID: options } : options;
const {
planID = null,
subscriptionID = null,
Expand All @@ -157,20 +166,20 @@ s * @example
isOneOffCharge = null,
} = opts || {};

const body = {
...(planID && { plan: planID }),
...(subscriptionID && { subscription_id: subscriptionID }),
...(typeof isPaid === 'boolean' && { is_paid: Number(isPaid) }),
...(from && { from: from.toISOString().substring(0, 10) }),
...(to && { to: to.toISOString().substring(0, 10) }),
...(typeof isOneOffCharge === 'boolean' && { is_one_off_charge: Number(isOneOffCharge) }),
};

return this._request<
GetSubscriptionPaymentsResponse,
GetSubscriptionPaymentsBody
>('/subscription/payments', {
body,
body: {
...(planID && { plan: planID }),
...(subscriptionID && { subscription_id: subscriptionID }),
...(typeof isPaid === 'boolean' && { is_paid: Number(isPaid) }),
...(from && { from: from.toISOString().substring(0, 10) }),
...(to && { to: to.toISOString().substring(0, 10) }),
...(typeof isOneOffCharge === 'boolean' && {
is_one_off_charge: Number(isOneOffCharge),
}),
},
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,20 @@ export interface SubscriptionUser {
};
quantity: number;
next_payment: Payment;
paused_at?: string
paused_from?: string
paused_reason?: string
paused_at?: string;
paused_from?: string;
paused_reason?: string;
}

export type GetSubscriptionUsersResponse = Array<SubscriptionUser>;

export interface GetSubscriptionPaymentsBody {
plan?: number;
subscription_id?: number
is_paid?: number
from?: string
to?: string
isOneOffCharge?: number
subscription_id?: number;
is_paid?: number;
from?: string;
to?: string;
isOneOffCharge?: number;
}

export interface SubscriptionPayment {
Expand Down

0 comments on commit a99cac4

Please sign in to comment.