How to use the cancelOrder() API reference?

Ok, this must be your still missing part…

You are asking for → LISTING ALL ORDERS OF A SPECIFIC MEMBER, right?
Let’s take a closer look on my example…

I am logen-in with my account, see the picture… (velo-ninja)
https://velo-ninja.wixsite.com/pricing-plans-setup/plans-pricing/payment/eyJpbnRlZ3JhdGlvbkRhdGEiOnt9LCJwbGFuSWQiOiI0NjBkZDE5Ni1hYzc1LTRjNDgtYWY1YS1mM2IzOTAzZmQzZTIifQ

You will see

And here you can see all PLANS of Velo-Ninja he already have had interacted with (used or still using)…

Here we have a list which shows us all PLANS of a specific USER, right?
So in this case we have 2-USERS

a) NOBODY → 1-ORDER purchased (ACTIVE
b) Velo-Ninja → 4-purchased ORDERS (all marked as payed) → 2x ACTIVE & 2 CANCELED.

So we know now, that velo ninja has 4-ORDERS in TOTAL, right?

Ok and before i show you the wished to see code, which do the magic, we need first to know the ID of Velo-Ninja, right?

Velo-Ninja’s Contact-ID: →
2024-01-07 14_22_27-Pricing-Plans-Setup _ Pricing Plans Setup

Ok, so let’s jum onto our little EXAMPLE-SETUP…
https://velo-ninja.wixsite.com/pricing-plans-setup

Once clicked onto → Load-Plans —> you get the owerview of the plans in a table.

The CONSOLE-LOG-OUTPUT for this STEP:

We have listed all the available plans with a button-click.
But what YOU want is to list all → ORDERS <— of a specific MEMBER, right?

Velo-Ninja is the specific MEMBER in this case and is logged-in.
Logged-In means he has already an ID (CONTACT-ID).

So ATTENTION → now comes the IMPORTANT-PART!!!

We click onto → ‘List my Orders

And what do we get inside of CONSOLE ???
2024-01-07 14_34_19-Pricing-Plans-Setup _ Pricing Plans Setup

We got an OBJECT, let’s open it…


That looks promising !!!

Let’s open one of the ITEMS…

I don’t know but, looks like all the 4-orders we were talking about before…

So? Did we got all ORDERS LISTED TO A SPECIFIC MEMBER ???

Let’s check again inside the DASHBORAD !

Yes looks like velo-ninja has endeed 4-maden orders in his subscription-area.

And to complete all that test-setup → Let’s CANCEL → ITEM[0] <----

We click onto…

But before we do this → let’s first grab the ID of the current selected-ORDER → ITEM[0], you will find it here…

The ordinary-ID i was talking about in my previous post.
Why wix did not call it → orderID ← i don’t know.
For everyone it is clear that marking such things in a to simple way like → id ← can cause problems later.

However!!!
We have our ORDER-ID, now let’s go back to the function i have shown your before in my previous post…

It was the BUTTON number 4 → for cancelation ???

$w('#btn4').onClick(async()=>{console.log('click')
   
   let ID = '471de1d9-0a44-428b-bee0-c01a0aba3639';
   
      let orderCanceled = await cancel_order(ID, "IMMEDIATELY", {suppressAuth: true}); console.log('orderCanceled: ', orderCanceled);       
  
});

Yeah, here i did not grab the ID automaticaly (just put it in HARD-CODED) you will have to change this of course, at make the code grab the ID → AUTOMATICALY at this point.

So we put in (replace) our current selected ORDER-ID of ITEM[0]

13122f6b-6a00-4cf0-a461-86d638089f0f —> into our function and publish website.
(Yeah forgot to update this code-part to AUTOMATIC GRAB THE ID).

$w('#btn4').onClick(async()=>{console.log('click')
   
   let ID = ' 13122f6b-6a00-4cf0-a461-86d638089f0f';
   
      let orderCanceled = await cancel_order(ID, "IMMEDIATELY", {suppressAuth: true}); console.log('orderCanceled: ', orderCanceled);       
  
});

And now finaly i am ready to click the CANCEL-BUTTON to cancel my order!!!

What did we got, after we have pressed the CANCEL-BUTTON ???
2024-01-07 14_54_48-Pricing-Plans-Setup _ Pricing Plans Setup

Seems like everything has worked well and we were able to cancel the specific order we wanted, right???

Let’s check! What happened to the FIRST-ORDER of → VELO-NINJA ???

CONCLUSION:
1) Were we able to get orders of a specific MEMBER ? —> YES !!!
2) Were we able to cancel one of the found ORDERS for a specific MEMBER ? → YES !!!
3) Did we use installed Wix-Members-Area? → NO!!!

Ok, it is not really a specific MEMBER → it is more the CURRENT-LOGGED-IN-MEMBER, but this is waht you wanted → A MEMBER should have the opertunity to be able to cancel his own subscriptions/orders on a selected PLAN.