▷ wixPaidPlans : cancelOrder Does not work

Good morning all,

I am currently having an issue canceling a user’s subscription with “Paid-plan”.

Small scenario : the user is connected and as soon as he arrives on the page, his subscription is canceled. Here is my code:

const planId = "e308d72c-e7b8-49aa-9c98-bccc42dd4dbd"; // Get the order ID of the subscription to cancel

wixPaidPlans.cancelOrder(planId)
    .then(() => {
        console.log("Subscription canceled !");

    })
    .catch((error) => {
 let errorMsg = error.message;
 let code = error.code;
        console.log(error.message);
    });

I don’t understand why, nothing is happening, the subscription is still present and has not been canceled. Here is the error that my browser console displays:

I did the same with adding another subscription when the user arrives on the page. And it works ! The code :

let planId = "fde335dc-cd5f-401e-97be-ff99bc4214a3";
                        wixPaidPlans.orderPlan(planId)
                            .then((myOrder) => {
 let myOrderId = myOrder.orderId;
 let myWixPayOrderId = myOrder.wixPayOrderId;
                        });

Please help me get my code to work so that the subscription in question automatically cancels when I get to the page. I really don’t understand my mistake, especially since I did exactly what the documentation says.

I’m working with this api, took me a bit to understand it. The cancel order only cancels that specific order, it doesn’t cancel the subscription. Meaning, the user can buy multiple subscriptions (orders) from the same plan. Therefore, to cancel a subscription you have to cancel all the orders of that subscription.

Also: Check that the ID that you are passing is the ID of the orderID, not he plan ID. You get the orderID via this api:
https://www.wix.com/corvid/reference/wix-paid-plans/getcurrentmemberorders

Also: On the function, you mention it doesn’t work, you are calling the cancelOrderApi, probably it doesn’t work because of you are passing the planID and not the OrderID. And in the function you say it works, you are using a different API to subscribe to a plan with the planID, so the second function will work, but you are ordering a plan not canceling an order

Hello, thank you for your answer !

How can I cancel all orders for this subscription with the code?
Thanks for your future reply ! :smiley:

Indeed, it was the id of the plan but how can I do to know the id of the order? I went through the database to get the plan id and I did a copy paste. But there, I don’t see any “id” for the commands. Can
you help me so I can know the order id please?

PS: I put back “orderplan” as indicated in the documentation but the error remains the same.

I don’t know if you are still having this problem but I had the same and fixed it by changing the ‘myOrder.wixPayOrderId’ to ‘myOrder.id’. The wixPayOrderId is always empty when running the code, however using just ‘id’ returns the ID specific to the order.