Merge remote-tracking branch 'origin/main'

This commit is contained in:
giancarlo
2024-05-15 11:08:59 +07:00
8 changed files with 60 additions and 38 deletions

View File

@@ -35,26 +35,6 @@ export default createBillingSchema({
cost: 9.99,
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',
lineItems: [
{
id: 'price_pro',
id: 'price_1PGOAVI1i3VnbZTqc69xaypm',
name: 'Base',
cost: 19.99,
type: 'flat',

View File

@@ -1645,9 +1645,12 @@ on conflict (
item_data
on conflict (id)
do update set
product_id = excluded.product_id,
variant_id = excluded.variant_id,
price_amount = excluded.price_amount,
quantity = excluded.quantity,
interval = excluded.interval,
type = excluded.type,
interval_count = excluded.interval_count;
return new_subscription;
@@ -2018,6 +2021,8 @@ on conflict (
on conflict (id)
do update set
price_amount = excluded.price_amount,
product_id = excluded.product_id,
variant_id = excluded.variant_id,
quantity = excluded.quantity;
return new_order;

View File

@@ -12,7 +12,10 @@ INSERT INTO public.billing_customers(account_id, provider, customer_id)
VALUES (tests.get_supabase_uid('primary_owner'), 'stripe', 'cus_test');
-- 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
SELECT is(
@@ -29,7 +32,9 @@ SELECT row_eq(
);
-- 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
select is(
@@ -41,7 +46,7 @@ select is(
select row_eq(
$$ select quantity from order_items where variant_id = 'var_test' $$,
row(10::int),
'The subscription items should be updated'
'The order items should be updated'
);
select is_empty(
@@ -49,6 +54,12 @@ select is_empty(
'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');
-- account can read their own subscription

View File

@@ -80,7 +80,7 @@ SELECT public.upsert_subscription(tests.get_supabase_uid('primary_owner'), 'cus_
},
{
"id": "sub_456",
"product_id": "prod_test_2",
"product_id": "prod_test_3",
"variant_id": "var_test_2",
"type": "flat",
"price_amount": 2000,
@@ -97,6 +97,13 @@ SELECT row_eq(
'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
SELECT row_eq(
$$ select interval from subscription_items where variant_id = 'var_test_2' $$,

View File

@@ -35,8 +35,8 @@ SELECT row_eq(
-- 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', '[
{"id":"order_item_1", "product_id": "prod_test", "variant_id": "var_test", "price_amount": 100, "quantity": 10},
{"id":"order_item_2", "product_id": "prod_test", "variant_id": "var_test_2", "price_amount": 200, "quantity": 1}
{"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_2", "variant_id": "var_test_4", "price_amount": 200, "quantity": 10}
]');
-- Verify that the subscription items were created correctly
@@ -54,15 +54,27 @@ SELECT is(
);
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),
'The subscription items should be updated'
'The subscription items quantity should be updated'
);
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),
'The subscription items should be updated'
'The subscription items price_amount should be updated'
);
select tests.authenticate_as('member');

View File

@@ -80,7 +80,7 @@ SELECT public.upsert_subscription(makerkit.get_account_id_by_slug('makerkit'), '
},
{
"id": "sub_456",
"product_id": "prod_test_2",
"product_id": "prod_test_3",
"variant_id": "var_test_2",
"type": "flat",
"price_amount": 2000,
@@ -100,14 +100,21 @@ SELECT row_eq(
SELECT row_eq(
$$ select price_amount from subscription_items where variant_id = 'var_test' $$,
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
SELECT row_eq(
$$ select interval from subscription_items where variant_id = 'var_test_2' $$,
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

View File

@@ -148,10 +148,10 @@ export class LemonSqueezyBillingStrategyService
...ctx,
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 };
}
}

View File

@@ -123,10 +123,10 @@ export class StripeBillingStrategyService
...ctx,
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 };
}
}