Ok, my friend, i think i got it to work on my test-site.
I made a lot of investigation to get it to work.
Some facts about my setup …
-YOU DO NOT NEED → Wix-Members-APP to be installed on your site (it works with wix-contacts, but a login is needed anyway.) —> LOGIN (o.k)
So this points were ok in your project.
-The Wix-Pricing-Plan-APP, of course has to be installed on your site, without it, you simply can’t do anything.
Also already done in your setup. —> installed PricingPlan-App (o.k.)
-Once you have installed the APP → you navigate to …
…in your wix-dashboard to create a new plan (this also can be done by CODE)
…our first plan…
…in detail…
This was done in your setup aswell → setting-up a new plan (o.k.)
SIDE-STEP: At this point we can see a TOGGLE-BUTTON (Allow plan-cancellation) —> this setup will work inside of your Wix-Members-Area
…you can learn more about it here…
Ok, i know at this point, you would say now → ‘but i do not want to use Wix-Members-Area’, that was your point causing the issue (no problem, we need to find another way).
So let’s continue.
We already setted-up our first test-plan called ‘Under-Contsruction-Plan’ .
We can set-up several plans of course, but what we want to do now is to Sell a plan
Since i setted-up a complete new website for testings (Pricing-Plan-APP installed only) i was the only member on my own site (no installed Member-Area, contacts only).
So i created a second TEST-CONTACT …
…and so on…
So at least we have now 2-Contacts in our setup.
-Mr-Nobody
-and me.
Where we can add a subscription/order… → selling a plan…
…marking it as paid → will create a new generated subscription…
So here you already can see 3x-FREE-subscriptions and one of those is → CANCELED.
You can do the cancelation of a subscription, directly in the Wix-Dashborad, like…
… after you have selected one of the subscription-members. Let’s do a futher cancelation of an order…
That was the cancelation of an order/subscription directly from the Wix-Dashboard, what you did not want to be done like that, right from the beginning.
Your intention was to do it different, to manage it by code → so let’s do it !!!
To be able to do it by code, you will have to ccreate a backend-JWS-module first.
->ou can call it like you want, i would say ‘pricingplans’, or just ‘plans.jsw’ would be ok.
Inside of this backend-module you place the following code…
export async function cancel_order(orderId, effectiveAt, options) {
try {
const order = await orders.cancelOrder(orderId, effectiveAt, options);
return order;
} catch (error) {
console.error(error);
return error;
}
}
The most will have difficulties while working with the description of the most API of wix, since there are often some hidden parts, anyone really mentins, here we have also such a part…
(orderId, effectiveAt, options); → options represents → {suppressAuth: true}
Even the AUTOCOMPLETION inside of the Wix-EDITOR did not recognize it and marked it as RED…
…as if the cancelOrder-function expects 2 values only! But in fact it need the SUPRESS AUTH for AUTORIZATION !!!
I can’t tell you any more where i have found it, but it seems there are different APIs out there, one of those mentioned it, others not!
Since there were Paid-Plan-APIs in the past and now even v2-version came out (so in total 3 different APIs → maybe something mixed up and wix could not give a clean overvie over their APIs → i mean even the AUTOCOMPLETION do not know, WHAT IS RIGHT AND WHAT IS WRONG!
However, after further investigations i got it at least to work!
I was able to cancel the order → with a click onto your wished CUSTOM CANCEL-ORDER-BUTTON to be able to cancel a subscription.
Oh, of course you need also the FRONT-END-CODE fot it…
I will show you just a simple version of it…
$w('#btn4').onClick(async()=>{console.log('click')
let ID = '471de1d9-0a44-428b-bee0-c01a0aba3639';
let subscriptionID = 'cec3b960-4d95-4bc1-9b25-a09859124949'; //'fca0d1d0-e625-468b-9fe9-e191ba72d8ef'; //'cec3b960-4d95-4bc1-9b25-a09859124949';
let orderCanceled = await cancel_order(ID, "IMMEDIATELY", {suppressAuth: true}); console.log('orderCanceled: ', orderCanceled);
});
You also have to pay attention to differ between →
a) memberID
b) contactID (same like member-ID)
c) subscriptionID
e) orderID
f) and even just an ordinary ID
You can see here cleary that i have tried different versions, to get it to work, since in the API-DOCS this point was not really described in detail.
Also take a look onto the logs in the console of my test-setup… the the difference before and after clicking onto the custom cancel-order-button…
All these subscriptionIDs were wrong, so it was not the subscription-ID at the end as assumed, it was just the ordinary-ID…
let subscriptionID = ‘cec3b960-4d95-4bc1-9b25-a09859124949’; //‘fca0d1d0-e625-468b-9fe9-e191ba72d8ef’; //‘cec3b960-4d95-4bc1-9b25-a09859124949’;
…but wait, what the h e l l i am talking about?
Well, before you can cancel an order by a custom generated code, of course first you have to find the right order you want to cancel, right??? → RIGHT !!!
So, let’s do it first…
$w('#btn3').onClick(async()=>{let options = {fieldset:'full'}
let orderList = await member_ListOrders(options); console.log('Orderlist: ', orderList);
});
and again a BACKEND-CODE we need…
export async function member_ListOrders(options) {
try {
const result = await orders.memberListOrders(options);
return result;
} catch (error) {
console.error(error);
return error
}
}
So without to write 5 more pages and discuss about all that topic, at the end it was possible to get everything working.
And to answer your question at the end → YES IT IS POSSIBLE TO CANCEL AN ORDER BY A CUSTOM GENERATED CODE; BY A CLICK ONTO A CUSTOM BUTTON ON, SOMEWHERE ON A CUSTOM PAGE, TO BE ABLE TO CANCEL THE ORDER, EVEN WITHOUT HAVING INSTALLED A MEMBERS-AREA.
YEAH —> EVEN NOT HAVING SETTED UP A LOGIN-SYSTEM → JUST USED THE CONTACTS.
My complete little test-setup with just instelled Wix-Pricing-Plans on this test-website, looked like…
CUSTOM-PAGE…
And this one was generated automatically by wix…
Every of the shown blue buttons has a CODED-API-INTERACTION with the PRICING-PLANS-APP
https://velo-ninja.wixsite.com/pricing-plans-setup
I hope these are enough infos about PRICING-PLANS for you, regarding your issue.
Took me just 24-hours (JUST)
ISSUE → RESOLVED ???