I wanted to make a really simple button, in a custom Plans page, that allows the client to go through the payment just like the pricing plans standard page. I added the function but it seems that it can’t read the Plan ID.
I’ve tried a lot of things, I came back to the standard code to see if anyone actually has a more simple solution. I just want it to read the ID of the plan so I can “copy and paste” the same code in other buttons.
You’ve got your onClick event handler confused. You can either put your onClick code in the page’s onReady(), or as a separate function (outside of the onReady). But not both, and not one inside of the other. See Where do I put my code for an explanation.
Your code should look something like this:
import wixPaidPlans from 'wix-paid-plans';
$w.onReady(function () {
});
export function myPurchaseButton_click(event) {
let planId = '< plan ID for a non-free plan >';
wixPaidPlans.purchasePlan(planId)
.then((myPurchase) => {
let myOrderId = myPurchase.orderId;
let myWixPayOrderId = myPurchase.wixPayOrderId;
let myWixPayStatus = myPurchase.wixPayStatus;
});
}
The above shows the onClick in a separate function as the sample snippet in the purchasePlan() API illustrates.