The payment system works on the page of all products of the store, but does not work on the page of a separate item.
In the editor, during the preview, it shows that the system cannot find the ID of item and, because of this, does not display the payment page.
Photos are not uploaded to the forum, so I attach files.
Backend:
// Filename: backend/pay.jsw (web modules need to have a .jsw extension)
export function multiply(factor1, factor2) {
return factor1 * factor2;
}
//Use the following code in one of your site's front-end files
//to call the multiply function from backend/pay.jsw.
/*
import {multiply} from 'backend/pay';
$w.onReady(function () {
multiply(4,5).then(product => {
console.log(product);
// Logs: 20
})
.catch(error => {
console.log(error);
});
});
*/
/**************************
* backend code - pay.jsw *
**************************/
import wixData from 'wix-data';
import wixPayBackend from 'wix-pay-backend';
export async function createMyPayment(productId) {
let rr = await wixData.query("BellaShop")
.eq("_id", productId)
.find()
.then(async (results) => {
if (results.items.length > 0) {
let firstItem = results.items[0];
return await wixPayBackend.createPayment({
items: [{
name: firstItem.title,
price: firstItem.price
}],
amount: firstItem.amount
});
} else {
// handle case where no matching items found
}
})
.catch((err) => {
let errorMsg = err;
});
return rr
/*
let tt = await wixData.get("BellaShop", productId)
.then(async (product) => {
console.log(product);
return await wixPayBackend.createPayment({
items: [{
name: product.title,
price: product.price
}],
amount: product.amount
});
});
return tt;
*/
}
Bella Shop Page Code:
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixData from 'wix-data';
//import wixPayBackend from 'wix-pay-backend';
import { createMyPayment } from 'backend/BS_Pay.jsw';
import wixPay from 'wix-pay';
$w.onReady(function () {
console.log("sdsdsds")
console.log("Ffffffffffffffffffffffffffffff")
});
/**************************
* backend code - pay.jsw *
**************************/
/********************
* client-side code *
********************/
export function myButton_click(event) {
console.log(event)
console.log(event.context.itemId)
let ttt=event.context.itemId
createMyPayment(ttt)
.then((payment) => {
console.log(payment)
wixPay.startPayment(payment.id);
});
}