I am looking to set a payment amount based on what date it is.
code is:
import wixPay from 'wix-pay-backend';
export function createPaymentForProduct() {
return wixPay.createPayment({
amount: 200.00,
items: [{ name: 'January', price: 200.00 }],
} );
}
I want my code to set variables based on the date to set both amount and price for a three month program…like this:
if date() >1/1/2022 then AMOUNT & PRICE = 200
if date() >2/1/2022 then AMOUNT & PRICE = 150
if date() >3/1/2022 then AMOUNT & PRICE = 100
Sorry but I’m new to velo and I just need the proper syntax.
I would google working with dates in Javascript to learn more but here is something that can get you started thinking about it.
Working with dates in Javascript can be complicated so definitely read up on it.
let dateToCheck = new Date('2022-01-01')
const dateToday = new Date();
if(dateToday > dateToCheck){
console.log("today is after 1/1/2022")
}
This works: *********************************************************
import wixPay from ‘wix-pay-backend’;
export function createPaymentForProduct() {
return wixPay.createPayment({
amount: 60.00,
items: [{ name: ‘Test Purchase’, price: 60.00 }],
} );
}
I’d like this to work but need some syntax help: ********************
import wixPay from ‘wix-pay-backend’;
export function createPaymentForProduct() {
if new Date() >1/1/2022 then VarAmt = 200.00;
if new Date() >2/1/2022 then VarAmt = 150.00;
if new Date() >3/1/2022 then VarAmt = 100.00;
if new Date() >4/1/2022 then VarAmt = 50.00;
return wixPay.createPayment({
amount: VarAmt,
items: [{ name: 'Test Purchase', price: VarAmt}],
} );
}
Any thoughts?