Paid Plan Orders - Loop with break

Hi all

I would like to loop through the current member’s orders, and once a condition is found, break the loop, but this is the first time I have tried a loop on my Wix site and I am having problems getting it to work. I have included my code below. Is there anything obvious that I am missing?

The error in the console log states “Uncaught (in promise) TypeError: Cannot read property ‘length’ of undefined”, but I suspect this isn’t the only issue and I am struggling to find resources to help fix it.

import wixPaidPlans from 'wix-paid-plans';

const planName = "TEST";
const options = {
    day: "numeric",
    month: "short",
    year: "numeric"
};
let orderId;
let validUntil;
let today = new Date()
let price;

$w.onReady(function () {

    wixPaidPlans.getCurrentMemberOrders()
        .then((orders) => {
             for (let i = 0; i < orders.items.length; i++) {
                 if (orders.items[i].planName === planName && orders.items[i].status === "ACTIVE") {
                    $w('#text35').text = "paid member on recurring";
                     break;
                    } else {
 if (orders.items[i].planName === planName && orders.items[i].validUntil >= today) {
                        $w('#text35').text = "cancelled member still within expiry";
 break;
                    } else {
                        $w('#text35').text = "standard member";
 break;
                    }
                }
            }
        })
});

try something like this instead of using a for loop to find something use the .find() and then you can look at whats inside the result and set the text with that. I haven’t tested as i don’t use wix paid plans but it should work fine


const planName = "TEST";
$w.onReady(function () {
    console.log(findOrders());
});

function findOrders(){
 var result = wixPaidPlans.getCurrentMemberOrders().find((order => order.planName === planName && order.status === "Active" ));
 return result;
} 

Thanks Some Guy. Unfortunately I am getting an error

TypeError: _wixPaidPlans2.default.getCurrentMemberOrders(…).find is not a function

I managed to get the loop working. For anyone interested, code is below. Many thanks

wixPaidPlans.getCurrentMemberOrders()
        .then((orders) => {
 for (let i = 0; i < orders.length; i++) {
 let item = orders[i];
 if (item.planName.substr(0, 8) === planName && item.status === "ACTIVE") {
                    $w('#text35').text = "umi plus member";
 break;
                } else {
 if (item.planName.substr(0, 8) === planName && item.validUntil >= today) {
                        $w('#text35').text = "cancelled member still within expiry";
 break;
                    } else {
                        $w('#text35').text = "standard member";
 break;
                    }
                }
            }
        })