I am trying to use wix pay api to let my site visitors pay after filling out a form I created with wix code. However, i don't want them to re-enter their information when they click Proceed to Payment. They already have filled out their first name, last name, email, phone number, and price (the quantity is set to 1 by default).
I just want the information to be passed on to the payment window when it opens:
The backend code:
payment.jsw
import wixPay from 'wix-pay-backend'; export function createMyPayment() { return wixPay.createPayment({ items: [{ firstName: "XYZ", lastName: "CXZ", email: "noreply@noreply.org", phone: "1234567890", name: "Donation", price: 10 }], amount: 10 }); }
The client side code:
import {createMyPayment} from 'backend/payments'; import wixPay from 'wix-pay'; import wixWindow from 'wix-window'; $w.onReady(function () { }); export function pay_click() {
createMyPayment({ items: [{ firstName: $w('#firstName').value, lastName: $w('#lastName').value, email: [$w('#email').value], phone: $w('#phone').value, name: $w('#name').value quantity: 1, }], amount: amount1 } ) .then( (payment) => { wixPay.startPayment(payment.id) .then( (result) => { if (result.status === "Successful") { } else if (result.status === "Failed") { // handle payment failure } else if (result.status === "Pending") { // handle payment pending } else if (result.status === "Cancelled") { // handle user closing payment panel } } ); } ); }
@chajj
You have an incorrect context for the button's onClick. You should have this:
$item('#pay').onClick(async () => {
$w is the global context, and $item is the local context.