({ communityId }: { communityId: string })
| 32 | } |
| 33 | |
| 34 | export async function index({ communityId }: { communityId: string }) { |
| 35 | const response1 = await stripe.customers.search({ |
| 36 | query: `metadata["communityId"]:"${communityId}"`, |
| 37 | }); |
| 38 | const customer = response1.data[0]; |
| 39 | const response2 = await stripe.subscriptions.list({ |
| 40 | customer: customer.id, |
| 41 | }); |
| 42 | const subscription = response2.data[0]; |
| 43 | const paymentMethodId = subscription.default_payment_method as string; |
| 44 | const paymentMethod = await stripe.paymentMethods.retrieve(paymentMethodId); |
| 45 | return { |
| 46 | status: 200, |
| 47 | data: { |
| 48 | customer: serializeCustomer(customer), |
| 49 | subscription: serializeSubscription(subscription), |
| 50 | paymentMethod: serializePaymentMethod(paymentMethod), |
| 51 | }, |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | export default async function handler( |
| 56 | request: NextApiRequest, |
no test coverage detected