Skip to content

Commit

Permalink
fix(wabe): fix coupon name, no allow_promotion when couponId (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
coratgerl authored Jan 2, 2025
1 parent 14c158c commit 818eb39
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/wabe-stripe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wabe-stripe",
"version": "0.5.12",
"version": "0.5.13",
"description": "Stripe payment adapter for Wabe",
"homepage": "https://wabe.dev",
"author": {
Expand Down
69 changes: 69 additions & 0 deletions packages/wabe-stripe/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,75 @@ describe('wabe-stripe', () => {
})
})

it('should not provide allo_promotion_codes and discounts in the same request', async () => {
const adapter = new StripeAdapter('API_KEY')

mockListCustomers.mockResolvedValue({
data: [
{
id: 'cus_123',
email: 'test@wabe.dev',
},
],
} as never)

mockCreatePayment.mockResolvedValue({
url: 'https://test.com',
} as never)

await adapter.createPayment({
customerEmail: 'lucas.coratger@gmail.com',
currency: Currency.EUR,
paymentMethod: ['card'],
products: [
{
name: 'Product 1',
unitAmount: 1000,
quantity: 1,
},
],
paymentMode: PaymentMode.subscription,
successUrl: 'https://wabe.dev',
cancelUrl: 'https://wabe.dev',
promotionCodeId: 'PROMO_123',
})

expect(mockCreatePayment).toHaveBeenCalledTimes(1)
expect(mockCreatePayment).toHaveBeenCalledWith({
customer: 'cus_123',
line_items: [
{
price_data: {
currency: 'eur',
product_data: {
name: 'Product 1',
},
unit_amount: 1000,
recurring: {
interval: 'month',
},
},
quantity: 1,
},
],
payment_method_types: ['card'],
mode: 'subscription',
success_url: 'https://wabe.dev',
cancel_url: 'https://wabe.dev',
automatic_tax: {
enabled: false,
},
invoice_creation: {
enabled: true,
},
discounts: [
{
promotion_code: 'PROMO_123',
},
],
})
})

it('should throw an error if the session url is not returned by Stripewhen creating a payment', () => {
const adapter = new StripeAdapter('API_KEY')

Expand Down
16 changes: 14 additions & 2 deletions packages/wabe-stripe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class StripeAdapter implements PaymentAdapter {
createInvoice = true,
allowPromotionCode = true,
promotionCodeId,
couponCodeId,
}: CreatePaymentOptions) {
const customersWithSameEmail = await this.stripe.customers.list({
email: customerEmail,
Expand Down Expand Up @@ -239,7 +240,9 @@ export class StripeAdapter implements PaymentAdapter {
invoice_creation: {
enabled: createInvoice,
},
allow_promotion_codes: allowPromotionCode,
...(!promotionCodeId && !couponCodeId
? { allow_promotion_codes: allowPromotionCode }
: {}),
...(automaticTax
? {
billing_address_collection: 'required',
Expand All @@ -252,7 +255,16 @@ export class StripeAdapter implements PaymentAdapter {
? {
discounts: [
{
coupon: promotionCodeId,
promotion_code: promotionCodeId,
},
],
}
: {}),
...(couponCodeId
? {
discounts: [
{
coupon: couponCodeId,
},
],
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wabe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wabe",
"version": "0.5.16",
"version": "0.5.17",
"description": "Your backend in minutes not days",
"homepage": "https://wabe.dev",
"author": {
Expand Down
1 change: 1 addition & 0 deletions packages/wabe/src/payment/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export type CreatePaymentOptions = {
createInvoice?: boolean
allowPromotionCode?: boolean
promotionCodeId?: string
couponCodeId?: string
}

export type InitWebhookOptions = {
Expand Down

0 comments on commit 818eb39

Please sign in to comment.