How to fix create-checkout-session 400 error after recent changes to offer and signup pages?

Post author
Craig Quilkey

I made a tweak to my Offerage and signup and seem to be getting a 400 error. I have the offer page where the user clicks the plan they want. They are redirected to the create account/signup screen. On click the button should redirect user to make the account and redirected to Stripe for payment. But it is creating the account in MemberStack but returning:
memberstack.js:2
POST https://client.memberstack.com/member/plans/create-checkout-session 400 (Bad Request)

could you please go here: https://www.productm8.io/ and click one of the plans and start to sign up and let me know what the issue is

regards C.
productm8.io
ProductM8 – AI-Powered Tools to Build & Validate Business Ideas Faster

Transform your business ideas into actionable plans with ProductM8. Use AI to map business models, define value propositions, and generate product strategies in minutes.

Comments

7 comments

  • Comment author
    A J

    Hey Craig Quilkey, a couple of things that I noticed would be:

    • In the offer page, you can set the 'Get Started' button's link to the page with the query parameters directly (without having an attribute and custom code to set it on the go). Currently, it seems when I do select the plan button, the price ID is not being passed as the query parameter as you would want for the setup to work. So you can simply set the query parameter of each plan button as showed in the screenshot below and replace the PRICE_ID with the actual price ID you have for each plan
    • I can see on the signup page, you have a custom code which calls window.MemberStack.openCheckout but you can find the right function to call for launching the checkout as per the developer docs here.

    The base code is as follows:

    // Initiate a Stripe Checkout session
    const response = await memberstack.purchasePlansWithCheckout({
      priceId: "PRICE_ID", // The ID of the price to purchase
      // Optional parameters:
      couponId: "COUPON_CODE",
      cancelUrl: "/cancel",
      successUrl: "/success",
      autoRedirect: true, // Default: true
      metadataForCheckout: {
        "key": "value"
      }
    });
    
    if (!response.data.url) {
      // Handle case where autoRedirect is false
      console.log("Checkout session created:", response.data);
    }
    
    return response;
    

    And in the place of "PRICE_ID" in the code, you can pass on the URL parameter that you fetch from 'planoffer' as per your setup and launch it after the signup.Also I am wondering is there a reason why you are taking a custom code approach for this?Since all of this can be done just with the use of attributes and the entire flow should be handled automatically.

    0
  • Comment author
    Craig Quilkey

    yeah its this page im having issues with:
    https://www.productm8.io/sign-up

    i have tried to add the data-ms-price:add attribute to the signup form as i was told by support dont add to the attribute to the create account button

    Even I have disabled the custom script on the pages and just tried adding the relevant attributes shared in the guide above. That approach should work without any errors, but still I face issues after adding attributes directly to the plan's get started button and disabling any custom script which affects the signup form or the buttons which have the attributes. I’m so close but I’m still getting an error on the signup page.

    I created a free subscription for some special guest but in the checkout im getting an error:

    memberstack.js:2 POST https://client.memberstack.com/member/plans/create-checkout-session 400 (Bad Request).

    The Voucher is simply revealing the 3rd panel to the user.

    Here is the URL
    https://www.productm8.io/pricing?voucherpass=CraigsVoucher

    any advice would be great

    0
  • Comment author
    A J

    Hey Craig Quilkey,

    For the 3rd panel's 'Get Started' button, can you have the custom attribute as data-ms-plan:add="pln_free-k31n90nvk" instead of data-ms-price:update="pln_free-k31n90nvk" as it is currently?

    That should solve the error and assign the free plan to the user when they click on the Get started button for the free plan.

    Hope this helps.

    0
  • Comment author
    Craig Quilkey

    Hi AJ, I applied this and tried both dynamically adding the attributes to the button or the attributes just being on the button. the Free returns an error both the start and the business buttons work fine. but the free panel does not let the user through.

    could you have another look at the URL and let me know what you think:
    https://www.productm8.io/pricing?voucherpass=CraigsVoucher

    0
  • Comment author
    A J

    I can still see that the free panel's 'Get Started' button has the custom attribute as data-ms-price:update="pln_free-k31n90nvk".

    Can you please change it to data-ms-plan:add="pln_free-k31n90nvk" and test the flow out and see if you still face any blockers?

    0
  • Comment author
    Craig Quilkey

    A J you might need to refresh as it is set to add

    Whether it is set to add or update the error is happening on the next screen once the subscribe button is pressed

    But A J i hugely appreciate your help!! thank you so much

    0
  • Comment author
    A J

    Hey Craig Quilkey,

    Welcome 😇

    The difference in the attributes I shared earlier is not just of add / update. Both the attributes are different in the use-case, such that the data-ms-price is used for paid plans and data-ms-plan is used for free ones.

    While I can see you have changed it to data-ms-price:add, what I had mentioned was to have the custom attribute as data-ms-plan:add="pln_free-k31n90nvk".

    You can also find this information by clicking the "Install & Publish" button when you select the respective free plan in Memberstack dashboard, in case you want to double-check.

    Can you make the changes and test it out to see if it helps?

    0

Please sign in to leave a comment.