This has never worked for me.
This code creates the conditions necessary to reproduce the bugs described in my parent post.
import wixCrm from 'wix-crm';
import { getContact } from 'backend/quoteme';
import { createPriceQuote } from 'backend/quoteme';
$w.onReady(function () {
$w('#Submit').onClick(() => {
const now = new Date()
let dueDate = new Date("Nov 3, 2024")
let inputEmail = 'quoteymctest@gabe.wtf';
let inputFirstName = 'Quotey';
let inputLastName = 'McTest';
let inputWidgets = '42'
let CRMContact = {
"firstName": inputFirstName,
"lastName": inputLastName,
"emails": [inputEmail],
"labels": ["Quoted2021"],
};
wixCrm.createContact(CRMContact)
.then(contactId => {
let QuoteCustomer = {
"contactId": contactId,
"email": inputEmail,
"address": {
"city": '',
"subdivision": '',
"postalCode": '',
"country": '',
"addressLine": '',
"formatted": '',
},
"company": '',
"fullname": '',
"firstName": inputFirstName,
"lastName": inputLastName,
};
var discopercento
if (inputWidgets > 69) {
discopercento = 30
} else if (inputWidgets > 49 && inputWidgets < 70) {
discopercento = 20
} else if (inputWidgets > 29 && inputWidgets < 50) {
discopercento = 10
} else {
discopercento = 0
}
let lineItems = [{
"id": "00001",
"name": "Premium Widget",
"description": "Top Quality",
"price": 10.00,
"quantity": inputWidgets,
},
{
"id": "00002",
"name": "Free Operator License",
"description": "",
"price": 0.00001,
"quantity": 1,
},
{
"id": "00003",
"name": "Features",
"description": "• Hand Made • 100% Pure • Automatic Operation • Advanced Technology",
"price": 0.00001,
"quantity": 1,
},
{
"id": "00004",
"name": "Comprehensive training video",
"description": "",
"price": 0.00001,
"quantity": 1,
},
{
"id": "00005",
"name": "E-mail access to professional widget engineers",
"description": "",
"price": 0.00001,
"quantity": 1,
}
];
let discount = {
"value": discopercento,
"type": "Percentage"
};
let paymentTerms = {
"termData": "",
"termType": "Other"
};
let metadata = {
"notes": "Thank you for your interest in purchasing a 100% authentic hand made Acme Widget of premium organic quality, and advanced technical sophistication.",
"legalTerms": "",
"sourceUrl": "",
"source": "",
"sourceRefId": ""
};
let dates = {
"issueDate": now,
"validThroughDate": dueDate,
};
let createPriceQuoteFields = {
"title": "Acme Widget",
"customer": QuoteCustomer,
"currency": "USD",
"lineItems": lineItems,
"discount": discount,
"paymentTerms": paymentTerms,
"metadata": metadata,
"dates": dates
};
createPriceQuote(createPriceQuoteFields)
.then(id => {
console.log(id);
});
});
});
});
// Filename: backend/quoteme.jsw (web modules need to have a .jsw extension)
import wixCrmBackend from 'wix-crm-backend';
import wixBillingBackend from 'wix-billing-backend';
import { priceQuotes } from 'wix-billing-backend';
export function getContact(contactId) {
return wixCrmBackend.getContactById(contactId);
}
export function createPriceQuote(createPriceQuoteFields) {
return priceQuotes.createPriceQuote(createPriceQuoteFields);
}