list payments
This commit is contained in:
@ -12,12 +12,55 @@ const client = got.extend({
|
||||
|
||||
async function request<T>(path: string, data: any) {
|
||||
return client.post<T>(path, {
|
||||
...data,
|
||||
vendor_id,
|
||||
vendor_auth_code,
|
||||
json: {
|
||||
...data,
|
||||
vendor_id,
|
||||
vendor_auth_code,
|
||||
},
|
||||
responseType: "json",
|
||||
});
|
||||
}
|
||||
|
||||
type GetPaymentsParams = {
|
||||
subscriptionId: string;
|
||||
};
|
||||
|
||||
export async function getPayments({ subscriptionId }: GetPaymentsParams) {
|
||||
type Payment = {
|
||||
id: number;
|
||||
subscription_id: number;
|
||||
amount: number;
|
||||
currency: string;
|
||||
payout_date: string;
|
||||
is_paid: number;
|
||||
is_one_off_charge: boolean;
|
||||
receipt_url?: string;
|
||||
};
|
||||
|
||||
type PaymentsSuccessResponse = {
|
||||
success: true;
|
||||
response: Payment[];
|
||||
};
|
||||
|
||||
type PaymentsErrorResponse = {
|
||||
success: false;
|
||||
error: {
|
||||
code: number;
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
|
||||
type PaymentsResponse = PaymentsSuccessResponse | PaymentsErrorResponse;
|
||||
|
||||
const { body } = await request<PaymentsResponse>("subscription/payments", { subscription_id: subscriptionId });
|
||||
console.log("body", typeof body);
|
||||
if (!body.success) {
|
||||
throw new Error(body.error.message);
|
||||
}
|
||||
|
||||
return body.response;
|
||||
}
|
||||
|
||||
type UpdateSubscriptionPlanParams = {
|
||||
subscriptionId: string;
|
||||
planId: string;
|
||||
@ -25,7 +68,7 @@ type UpdateSubscriptionPlanParams = {
|
||||
};
|
||||
|
||||
export async function updateSubscriptionPlan({ subscriptionId, planId, prorate = true }: UpdateSubscriptionPlanParams) {
|
||||
const { body } = await request("/subscription/users/update", {
|
||||
const { body } = await request("subscription/users/update", {
|
||||
subscription_id: subscriptionId,
|
||||
plan_id: planId,
|
||||
prorate,
|
||||
@ -35,7 +78,7 @@ export async function updateSubscriptionPlan({ subscriptionId, planId, prorate =
|
||||
}
|
||||
|
||||
export async function cancelPaddleSubscription({ subscriptionId }: { subscriptionId: string }) {
|
||||
const { body } = await request("/subscription/users_cancel", { subscription_id: subscriptionId });
|
||||
const { body } = await request("subscription/users_cancel", { subscription_id: subscriptionId });
|
||||
|
||||
return body;
|
||||
}
|
||||
|
Reference in New Issue
Block a user