(communityId: string, email: string)
| 67 | } |
| 68 | |
| 69 | async function findOrCreateCustomer(communityId: string, email: string) { |
| 70 | const { data } = await stripe.customers.search({ |
| 71 | query: `metadata["communityId"]:"${communityId}"`, |
| 72 | }); |
| 73 | |
| 74 | return ( |
| 75 | data[0] || |
| 76 | (await stripe.customers.create({ |
| 77 | name: `CUSTOMER ${communityId}`, |
| 78 | email, |
| 79 | metadata: { |
| 80 | email, |
| 81 | communityId, |
| 82 | }, |
| 83 | })) |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | export async function create({ |
| 88 | email, |