Sir pls can you help me correct this code. I am new to Velo and I have been able to gather all these codes online using my little html and php knowledge to understand it. All I want the code to do is get the image and add it to quotesummary array. Also i want the pay button to force user to upload an image before showing the checkout page. When I tested the code it doesn’t force me to upload it just skip upload and move to checkout. Also, the image to display just show object instead of image url or preview. Thanks in advance
import { createMyPayment } from ‘backend/payment’ ;
import wixPay from ‘wix-pay’ ;
import wixData from ‘wix-data’ ;
$w . onReady ( function () {
let uploader_UploadFile_Arr = [];
uploader_UploadFile_Arr [ 0 ] = 1 ;
quoteSummary_Arr [ 0 ] = “
Order Summary” ;
let price ;
//UPLOADED IMAGES
$w ( “#uploader” ). onChange (() => {
calculator ();
uploader_UploadFile_Arr [ 0 ] = $w ( “#uploader” ). value ;
if ( $w ( “#uploader” ). value . length > 0 ) {
quoteSummary_Arr [ 5 ] = 🧾Image Uploaded: ${ uploader_UploadFile_Arr [ 0 ]}
;
calculator ();
} else {
quoteSummary_Arr . splice ( 5 , 1 );
calculator ();
}
});
//GENERAL CALCULATOR FUNCTION📌
const calculator = function () {
//CALCULATOR
price = ( Number ( lpages_Num_Arr [ 0 ]) * Number ( wpages_Num_Arr [ 0 ]) * Number ( measurement_price_Arr . reduce (( a , b ) => a + b , 0 )) * Number ( qtypages_Num_Arr [ 0 ])). toFixed ( 2 );
$w ( “#totalPriceText” ). text = £ ${ Number ( price ). toLocaleString ( 'en-US' )}
;
$w ( ‘#totalPriceText’ ). text = £ ${ parseFloat ( price ). toFixed ( 2 )}
;
//SUMMARY TEXTS📖
$w ( “#quoteSummaryText” ). text = quoteSummary_Arr . join ( " " );
}
//WIX PAY API💳
$w ( “#paymentButton” ). onClick (() => {
if ( $w ( “#uploader” ). value . length > 0 )
{
$w ( ‘#uploader’ ). startUpload ()
. then (( UploadFile )=>{
let imgurl = UploadFile . url ;
let toInsert ={
“image” : imgurl
};
wixData . insert ( “SingleTransferUploads” , toInsert )
. then (( results )=>{
$w ( ‘#msg’ ). text = “Image Submitted Successfully” ;
$w ( ‘#msg’ ). expand ();
})
. catch (( err )=>{
$w ( ‘#msg’ ). text = err ,
$w ( ‘#msg’ ). expand ();
})
})
} else {
$w ( ‘#msg’ ). text = “Please choose an image” ;
$w ( ‘#msg’ ). expand ();
}
createMyPayment ( quoteSummary_Arr . join ( " " ), price )
. then (( payment ) => {
wixPay . startPayment ( payment . id ). then (( result ) => {
});
});
});
});