So, i know this type of error got questioned alot, but im unable to find the right solution for my problem.
Im totally new with corvid, with some progamming knowledge in other languages, but just superficial.
So what i am trying to achieve is to sell coupons for some services in the bookings app.
How my plan is: I have 1 product (a Coupon) in the Wix Shop app with different options, which will result in different prices (for different services in the bookings app later on). Someone buys his item in the store ( the coupon) and then my code should generate the coupon in wix and send it to him per mail.
So, thats the goal, that he can later give this code to someone as a present and this person can use it for the service.
Im far away from that, i just started looking into it but i ran into this error
“TypeError: Cannot read property ‘coupons’ of undefined”
My code is very short, i just copied the example to create a coupon from the api, it looks like this:
import wixMarketing from 'wix-marketing-backend';
export function createCoupon() {
//Add your code for this event here:
let couponData = {
"name": "My Coupon",
"code": "myCouponCode",
"startTime": new Date(),
"scope": {
"namespace": "bookings" // Coupon applies to all booking services
},
"moneyOffAmount": 49
};
return wixMarketing.coupons.createCoupon(couponData);
}
$w.onReady(function () {
//TODO: write your page related code here...
createCoupon();
});
I wrote this code into a test page, just to test if it generates the coupon “My Coupon” for 49€ if i load the page (i tested it with a button before), and i cant see where the error is, maybe someone of you could give me a tip?
This could wont do what i want it to do in the end, but i wanted the “generate a coupon” part to work before i try to send it per mail to the customer.
Thanks in advance!
Hauke