Hi All,
I have been trying this code on this page for 2 days now:
https://www.wix.com/corvid/forum/community-discussion/custom-payment-amounts-with-pay-api
I have been modifying this example along with it:
https://support.wix.com/en/article/corvid-tutorial-using-the-corvid-pay-api-to-collect-payments-for-a-single-product
https://www.youtube.com/watch?v=YJuYl47tjxs
It doesn’t work when I modify the example. I am using Square as my payment portal. My client wants this by tomorrow morning EST. I even tried modifying the code to have a construct field. Here is my current code:
PAGE CODE
import wixPay from 'wix-pay';
import {createMyPayment} from 'backend/BE_PayAPI';
export function button1_click(event) {
createMyPayment($w('#input1').value,$w('#input2').value)
const invoicenumber = `${$w("#input1").value}`;
const customamount = `${$w("#input2").value}`
.then( (payment) => {
wixPay.startPayment(payment.id);
} );
}
BACKEND CODE
import wixPay from 'wix-pay-backend';
export function createMyPayment(invoicenumber,customamount){
let cPaymentString = { amount: customamount,
items:
[{name: invoicenumber, price: customamount}] };
return wixPay.createPayment(cPaymentString);
}
I am using an example site right now so details might not match branding.
My URL: https://andrew0657.wixsite.com/mysite-1
Any insight tonight would be beyond helpful!
Solved! Here is the new codes.
BACKEND CODE
//pay.jsw
import wixPay from 'wix-pay-backend';
export function createMyPayment(description,customamount){
let cPaymentString = { amount: customamount,
items:
[{name: description, price: customamount}] };
return wixPay.createPayment(cPaymentString);
}
PAGE CODE
import {createMyPayment} from 'backend/pay';
import wixPay from 'wix-pay';
export function button1_click(event) {
createMyPayment($w('#input1').value,$w('#input2').value)
.then( (payment) => {
wixPay.startPayment(payment.id);
} );
}
I think what wasn’t clear was that export function createMyPayment(description,customamount)
directly correlates to what is in the parentheses here:
createMyPayment($w(‘#input1’).value,$w(‘#input2’).value)
So Input 1 for me was the item name and input 2 is the value.
If you were to just name your item it would be:
createMyPayment(“ITEM NAME”,$w(‘#input2’).value)
Hope this helps anyone.
hey elizabeth! i’ve been looking at the same samples but i just can’t get it to work! i’ve scrapped what i had and copied your code and am still scratching my head. i have a page with two input boxes and a button. Everything is setup as far as accepting payments/published/etc but nonetheless, nothing happens when i click the button. could you give any insight? i use the wix stores for other products, do u think this may affect it’s ability to work? i look forward to your reply! thank you!
@deleteduser omg! doh! thank you so much! lol! works perfectly!
UPDATE For Custom Quantity
PAGE CODE
import {createMyPayment} from 'backend/pay';
import wixPay from 'wix-pay';
export function buynow_click(event) {
createMyPayment($w('#productname').text, $w('#qty').value, $w('#price').text,)
.then( (payment) => {
wixPay.startPayment(payment.id);
} );
}
BACKEND jsw
//pay.jsw
import wixPay from 'wix-pay-backend';
export function createMyPayment(description,value, customamount){
let cPaymentString = {
amount: customamount * value,
quantity: value,
items:
[{name: description, quantity:value, price: customamount, }] };
return wixPay.createPayment(cPaymentString);
}
Note that:
Name is a text field.
Quantity is an input field, but it could be a dropdown
Price is a text field that is a number
This is also attached to a database, but it doesn’t have to be.