You don’t need to change much in this tutorial, so you have changed it too much.
If you go carefully down through step 5 it will show and explain to you how to add the code and what to change etc.
If anything needs to be changed in the code, it will be mentioned in the tutorial that it needs to be changed.
As for the pay or cancel part of the lightbox, then don’t worry as that is all contained within the code already.
If you look at it you can work out what is what with the open lightbox command and the then if go for it, then it starts the Wix Pay start payment function etc, etc.
It does work and runs correct, it just doesn’t look right if you don’t understand it completely.
As part of our customization, we added two lightboxes to our site (to be used in Step 5).
-
The Confirm lightbox displays information about the currently-selected plan, and provides buttons for continuing or canceling the purchase.
-
The Congrats lightbox lets you know that you purchased a free plan.
In this step, we kept it simple. However, this is the opportunity for you to really customize the process as you like.
So just make sure that you have the two buttons setup on your are you ready lightbox with the confirm one called goForIt.
The Not Yet button you simply utilize the close button of the lightbox itself and change the design of it to whatever design you have for the confirm button so that they match. Then if they choose Not Yet then the lightbox is just closed and they don’t proceed any further with the plan purchase.
Plus, take off the lightboxes ‘X’ close button too as you only need the yes or no buttons on the lightbox.
In our example, we customized the flow by:
-
If the plan costs money, asking for user confirmation using the Confirm lightbox. If the user confirms, we call orderPlan() and then process payment with the Wix Pay startPayment function.
-
If the plan is free, using the Congrats lightbox to let the user know the plan order is successful.
The order details are contained in the orderObject object.
When copying this snippet, make sure to change the names of your lightboxes to match your own.
function processPlan(myId, myPrice) {
if (myPrice > 0) {
wixPaidPlans.orderPlan(myId).then(orderObject => {
wixWindow.openLightbox("Confirm", orderObject)
.then((goForIt) => {
if (goForIt) {
wixPay.startPayment(orderObject.wixPayOrderId);
}
});
})
} else {
wixPaidPlans.orderPlan(myId).then(orderObject => {
wixWindow.openLightbox("Congrats", orderObject);
})
}
}
Finally just remember that this tutorial has parts of it in the backend, so it won’t work properly when previewing your site.
Hopefully that all makes sense to you.