w-aura/src/api/resources/Payment.ts
2024-06-03 16:59:41 +00:00

51 lines
1.2 KiB
TypeScript

import routes from "@/routes";
import { getAuthHeaders } from "../utils";
interface Payload {
token: string;
}
export interface PayloadPost extends Payload {
productId: string;
placementId: string;
paywallId: string;
}
interface ResponsePostSuccess {
status: "payment_intent_created" | "paid" | unknown,
type: "setup" | "payment",
data: {
client_secret: string,
paymentIntentId: string,
return_url?: string,
public_key: string,
product: {
id: string,
name: string,
description?: string,
price: {
id: string,
unit_amount: number,
currency: "USD" | string
}
}
}
}
interface ResponsePostError {
status: string;
message: string;
}
export type ResponsePost = ResponsePostSuccess | ResponsePostError;
export const createRequestPost = ({ token, productId, placementId, paywallId }: PayloadPost): Request => {
const url = new URL(routes.server.makePayment());
const body = JSON.stringify({
productId,
placementId,
paywallId
});
return new Request(url, { method: "POST", headers: getAuthHeaders(token), body });
};