Question:
I’m having trouble getting getPriceQuote() to return data. I’m getting “Unable to handle the request.” I’ll paste the code below.
Product:
Wix Editor
What are you trying to achieve:
I have saved the quote id and am trying to get the data related to that quote to display on a member page.
What have you already tried:
I used the velo api data to write my code.
Additional information:
This is my code in a backend .jsw file. createQuote() does what it’s supposed to. findQuote() does not. I have checked that I am definitely entering the method and can return test data but priceQuotes.getPriceQuote(quoteId.id) is causing the error msg "Unable to handle the request. "
import { priceQuotes } from 'wix-billing-backend';
import wixData from 'wix-data';
export async function createQuote(cartData, user, quoteData, subtotal) {
const now = new Date()
const dueDate = new Date()
dueDate.setDate(now.getDate() + 30)
let customer = {
"contactId": user.contactId,
"email": user.loginEmail,
"address": {
"city": quoteData.qCity,
"subdivision": quoteData.qShippingLine1,
"postalCode": quoteData.qZip,
"country": "USA",
"addressLine": quoteData.qShippingLine1
},
"billingAddress": {
"country": "USA",
"streetAddress": {
"value": user.contactDetails.addresses[0].addressLine,
"type": "Name"
},
"addressLine": user.contactDetails.addresses[0].addressLine,
"addressLine2": user.contactDetails.addresses[0].addressLine,
"postalCode": user.contactDetails.addresses[0].postalCode,
"subdivision": user.contactDetails.addresses[0].subdivision,
"city": user.contactDetails.addresses[0].city
},
"shippingAddress": {
"country": "USA",
"streetAddress": {
"value": quoteData.qShippingLine1,
"type": "Name"
},
"addressLine": quoteData.qShippingLine1,
"addressLine2": quoteData.qShippingLine2,
"postalCode": quoteData.qZip,
"subdivision": quoteData.qShippingLine1,
"city": quoteData.qCity
},
"phone": quoteData.qPhone,
"firstName": quoteData.qFirstName,
"lastName": quoteData.qLastName
};
let lineItems = [];
cartData.forEach(product => {
let description = "";
let options = product.options;
options.forEach(selectedOption => {
description = description + selectedOption.selection + " ";
});
let item = {
"id": product.productId,
"name": product.name,
"description": description,
"price": product.price,
"quantity": product.quantity
};
lineItems.push(item);
});
let discount = {
"value": 0,
"type": "Fixed"
};
let paymentTerms = {
"termData": "some term data",
"termType": "DueOnReceipt"
};
let dates = {
"issueDate": now,
"validThroughDate": dueDate
};
let metadata = {
"notes": quoteData.qNotes
};
try {
let createPriceQuoteFields = {
"title": quoteData.qLastName + " " + "Freight Quote",
"customer": customer,
"currency": "USD",
"lineItems": lineItems,
"discount": discount,
"paymentTerms": paymentTerms,
"dates": dates,
"metadata": metadata
};
const name = user.contactDetails.firstName + " " + user.contactDetails.lastName;
priceQuotes.createPriceQuote(createPriceQuoteFields)
.then((result) => {
let toInsert = {
"quoteId": result.id,
"email": user.loginEmail,
"title": name,
"subtotal": subtotal
};
wixData.insert("PendingCarts", toInsert)
.then(() => {
return true;
}).catch((err) => {
console.log("Error saving quote id in CMS: ", err);
return false;
});
})
} catch (error) {
console.log("Backend error creating quote: ", error)
}
}
export function findQuote(quoteId) {
return priceQuotes.getPriceQuote(quoteId.id);
}