diff options
Diffstat (limited to 'cloud/core/src')
| -rw-r--r-- | cloud/core/src/billing.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/cloud/core/src/billing.ts b/cloud/core/src/billing.ts index cbf064bfe..2254adc79 100644 --- a/cloud/core/src/billing.ts +++ b/cloud/core/src/billing.ts @@ -224,4 +224,21 @@ export namespace Billing { return session.url }, ) + + export const generateReceiptUrl = fn( + z.object({ + paymentID: z.string(), + }), + async (input) => { + const { paymentID } = input + + const intent = await Billing.stripe().paymentIntents.retrieve(paymentID) + if (!intent.latest_charge) throw new Error("No charge found") + + const charge = await Billing.stripe().charges.retrieve(intent.latest_charge as string) + if (!charge.receipt_url) throw new Error("No receipt URL found") + + return charge.receipt_url + }, + ) } |
