starting to use webhook
This commit is contained in:
parent
bcf8946740
commit
88d9c5f2cd
|
@ -19,7 +19,6 @@ paymentRouter.use((req, res, next) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
paymentRouter.post("/create-checkout-session", async (req, res, next) => {
|
paymentRouter.post("/create-checkout-session", async (req, res, next) => {
|
||||||
console.log("with key", env.stripeSecretKey);
|
|
||||||
try {
|
try {
|
||||||
const prices = await stripe.prices.list({
|
const prices = await stripe.prices.list({
|
||||||
lookup_keys: [req.body.lookup_key],
|
lookup_keys: [req.body.lookup_key],
|
||||||
|
@ -35,7 +34,6 @@ paymentRouter.post("/create-checkout-session", async (req, res, next) => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
mode: 'subscription',
|
mode: 'subscription',
|
||||||
// TODO ADD URLS
|
|
||||||
success_url: `https://account.lingdocs.com/user?upgrade=success`,
|
success_url: `https://account.lingdocs.com/user?upgrade=success`,
|
||||||
cancel_url: `https://account.lingdocs.com/user`,
|
cancel_url: `https://account.lingdocs.com/user`,
|
||||||
});
|
});
|
||||||
|
@ -91,13 +89,6 @@ paymentRouter.post(
|
||||||
let status;
|
let status;
|
||||||
// Handle the event
|
// Handle the event
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'customer.subscription.trial_will_end':
|
|
||||||
subscription = event.data.object;
|
|
||||||
status = subscription.status;
|
|
||||||
console.log(`Subscription status is ${status}.`);
|
|
||||||
// Then define and call a method to handle the subscription trial ending.
|
|
||||||
// handleSubscriptionTrialEnding(subscription);
|
|
||||||
break;
|
|
||||||
case 'customer.subscription.deleted':
|
case 'customer.subscription.deleted':
|
||||||
subscription = event.data.object;
|
subscription = event.data.object;
|
||||||
status = subscription.status;
|
status = subscription.status;
|
||||||
|
@ -109,16 +100,10 @@ paymentRouter.post(
|
||||||
subscription = event.data.object;
|
subscription = event.data.object;
|
||||||
status = subscription.status;
|
status = subscription.status;
|
||||||
console.log(`Subscription status is ${status}.`);
|
console.log(`Subscription status is ${status}.`);
|
||||||
|
console.log(`Will upgrade ${request.user?.name}`);
|
||||||
// Then define and call a method to handle the subscription created.
|
// Then define and call a method to handle the subscription created.
|
||||||
// handleSubscriptionCreated(subscription);
|
// handleSubscriptionCreated(subscription);
|
||||||
break;
|
break;
|
||||||
case 'customer.subscription.updated':
|
|
||||||
subscription = event.data.object;
|
|
||||||
status = subscription.status;
|
|
||||||
console.log(`Subscription status is ${status}.`);
|
|
||||||
// Then define and call a method to handle the subscription update.
|
|
||||||
// handleSubscriptionUpdated(subscription);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
// Unexpected event type
|
// Unexpected event type
|
||||||
console.log(`Unhandled event type ${event.type}.`);
|
console.log(`Unhandled event type ${event.type}.`);
|
||||||
|
|
|
@ -53,7 +53,8 @@
|
||||||
</form>
|
</form>
|
||||||
<h5>Account Level: <%= user.level.charAt(0).toUpperCase() + user.level.slice(1) %></h5>
|
<h5>Account Level: <%= user.level.charAt(0).toUpperCase() + user.level.slice(1) %></h5>
|
||||||
<% if (upgrade === "success") { %>
|
<% if (upgrade === "success") { %>
|
||||||
<p>🎉 Subscription started. Thank you for your purchase! 🎉</p>
|
<p>🎉 Account upgraded to student 🎉</p>
|
||||||
|
<p>Thank you for your purchase!</p>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if (user.level === "basic") { %>
|
<% if (user.level === "basic") { %>
|
||||||
<% if (user.upgradeToStudentRequest === "waiting") { %>
|
<% if (user.upgradeToStudentRequest === "waiting") { %>
|
||||||
|
|
Loading…
Reference in New Issue