I am currently working over my client site where I created a fully custom e-commerce site without using any Wix store.
I have created the database of “Cart” where when any user click on “Add to cart” button on any product page then that product with having some details will be inserted into the “Cart” database with having the current user ID now the problem arise while I am creating the payment in back-end while creating payment according to the products in that database.
-----Backend code----------
import wixData from 'wix-data';
import wixPayBackend from 'wix-pay-backend';
export async function createMyPayment (userID) {
let pro=await wixData.query('Cart').eq('userId', userID).find().then((result)=>{
let option=[];
let total=0;
for (var i = 0; i < result.items.length; i++) {
let temp={
name:result.items[i].productName,
price:result.items[i].productTotal,
quantity:0
}
total=total+temp.price;
option.push(temp)
}
let res={
item:option,
tot:total
}
return res;
})
return wixPayBackend.createPayment({
items:pro.item,amount:pro.tot,currency:"USD"
})
}
----------------Client side code----------------
export async function checkout_click(event) {
await createMyPayment(wixUsers.currentUser.id).then((payment)=>{
wixPay.startPayment(payment.id)
}).catch(err=>console.log(err))
}
After completing this when I am previewing the site this error rising when clicking on the checkout button.
Error: WixPayBackend.createPayment: can’t create payment, details: Total amount should be the sum of the item amounts
Please kindly help me out your help will be highly appreciated!!!