Looking at your previous post for this, so I could get the backend files info.
https://www.wix.com/corvid/forum/community-discussion/coupon-code-help
Instead of having to simply use the backend files from the tutorial used.
https://www.wix.com/corvid/forum/community-discussion/coupon-code-help
Try this code below.
EK_payAPI.jsw code
import wixPay from 'wix-pay-backend';
export function createPaymentForProduct1() {
return wixPay.createPayment( {
amount: 120,
items: [{name: 'Portrait With Frame', price: 120}],
} );
}
EKdiscount_payAPI.jsw code
import wixPay from 'wix-pay-backend';
export function createPaymentForProduct2() {
return wixPay.createPayment({
amount: 60,
items: [{ name: 'Portrait With Frame', price: 60 }],
});
}
Page Code
import wixPay from 'wix-pay';
import {createPaymentForProduct1} from 'backend/EK_PayAPI';
import {createPaymentForProduct2} from 'backend/EKdiscount_PayAPI';
let couponCode = 'FCES1ST';
$w.onReady(function () {
});
export function button1_click(event) {
if ($w('#input7').value === couponCode) {
createPaymentForProduct2().then(payment => {
wixPay.startPayment(payment.id, { "termsAndConditionsLink": "https://ek4art.wixsite.com/ekart/terms-and-conditions" });
});
}
if ($w('#input7').value === "") {
createPaymentForProduct1().then(payment => {
wixPay.startPayment(payment.id, { "termsAndConditionsLink": "https://ek4art.wixsite.com/ekart/terms-and-conditions" });
});
}
}
Please note that I have made two small changes in the spellings for portrait and discount in the backend jsw files.
Also note that this was just done on a free test site and no payment providers could be connected to test if it all fully works, however there are no errors.
You will have to test it on your end to see if it fully works with your payment already setup etc.
Finally, just checking, do you have the coupon code setup in the coupon section in the Wix Dashboard, as if you did and you used the coupon code input in the checkout, then you would not need the second payment option as the coupon would deduct it automatically for you.