Skip to content

Commit

Permalink
fix: Subscription returning bad request
Browse files Browse the repository at this point in the history
  • Loading branch information
sashko9807 committed Dec 9, 2024
1 parent d34dd63 commit 036bee5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/api/src/stripe/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,17 @@ export class StripeService {
if (!campaign) throw new Error(`Campaign with id ${campaignId} not found`)

const productLookup = await this.stripeClient.products.search({
query: `-name:'${campaign.title}'`,
query: `metadata["campaignId"]:"${campaign.id}"`,
})

if (productLookup) return productLookup.data[0]
if (productLookup.data.length) return productLookup.data[0]
return await this.stripeClient.products.create(
{
name: campaign.title,
description: `Donate to ${campaign.title}`,
metadata: {
campaignId: campaign.id,
},
},
{ idempotencyKey: `${idempotencyKey}--product` },
)
Expand Down

0 comments on commit 036bee5

Please sign in to comment.