try {
console.log('API URL :', `${env.STRAPI_API_URL}/c-orders`);
const connection = await fetch(`${env.STRAPI_API_URL}/c-orders`, {
headers: {
Authorization: `Bearer ${env.STRAPI_API_KEY}`,
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
data: {
planId,
date: new Date(),
deliveryDate: new Date(deliveryDate * 1000),
status: 1,
details,
grossPrice: totalPrice,
finalPrice: totalPrice,
subscriptionId: subscription ? strapiSubscriptionId : null,
userId,
paymentId: paymentIntent,
paymentStatus: subscription ? 'processing' : 'success',
orderInfo: [],
stripeInvoiceId: invoice,
},
}),
});
console.log('connection :', connection);
const data = await connection.json();
console.log('data :', JSON.stringify(data, null, 2));
if (connection.status !== 200) wasOrderCreated = false;
wasOrderCreated = true;
} catch (err) {
console.log('err :', err);
return false;
}
try {
console.log('API URL :', `${env.STRAPI_API_URL}/c-orders`);
const connection = await fetch(`${env.STRAPI_API_URL}/c-orders`, {
headers: {
Authorization: `Bearer ${env.STRAPI_API_KEY}`,
'Content-Type': 'application/json',
},
method: 'POST',
body: JSON.stringify({
data: {
planId,
date: new Date(),
deliveryDate: new Date(deliveryDate * 1000),
status: 1,
details,
grossPrice: totalPrice,
finalPrice: totalPrice,
subscriptionId: subscription ? strapiSubscriptionId : null,
userId,
paymentId: paymentIntent,
paymentStatus: subscription ? 'processing' : 'success',
orderInfo: [],
stripeInvoiceId: invoice,
},
}),
});
console.log('connection :', connection);
const data = await connection.json();
console.log('data :', JSON.stringify(data, null, 2));
if (connection.status !== 200) wasOrderCreated = false;
wasOrderCreated = true;
} catch (err) {
console.log('err :', err);
return false;
}