Skip to content

Commit

Permalink
fix(wabe-stripe): return code when create stripe coupon (#117)
Browse files Browse the repository at this point in the history
* fix(wabe-stripe): return code when create stripe coupon

* feat: improve documentation
  • Loading branch information
coratgerl authored Dec 26, 2024
1 parent 61dd791 commit f2f0299
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions packages/wabe-documentation/docs/payment/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ You can create a coupon using the `createCoupon` method.

```ts
const fn = async (context: WabeContext<any>) => {
const couponId = await context.wabe.controllers.payment.createCoupon({
const {code, id: stripeId} = await context.wabe.controllers.payment.createCoupon({
duration: 'repeating',
durationInMonths: 3,
name: 'MYCOUPON',
Expand All @@ -61,7 +61,7 @@ Or with fixed amount:

```ts
const fn = async (context: WabeContext<any>) => {
const couponId = await context.wabe.controllers.payment.createCoupon({
const {code, id: stripeId} = await context.wabe.controllers.payment.createCoupon({
duration: 'forever',
currency: Currency.EUR,
amountOff: 100,
Expand All @@ -76,7 +76,7 @@ You can create a promotion code from a coupon using the `createPromotionCode` me

```ts
const fn = async (context: WabeContext<any>) => {
const promotionCode = await context.wabe.controllers.payment.createPromotionCode({
const {code, id: stripeId} = await context.wabe.controllers.payment.createPromotionCode({
couponId: 'coupon_123',
code: 'MYCODE',
})
Expand Down
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.9",
"version": "0.5.10",
"description": "Stripe payment adapter for Wabe",
"homepage": "https://wabe.dev",
"author": {
Expand Down
5 changes: 3 additions & 2 deletions packages/wabe-stripe/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('wabe-stripe', () => {
percent_off: undefined,
} as never)

const couponId = await adapter.createCoupon({
const { id, code } = await adapter.createCoupon({
amountOff: 1000,
currency: Currency.EUR,
duration: 'forever',
Expand All @@ -161,7 +161,8 @@ describe('wabe-stripe', () => {
percent_off: undefined,
})

expect(couponId).toEqual('coupon_123')
expect(id).toEqual('coupon_123')
expect(code).toEqual('Coupon 1')
})

it('should create a promotion code', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/wabe-stripe/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class StripeAdapter implements PaymentAdapter {

if (!coupon.id) throw new Error('Error creating Stripe coupon')

return coupon.id
return { id: coupon.id, code: coupon.name || '' }
}

async createPromotionCode({
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.12",
"version": "0.5.13",
"description": "Your backend in minutes not days",
"homepage": "https://wabe.dev",
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/wabe/src/payment/DevAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class PaymentDevAdapter implements PaymentAdapter {

// biome-ignore lint/suspicious/useAwait: false
async createCoupon() {
return ''
return { code: '', id: '' }
}

// biome-ignore lint/suspicious/useAwait: false
Expand Down
4 changes: 3 additions & 1 deletion packages/wabe/src/payment/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ export interface PaymentAdapter {
* @param options CreateCouponOptions
* @returns id The coupon id
*/
createCoupon: (options: CreateCouponOptions) => Promise<string>
createCoupon: (
options: CreateCouponOptions,
) => Promise<{ code: string; id: string }>
/**
* Disable a promotion code
* @param options DeletePromotionCodeOptions
Expand Down

0 comments on commit f2f0299

Please sign in to comment.