简体   繁体   English

试用结束后显示高级条带订阅

[英]showing premium stripe subscription after trial ends

I have an app in which I have successfully set up stripe payments, with a trial, and then after the 60 day trial, a 9.99 per month fee.我有一个应用程序,我在其中成功设置了条带付款,并进行了试用,然后在 60 天试用后,每月收取 9.99 美元的费用。 However, once the 60 days is up, I want to give the user an option to have a 99.99 per year one time fee instead.但是,一旦 60 天结束,我想给用户一个选项,改为每年收取 99.99 的一次性费用。

I have done this, but the problem is, if I go into the manage subscriptions page in my app, it gives the option for the 99.99 plan even if the 60 days isnt up, and then if I click update to move to that plan, it doesn't cancel the original trial, and then pretty much breaks my code after that.我已经这样做了,但问题是,如果我 go 进入我的应用程序中的管理订阅页面,即使 60 天没有结束,它也会提供 99.99 计划的选项,然后如果我单击更新以移至该计划,它不会取消原始试用版,然后在此之后几乎破坏了我的代码。

code (just incase needed)代码(以防万一需要)

    export async function createCheckoutSession(){
  let user = firebase.auth().currentUser;

      const checkoutSessionRef =  firestore
      .collection('customers')
      .doc(userID)
      .collection('checkout_sessions')
      .add({
        price: 'price_1Iav0JKDPaWWeL1yBa9F7Aht',
        success_url: "http://localhost:3000/successPage",
        cancel_url: "http://localhost:3000/signup",
    });
      // Wait for the CheckoutSession to get attached by the extension
            (await checkoutSessionRef).onSnapshot(function (snap) {
              const { error, sessionId } = snap.data();
              if (error) {
            // Show an error to your customer and 
            // inspect your Cloud Function logs in the Firebase console.
              console.log(`An error occured: ${error.message}`);
            }
            if (sessionId) {
            // We have a session, let's redirect to Checkout
            // Init Stripe
            const stripe = window.Stripe('pk_test');
            stripe.redirectToCheckout({sessionId})
            console.log("logged stripe")
          }
      });
    }

manage subscription function (firebase api)管理订阅 function (firebase api)

  export async function goToBilliingPortal(){
  const functionRef = app
  .functions('us-central1')
  .httpsCallable('ext-firestore-stripe-subscriptions-createPortalLink');
  const {data} = await functionRef({returnUrl : window.location.origin});
  window.location.assign(data.url);
};

is there a way to hide the 99.99 plan until the trial is up?有没有办法在试用期结束之前隐藏 99.99 计划?

You'll need to keep track of the trial status yourself and check it when generating Customer Portal links.您需要自己跟踪trial状态并在生成客户门户链接时进行检查。 While trialing, if you do not wish to allow the customer to change to another plan you need to create another Portal Configuration which disabled subscription updates ( ref ).在试用期间,如果您不希望客户更改为另一个计划,您需要创建另一个禁用订阅更新的门户配置( 参考)。

During the trial you'd use this configuration when creating portal links ( ref ).在试用期间,您将在创建门户链接 ( ref ) 时使用此configuration After the trial you can use another configuration when allows for changes.试用后,您可以在允许更改时使用其他配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM