Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ To deploy the sync-engine to a Supabase Edge Function, follow this [guide](./doc
- [x] `checkout.session.async_payment_succeeded` 🟢
- [x] `checkout.session.completed` 🟢
- [x] `checkout.session.expired` 🟢
- [x] `coupon.created` 🟢
- [x] `coupon.deleted` 🟢
- [x] `coupon.updated` 🟢
- [x] `credit_note.created` 🟢
- [x] `credit_note.updated` 🟢
- [x] `credit_note.voided` 🟢
Expand Down Expand Up @@ -128,6 +131,8 @@ To deploy the sync-engine to a Supabase Edge Function, follow this [guide](./doc
- [x] `price.created` 🟢
- [x] `price.deleted` 🟢
- [x] `price.updated` 🟢
- [x] `promotion_code.created` 🟢
- [x] `promotion_code.updated` 🟢
- [x] `product.created` 🟢
- [x] `product.deleted` 🟢
- [x] `product.updated` 🟢
Expand Down
45 changes: 45 additions & 0 deletions packages/fastify-app/src/test/helpers/mockStripe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import { vitest } from 'vitest'

export const mockStripe = {
coupons: {
retrieve: vitest.fn((id) =>
Promise.resolve({
id,
object: 'coupon',
amount_off: null,
created: 1773056115,
currency: null,
duration: 'once',
duration_in_months: null,
livemode: false,
max_redemptions: null,
metadata: {},
name: 'TEST_DISCOUNT',
percent_off: 100,
redeem_by: null,
times_redeemed: 0,
valid: true,
})
),
},
checkout: {
sessions: {
retrieve: vitest.fn((id) =>
Expand Down Expand Up @@ -95,6 +116,30 @@ export const mockStripe = {
})),
},
},
promotionCodes: {
retrieve: vitest.fn((id) =>
Promise.resolve({
id,
object: 'promotion_code',
active: true,
code: 'FREE2026',
coupon: '82cOWD3z',
created: 1773056115,
customer: null,
customer_account: null,
expires_at: null,
livemode: false,
max_redemptions: null,
metadata: {},
restrictions: {
first_time_transaction: true,
minimum_amount: null,
minimum_amount_currency: null,
},
times_redeemed: 0,
})
),
},
invoices: {
retrieve: vitest.fn((id) =>
Promise.resolve({
Expand Down
32 changes: 32 additions & 0 deletions packages/fastify-app/src/test/stripe/coupon_created.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"id": "evt_1T925fEduqPk9bEEIR3ResAc",
"object": "event",
"api_version": "2023-10-16",
"created": 1773056115,
"data": {
"object": {
"id": "82cOWD3z",
"object": "coupon",
"amount_off": null,
"created": 1773056115,
"currency": null,
"duration": "once",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {},
"name": "TEST_DISCOUNT",
"percent_off": 100,
"redeem_by": null,
"times_redeemed": 0,
"valid": true
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": "req_hMl8XMocNsAed3",
"idempotency_key": "eb42ae66-a11a-47a3-acdd-3ff904f249a5"
},
"type": "coupon.created"
}
51 changes: 51 additions & 0 deletions packages/fastify-app/src/test/stripe/promotion_code_created.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"id": "evt_1T925fEduqPk9bEEIR3ResAb",
"object": "event",
"api_version": "2023-10-16",
"created": 1773056115,
"data": {
"object": {
"id": "promo_1T925fEduqPk9bEE4b5egICF",
"object": "promotion_code",
"active": true,
"code": "FREE2026",
"coupon": {
"id": "82cOWD3z",
"object": "coupon",
"amount_off": null,
"created": 1773056115,
"currency": null,
"duration": "once",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {},
"name": "TEST_DISCOUNT",
"percent_off": 100,
"redeem_by": null,
"times_redeemed": 0,
"valid": true
},
"created": 1773056115,
"customer": null,
"customer_account": null,
"expires_at": null,
"livemode": false,
"max_redemptions": null,
"metadata": {},
"restrictions": {
"first_time_transaction": true,
"minimum_amount": null,
"minimum_amount_currency": null
},
"times_redeemed": 0
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": "req_hMl8XMocNsAed2",
"idempotency_key": "eb42ae66-a11a-47a3-acdd-3ff904f249a4"
},
"type": "promotion_code.created"
}
2 changes: 2 additions & 0 deletions packages/fastify-app/src/test/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('POST /webhooks', () => {
'customer_deleted.json',
'customer_tax_id_created.json',
'customer_tax_id_updated.json',
'coupon_created.json',
Comment thread
Nika0000 marked this conversation as resolved.
'product_created.json',
'product_updated.json',
'price_created.json',
Expand Down Expand Up @@ -126,6 +127,7 @@ describe('POST /webhooks', () => {
'refund_updated.json',
'checkout_session_completed.json',
'invoice_payment_paid.json',
'promotion_code_created.json',
Comment thread
Nika0000 marked this conversation as resolved.
])('event %s is upserted', async (jsonFile) => {
const eventBody = await import(`./stripe/${jsonFile}`).then(({ default: myData }) => myData)
// Update the event body created timestamp to be the current time
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
create table
if not exists "stripe"."promotion_codes" (
"id" text primary key,
"object" text,
"active" boolean,
"code" text,
"coupon" text,
"created" integer,
"customer" text,
"customer_account" text,
"expires_at" integer,
"livemode" boolean,
"max_redemptions" bigint,
"metadata" jsonb,
"restrictions" jsonb,
"times_redeemed" bigint,
"updated_at" timestamptz default timezone('utc'::text, now()) not null,
"last_synced_at" timestamptz
);

create index stripe_promotion_codes_coupon_idx on "stripe"."promotion_codes" using btree (coupon);
create index stripe_promotion_codes_customer_idx on "stripe"."promotion_codes" using btree (customer);

create trigger handle_updated_at
before update
on stripe.promotion_codes
for each row
execute procedure set_updated_at();
22 changes: 22 additions & 0 deletions packages/sync-engine/src/schemas/coupon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { EntitySchema } from './types'

export const couponSchema: EntitySchema = {
properties: [
'id',
'object',
'name',
'valid',
'created',
'currency',
'duration',
'livemode',
'metadata',
'redeem_by',
'amount_off',
'percent_off',
'times_redeemed',
'max_redemptions',
'duration_in_months',
'percent_off_precise',
],
} as const
20 changes: 20 additions & 0 deletions packages/sync-engine/src/schemas/promotion_code.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { EntitySchema } from './types'

export const promotionCodeSchema: EntitySchema = {
properties: [
'id',
'object',
'active',
'code',
'coupon',
'created',
'customer',
'customer_account',
'expires_at',
'livemode',
'max_redemptions',
'metadata',
'restrictions',
'times_redeemed',
],
} as const
Loading
Loading