I have created a custom payment form and for some reason it is throwing an error and not saving when my client in Israel fills it out, however when I fill it out it works fine. Could be a server error or something else I really do not know.
Can you post your code so I can take a look?
Yes sorry, it is a bit of frontend and backend
You can also try filling out the form here - https://www.israeletc.com/register
Frontend -
import {createMyPayment} from "backend/payment"
import wixPay from 'wix-pay';
import { session } from 'wix-storage';
import wixLocation from 'wix-location';
$w.onReady(function () {
$w("#dataset1").onAfterSave(()=> {
$w("#loader").show()
createMyPayment(parseInt($w("#numberOfAttendies").value))
.then((payment)=> {
wixPay.startPayment(payment.id).then(()=> {
$w("#loader").hide()
wixLocation.to("/thank-you")
})
})
})
let option = session.getItem('Option')
console.log(option)
$w("#dropdown1").value = option
$w("#numberOfAttendies").onChange(()=> {
let value = $w("#numberOfAttendies").value
//
if (value === "1") {
$w("#person1").collapse()
$w("#person2").collapse()
$w("#person3").collapse()
$w("#person4").collapse()
$w("#person5").collapse()
$w("#person6").collapse()
$w("#person7").collapse()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "2") {
$w("#person1").expand()
$w("#person2").collapse()
$w("#person3").collapse()
$w("#person4").collapse()
$w("#person5").collapse()
$w("#person6").collapse()
$w("#person7").collapse()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "3") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").collapse()
$w("#person4").collapse()
$w("#person5").collapse()
$w("#person6").collapse()
$w("#person7").collapse()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "4") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").expand()
$w("#person4").collapse()
$w("#person5").collapse()
$w("#person6").collapse()
$w("#person7").collapse()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "5") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").expand()
$w("#person4").expand()
$w("#person5").collapse()
$w("#person6").collapse()
$w("#person7").collapse()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "6") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").expand()
$w("#person4").expand()
$w("#person5").expand()
$w("#person6").collapse()
$w("#person7").collapse()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "7") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").expand()
$w("#person4").expand()
$w("#person5").expand()
$w("#person6").expand()
$w("#person7").collapse()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "8") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").expand()
$w("#person4").expand()
$w("#person5").expand()
$w("#person6").expand()
$w("#person7").expand()
$w("#person8").collapse()
$w("#person9").collapse()
}
if (value === "9") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").expand()
$w("#person4").expand()
$w("#person5").expand()
$w("#person6").expand()
$w("#person7").expand()
$w("#person8").expand()
$w("#person9").collapse()
}
if (value === "10") {
$w("#person1").expand()
$w("#person2").expand()
$w("#person3").expand()
$w("#person4").expand()
$w("#person5").expand()
$w("#person6").expand()
$w("#person7").expand()
$w("#person8").expand()
$w("#person9").expand()
}
})
});
Backend -
import wixPay from 'wix-pay-backend';
export function createMyPayment(quantity) {
let cPaymentString = {
amount: 100 * quantity,
quantity: quantity,
items: [{
name: "registration",
quantity: quantity,
price: 100
}]
}
return wixPay.createPayment(cPaymentString)
}
I tried here and the form seemed to work fine. I see no error on your code on the Wix Pay side.
Is the problem on the Form itself? Where is the Form code?
See that is what I keep saying to the client, I cannot recreate the issue and was just wondering if there were any known issues. The form is actually just connect right to a dataset on the page so I just utilized the $w(“#dataset1”).save function.
Perhaps this is a network or system issue. Bugs and system issues should be reported to Wix Customer Care .
@jarod I had nightmares with this expand/collapse code, so I had to refactor it.
See if this helps you:
//This is the list of elements you need to expand/collapse
const personList = [
"#person1",
"#person2",
"#person3",
"#person4",
"#person5",
"#person6",
"#person7",
"#person8",
"#person9",
]
$w.onReady(() => {
$w("#numberOfAttendies").onChange(({ target }) => {
//This is an error check, cause there is no #person0 or #person-1
if (target.value >= 1) {
let expandAttendies = expand(target.value)
$w(`${expandAttendies}`).expand()
//This is just an error check to stop collapsing items that don't exist.
if (target.value <= personList.length - 1) {
let collapseAttendies = collapse(expandAttendies)
$w(`${collapseAttendies}`).collapse()
}
}
})
})
//This function expands the elements based on the value of the input
function expand(value) {
let elements = []
for (let index = 0; index < value; index++) {
elements.push(personList[index])
}
return elements.toString()
}
//This function collapse the elements based on the expanded elements
function collapse(expandedArray) {
let collapsedArray = personList.filter(item => !expandedArray.includes(item))
return collapsedArray.toString()
}
@bwprado
Are the curly brakets neccessary here…?
$w("#numberOfAttendies").onChange(({target})=>{......
@russian-dima I guess, cause it is a destructuring of the event object. Otherwise the value property is not accessible.