I’m trying to get this integration working with PayPal. The Wix Web API has a function that is supposed to fire when a payment status update fires. When I run with the debugger on in the web browser, I don’t see the javascript enter the event code. NOTE this is my first try at javascript, I have done programming in other languanges for years. Here is the “event code” from the Wix backend
import {post_cryptlex} from ‘router’;
import {genPassword} from “genPassword”;
import {createUser, createLicense, renewLicense} from ‘CryptlexApi’;
export function wixPay_onPaymentUpdate(event) {
this.headers = {
‘Content-Type’: ‘application/json’,
‘Authorization’: ‘payments2_api1.wix.com’
};
if (event.status === "Successful") {
createUser('license', event);
createLicense('renew-license', event);
if(event.payment.items.name === "license") {
const productId = 'PASTE_YOUR_PRODUCT_ID';
// get post params from request data
const { first_name, last_name, order_id, country, phone, email } = event.userInfo;
// create license user
const userBody = {
email: email,
firstName: first_name,
lastName: last_name,
password: genPassword(12),
role: 'user'
};
const user = createUser(userBody);
// create license
const licenseBody = {
productId: productId,
userId: user.id,
metadata: []
};
licenseBody.metadata.push({ key: 'order_id', value: event.transactionId, visible: false });
const license = createLicense(licenseBody);
console.log("license created successfully!")
// return license key to payment processor
return license.key;
}
else if (event.payment.items.name === 'renew-license') {
const productId = 'PASTE_YOUR_PRODUCT_ID';
// get post params from request body
const { order_id } = event.data.order_id;
// renew license expiry
const license = renewLicense(productId, 'order_id', event.transactionId);
// return new expiry date
return { message: `License new expiry date: ${license.expiresAt}` }
}
else {
console.log("Event requested was: ", event.payment.items.name)
}
}
else {
console.log("Payment update event result was: ", event.status)
}
}