Wix-Pay API Help

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
}
} );
} );
}

See the post New Feature Opened: PAY API! for more information and an example app.

Hi! I’m a product manager in the Wix Forms team at Wix. I’d be happy to talk to you to better understand your needs. Please let me know if you’d be willing to schedule a call with me. Thanks!

1 Like

Hi Rinat, happy to schedule a call! Please let me know how you would like to connect!

Hello @yisrael-wix ! Thank you always for your help. I have followed the example you have mentioned above. However, I seem to have a problem that I am hoping you can assist me with!

I have a collection with 4 items (fields: title, price and price value - Permission: Site Content)
I have a repeater connected to that database.

On my live website and on preview mode, the repeater shows the items perfectly, the corresponding price to each item. However, when I click Buy Now, the amount on checkout changes to a different item.

For a better understanding of the issue, this is a screencast of the issue (google drive)

My backend code is the following

iimport wixPay from ‘wix-pay-backend’;
import wixData from ‘wix-data’;

export async function createPaymentForProduct(productId) {
let product = await wixData.get(‘LGBTBARNY_SPONSORSHIP’, productId);
return wixPay.createPayment({
amount: product.priceValue,
items: [
{name: product.title, price: product.priceValue}
]
});
}

My client side code is:

import wixPay from ‘wix-pay’;
import {createPaymentForProduct} from ‘backend/sponsors_payments’;

export function repeater2_itemReady($item, itemData, index) {
let itemId = itemData._id;
$w(‘#pay’).onClick( async () => {
let payment = await createPaymentForProduct(itemId);
await wixPay.startPayment(payment.id);
});
}

@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.

@yisrael-wix THANK YOU!

@chajj Could you please schedule a call here - stunningfeedback.com :slight_smile: Make sure you are looking at the right timezone! Thanks so much & looking forward to it!