Wix Plans Direct Purchase on Repeater

Hello,

I was wondering if anyone can please help me figure out why my code is not working?

I am using the Wix-Pricing-Plans Api and followed the instructions, but I am not able to trigger the startOnlinePurchase event for each item in my repeater.

startOnlinePurchase - Velo API Reference - Wix.com

I have the repeater setup like above and linked to a dataset (#dataset1) that is then tied to the pricing plans database.

The buy now button is labelled #button1 and has the OnClick event handler set.

Here is my code.

import { checkout } from 'wix-pricing-plans';

let planId = $w("#dataset1").getCurrentItem();
console.log(planId);

$w('#button1').onClick((event) => {
  checkout.startOnlinePurchase(planId)
      .then((purchase) => {
          const myOrderId = purchase.order._id;
          const myWixPayOrderId = purchase.order.wixPayOrderId;
          const myWixPayStatus = purchase.wixPayStatus;
      });
});

When I check the console log I get all the plan information for the first plan in the repeater. (Plan Id, Price, Description etc.)

It should be simple and I am sure I am missing something small but just cannot figure out what it is sorry if anyone could help that would be greatly appreciated.

Thanks in advance!

Are you in preview?

@certified-code No same problem when published on live site as well sadly.

Is your code wrapped in the onReady function?

@certified-code no it is not actually I did try that earlier and it still didn’t work but I can definitely try again for sure. Thanks!

@certified-code I added the onReady and still nothing sorry. :frowning:

Here is my code.


import { checkout } from 'wix-pricing-plans';


$w.onReady(function () {

let planId = $w("#dataset1").getCurrentItem();
console.log(planId);

$w('#button1').onClick((event) => {
  checkout.startOnlinePurchase(planId)
      .then((purchase) => {
          const myOrderId = purchase.order._id;
          const myWixPayOrderId = purchase.order.wixPayOrderId;
          const myWixPayStatus = purchase.wixPayStatus;
      });
})
});

@certified-code I have not been able to fix this just wondering if you had any suggestions? If not no worries I will just have to try a different way but would prefer this method I just for some reason am struggling with this API.

I have now figured this out and it does work. Now it allows the current plan displayed in the repeater to be purchased directly by the click of the button.

Here is my code:


import wixPaidPlans from 'wix-paid-plans';
import wixData from 'wix-data';

$w.onReady( function () {
 $w("#button1").onClick( (event) => {
   let $item = $w.at(event.context);
   let clickedItemData = $item("#dataset2").getCurrentItem();
   let planId = clickedItemData._id
 wixPaidPlans.orderPlan(planId)
      .then((myOrder) => {
        let myOrderId = myOrder.orderId;
        let myWixPayOrderId = myOrder.wixPayOrderId;
console.log(planId);

 
      });
})
})

not working on mine