Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -35,26 +35,6 @@ export default createBillingSchema({
|
|||||||
cost: 9.99,
|
cost: 9.99,
|
||||||
type: 'flat' as const,
|
type: 'flat' as const,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: 'price_1P8N0zI1i3VnbZTqtUPc1Zvr',
|
|
||||||
name: 'Addon 3',
|
|
||||||
cost: 0,
|
|
||||||
type: 'per_seat' as const,
|
|
||||||
tiers: [
|
|
||||||
{
|
|
||||||
upTo: 1,
|
|
||||||
cost: 0,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
upTo: 5,
|
|
||||||
cost: 4,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
upTo: 'unlimited',
|
|
||||||
cost: 3,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -89,7 +69,7 @@ export default createBillingSchema({
|
|||||||
interval: 'month',
|
interval: 'month',
|
||||||
lineItems: [
|
lineItems: [
|
||||||
{
|
{
|
||||||
id: 'price_pro',
|
id: 'price_1PGOAVI1i3VnbZTqc69xaypm',
|
||||||
name: 'Base',
|
name: 'Base',
|
||||||
cost: 19.99,
|
cost: 19.99,
|
||||||
type: 'flat',
|
type: 'flat',
|
||||||
|
|||||||
@@ -1645,9 +1645,12 @@ on conflict (
|
|||||||
item_data
|
item_data
|
||||||
on conflict (id)
|
on conflict (id)
|
||||||
do update set
|
do update set
|
||||||
|
product_id = excluded.product_id,
|
||||||
|
variant_id = excluded.variant_id,
|
||||||
price_amount = excluded.price_amount,
|
price_amount = excluded.price_amount,
|
||||||
quantity = excluded.quantity,
|
quantity = excluded.quantity,
|
||||||
interval = excluded.interval,
|
interval = excluded.interval,
|
||||||
|
type = excluded.type,
|
||||||
interval_count = excluded.interval_count;
|
interval_count = excluded.interval_count;
|
||||||
|
|
||||||
return new_subscription;
|
return new_subscription;
|
||||||
@@ -2018,6 +2021,8 @@ on conflict (
|
|||||||
on conflict (id)
|
on conflict (id)
|
||||||
do update set
|
do update set
|
||||||
price_amount = excluded.price_amount,
|
price_amount = excluded.price_amount,
|
||||||
|
product_id = excluded.product_id,
|
||||||
|
variant_id = excluded.variant_id,
|
||||||
quantity = excluded.quantity;
|
quantity = excluded.quantity;
|
||||||
|
|
||||||
return new_order;
|
return new_order;
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ INSERT INTO public.billing_customers(account_id, provider, customer_id)
|
|||||||
VALUES (tests.get_supabase_uid('primary_owner'), 'stripe', 'cus_test');
|
VALUES (tests.get_supabase_uid('primary_owner'), 'stripe', 'cus_test');
|
||||||
|
|
||||||
-- Call the upsert_order function
|
-- Call the upsert_order function
|
||||||
SELECT public.upsert_order(tests.get_supabase_uid('primary_owner'), 'cus_test', 'order_test', 'pending', 'stripe', 100, 'usd', '[{"id":"order_item_1", "product_id": "prod_test", "variant_id": "var_test", "price_amount": 100, "quantity": 1}, {"id":"order_item_2", "product_id": "prod_test", "variant_id": "var_test_2", "price_amount": 100, "quantity": 1}]');
|
SELECT public.upsert_order(tests.get_supabase_uid('primary_owner'), 'cus_test', 'order_test', 'pending', 'stripe', 100, 'usd', '[
|
||||||
|
{"id":"order_item_1", "product_id": "prod_test", "variant_id": "var_test", "price_amount": 100, "quantity": 1},
|
||||||
|
{"id":"order_item_2", "product_id": "prod_test", "variant_id": "var_test_2", "price_amount": 100, "quantity": 10}
|
||||||
|
]');
|
||||||
|
|
||||||
-- Verify that the order was created correctly
|
-- Verify that the order was created correctly
|
||||||
SELECT is(
|
SELECT is(
|
||||||
@@ -29,7 +32,9 @@ SELECT row_eq(
|
|||||||
);
|
);
|
||||||
|
|
||||||
-- Call the upsert_order function again to update the order
|
-- Call the upsert_order function again to update the order
|
||||||
select public.upsert_order(tests.get_supabase_uid('primary_owner'), 'cus_test', 'order_test', 'succeeded', 'stripe', 100, 'usd', '[{"id":"order_item_1", "product_id": "prod_test", "variant_id": "var_test", "price_amount": 100, "quantity": 10}]');
|
select public.upsert_order(tests.get_supabase_uid('primary_owner'), 'cus_test', 'order_test', 'succeeded', 'stripe', 100, 'usd', '[
|
||||||
|
{"id":"order_item_1", "product_id": "prod_test_2", "variant_id": "var_test", "price_amount": 100, "quantity": 10}
|
||||||
|
]');
|
||||||
|
|
||||||
-- Verify that the order was updated correctly
|
-- Verify that the order was updated correctly
|
||||||
select is(
|
select is(
|
||||||
@@ -41,7 +46,7 @@ select is(
|
|||||||
select row_eq(
|
select row_eq(
|
||||||
$$ select quantity from order_items where variant_id = 'var_test' $$,
|
$$ select quantity from order_items where variant_id = 'var_test' $$,
|
||||||
row(10::int),
|
row(10::int),
|
||||||
'The subscription items should be updated'
|
'The order items should be updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
select is_empty(
|
select is_empty(
|
||||||
@@ -49,6 +54,12 @@ select is_empty(
|
|||||||
'The order item should be deleted when the order is updated'
|
'The order item should be deleted when the order is updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
select row_eq(
|
||||||
|
$$ select product_id from order_items where id = 'order_item_1' $$,
|
||||||
|
row('prod_test_2'::text),
|
||||||
|
'The order item should be deleted when the order is updated'
|
||||||
|
);
|
||||||
|
|
||||||
select tests.authenticate_as('primary_owner');
|
select tests.authenticate_as('primary_owner');
|
||||||
|
|
||||||
-- account can read their own subscription
|
-- account can read their own subscription
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ SELECT public.upsert_subscription(tests.get_supabase_uid('primary_owner'), 'cus_
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "sub_456",
|
"id": "sub_456",
|
||||||
"product_id": "prod_test_2",
|
"product_id": "prod_test_3",
|
||||||
"variant_id": "var_test_2",
|
"variant_id": "var_test_2",
|
||||||
"type": "flat",
|
"type": "flat",
|
||||||
"price_amount": 2000,
|
"price_amount": 2000,
|
||||||
@@ -97,6 +97,13 @@ SELECT row_eq(
|
|||||||
'The subscription items should be updated'
|
'The subscription items should be updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
-- Verify that the subscription items were updated correctly
|
||||||
|
SELECT row_eq(
|
||||||
|
$$ select product_id from subscription_items where id = 'sub_456' $$,
|
||||||
|
row('prod_test_3'::varchar),
|
||||||
|
'The subscription items should be updated'
|
||||||
|
);
|
||||||
|
|
||||||
-- Verify that the subscription items were updated correctly
|
-- Verify that the subscription items were updated correctly
|
||||||
SELECT row_eq(
|
SELECT row_eq(
|
||||||
$$ select interval from subscription_items where variant_id = 'var_test_2' $$,
|
$$ select interval from subscription_items where variant_id = 'var_test_2' $$,
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ SELECT row_eq(
|
|||||||
|
|
||||||
-- Call the upsert_order function again to update the order
|
-- Call the upsert_order function again to update the order
|
||||||
SELECT public.upsert_order(makerkit.get_account_id_by_slug('makerkit'), 'cus_test', 'order_test', 'succeeded', 'stripe', 100, 'usd', '[
|
SELECT public.upsert_order(makerkit.get_account_id_by_slug('makerkit'), 'cus_test', 'order_test', 'succeeded', 'stripe', 100, 'usd', '[
|
||||||
{"id":"order_item_1", "product_id": "prod_test", "variant_id": "var_test", "price_amount": 100, "quantity": 10},
|
{"id":"order_item_1", "product_id": "prod_test", "variant_id": "var_test", "price_amount": 100, "quantity": 1},
|
||||||
{"id":"order_item_2", "product_id": "prod_test", "variant_id": "var_test_2", "price_amount": 200, "quantity": 1}
|
{"id":"order_item_2", "product_id": "prod_test_2", "variant_id": "var_test_4", "price_amount": 200, "quantity": 10}
|
||||||
]');
|
]');
|
||||||
|
|
||||||
-- Verify that the subscription items were created correctly
|
-- Verify that the subscription items were created correctly
|
||||||
@@ -54,15 +54,27 @@ SELECT is(
|
|||||||
);
|
);
|
||||||
|
|
||||||
SELECT row_eq(
|
SELECT row_eq(
|
||||||
$$ select quantity from order_items where variant_id = 'var_test' $$,
|
$$ select quantity from order_items where variant_id = 'var_test_4' $$,
|
||||||
row(10::int),
|
row(10::int),
|
||||||
'The subscription items should be updated'
|
'The subscription items quantity should be updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
SELECT row_eq(
|
SELECT row_eq(
|
||||||
$$ select price_amount from order_items where variant_id = 'var_test_2' $$,
|
$$ select variant_id from order_items where id = 'order_item_2' $$,
|
||||||
|
row('var_test_4'::text),
|
||||||
|
'The subscription items variant_id should be updated'
|
||||||
|
);
|
||||||
|
|
||||||
|
SELECT row_eq(
|
||||||
|
$$ select product_id from order_items where id = 'order_item_2' $$,
|
||||||
|
row('prod_test_2'::text),
|
||||||
|
'The subscription items prod_test_2 should be updated'
|
||||||
|
);
|
||||||
|
|
||||||
|
SELECT row_eq(
|
||||||
|
$$ select price_amount from order_items where variant_id = 'var_test_4' $$,
|
||||||
row(200::numeric),
|
row(200::numeric),
|
||||||
'The subscription items should be updated'
|
'The subscription items price_amount should be updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
select tests.authenticate_as('member');
|
select tests.authenticate_as('member');
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ SELECT public.upsert_subscription(makerkit.get_account_id_by_slug('makerkit'), '
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "sub_456",
|
"id": "sub_456",
|
||||||
"product_id": "prod_test_2",
|
"product_id": "prod_test_3",
|
||||||
"variant_id": "var_test_2",
|
"variant_id": "var_test_2",
|
||||||
"type": "flat",
|
"type": "flat",
|
||||||
"price_amount": 2000,
|
"price_amount": 2000,
|
||||||
@@ -100,14 +100,21 @@ SELECT row_eq(
|
|||||||
SELECT row_eq(
|
SELECT row_eq(
|
||||||
$$ select price_amount from subscription_items where variant_id = 'var_test' $$,
|
$$ select price_amount from subscription_items where variant_id = 'var_test' $$,
|
||||||
row('2000'::numeric),
|
row('2000'::numeric),
|
||||||
'The subscription items should be updated'
|
'The subscription items price_amount should be updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Verify that the subscription items were updated correctly
|
-- Verify that the subscription items were updated correctly
|
||||||
SELECT row_eq(
|
SELECT row_eq(
|
||||||
$$ select interval from subscription_items where variant_id = 'var_test_2' $$,
|
$$ select interval from subscription_items where variant_id = 'var_test_2' $$,
|
||||||
row('year'::varchar),
|
row('year'::varchar),
|
||||||
'The subscription items should be updated'
|
'The subscription items interval should be updated'
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Verify that the subscription items were updated correctly
|
||||||
|
SELECT row_eq(
|
||||||
|
$$ select product_id from subscription_items where id = 'sub_456' $$,
|
||||||
|
row('prod_test_3'::varchar),
|
||||||
|
'The subscription items product_id should be updated'
|
||||||
);
|
);
|
||||||
|
|
||||||
-- Verify that the subscription was updated correctly
|
-- Verify that the subscription was updated correctly
|
||||||
|
|||||||
@@ -148,10 +148,10 @@ export class LemonSqueezyBillingStrategyService
|
|||||||
...ctx,
|
...ctx,
|
||||||
error: (error as Error)?.message,
|
error: (error as Error)?.message,
|
||||||
},
|
},
|
||||||
'Failed to cancel subscription',
|
'Failed to cancel subscription. It may have already been cancelled.',
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new Error('Failed to cancel subscription');
|
return { success: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -123,10 +123,10 @@ export class StripeBillingStrategyService
|
|||||||
...ctx,
|
...ctx,
|
||||||
error,
|
error,
|
||||||
},
|
},
|
||||||
'Failed to cancel subscription',
|
'Failed to cancel subscription. It may have already been cancelled.',
|
||||||
);
|
);
|
||||||
|
|
||||||
throw new Error('Failed to cancel subscription');
|
return { success: false };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user