Question:
I have 2 input fields one is required the other is an optional entry. The site visitor must enter a value ( HOA dues) in the first field and optionally enter a value in the second field. I wrote a Velo code that adds the 2 values and the payment is initiated when both field are filled. However, when the second field is left blank (no amount entered). I get the following error:
" WixPayBackend.createPayment: can’t create payment, details:
Could not decode [“”] at [.items[1].price] as [BigDecimal]."
I have tried different things and did a lot of Googling but was unable to find a solution. Appreciate any insight into this issue.
Product:*
Wix Editor, Velo
What are you trying to achieve:
Ability to add the entered value of two fields even though the second field may be left blank (no value entered) or with a value entered.
(example 1: field1= $200, Field2= $100, Amount: $300)
(example 2: field1= $200, Field2= blank (no entry) , Amount: $200)
Example 2 throws out an error,
What have you already tried:
I have tried different things and did a lot of Googling but was unable to find a solution.
Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]
Thank you for the quick reply. I added russian-dima’s suggestion (parseFloat) but it still doe not work.
The two fields settings are “Text”, no verification and show initial text “none”.
here is my code:
// WIX Pay Dues (Client side) - Front end//
// Velo API Reference: Introduction - Velo API Reference - Wix.com //
import { createMyPayment } from ‘backend/dues-pay-backend’;
import wixPay from ‘wix-pay’;
$w.onReady(function () {
let payDuesAmount;
let lakeFundAmount;
let totalDue;
let totalAmount;
$w("#payDuesInput").onChange(() => {
payDuesAmount = $w("#payDuesInput").value;
console.log(payDuesAmount);
})
$w("#lakeFundInput").onChange(() => {
lakeFundAmount = $w("#lakeFundInput").value;
console.log(lakeFundAmount);
})
// Home owner does not enter a lake donation. Pays dues only//
if (lakeFundAmount === null || lakeFundAmount == 0) {
totalAmount = parseFloat(payDuesAmount) || 0;
console.log(totalAmount);
// Home owner only enters lake donation. No dues//
} else if (payDuesAmount === null || payDuesAmount == 0) {
totalAmount = parseFloat(lakeFundAmount) || 0;
console.log(totalAmount);
// Home owner enters both a lake donation and pays dues//
} else {
totalDue = payDuesAmount + lakeFundAmount;
totalAmount = parseFloat(totalDue) || 0;
console.log(totalAmount);
}
$w("#payNowButton").onClick(async () => {
const payment = await createMyPayment(totalAmount);
const result = await wixPay.startPayment(payment.id);
console.log(result);
})
});
//dues-pay-backend//
import wixPayBackend from ‘wix-pay-backend’;
export function createMyPayment(totalAmount) {
let items;
let amount;
Thank you Pratham. I went ahead and coded similarly as you suggested. However, the problem is that the createMyPayment module at the backend rejects any item that has a value of zero. I can do the addition in the frontend but then this becomes a single item (totalAmount) and therefore when the payment is submitted the pay dues and lake fund amount are not shown as separate items in the checkout confirmation email:
SUMMARY (using totalAmount)
Item Name Quantity Total
Pay Dues Price: $2.00 1 $2.00
What I need is:
SUMMARY
Item Name Quantity Total
Pay Dues: Price: $1.00 1 $1.00
Lake Fund: Price: $1.00 1 $1.00
Is there a way to pass variables from the frontend to the backend. (payDuesAmount and lakeFundAmount)?
Thank you so much Pratham. That did it. I added another condition as the home owner can also choose to only submit a lake donation.
I appreciate your assistance.