I have got a problem while sending an array of multiple items while creating a payment in the backend where I want to initialize items variable with the multiple items array. Here is my code for doing such task can you please help me out why it’s returning an empty error.
Please help me ASAP!
import wixPay from ‘wix-pay-backend’;
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
export function createPayment() {
let products=wixData.query(‘Cart’).eq(‘userId’,wixUsers.currentUser.id).find().
then((result)=>{
let items=;
if (result.items.length>0) {
for ( var i = 0; i < result.items.length; i++) {
let option={
name:result.items[i].productName,
price:result.items[i].productPrice,
quantity:1
}
items.push(option)
}
}
return (items);
}). catch ((err)=>{
return (err.message);
})
console.log(products)
let total=0;
for ( var i = 0; i < products.length; i++) {
total=total+products[i].price;
}
let option={
items:products,
amount:total,
currency:‘USD’
}
return wixPay.createPayment(option)
}
//Here is the frontend code
export function checkout_click(event) {
createPayment().then((payment)=>{
wixPay.startPayment(payment.id)
}). catch (err=>console.log(err))
}