This commit is contained in:
@@ -333,8 +333,9 @@ export class CartComponent implements OnDestroy {
|
||||
this.closeTimeout = setTimeout(() => {
|
||||
this.autoSubmitPurchase();
|
||||
}, 5000);
|
||||
this.recordOrder();
|
||||
this.cartService.clearCart();
|
||||
|
||||
|
||||
|
||||
}
|
||||
// Continue checking for 3 minutes regardless of other statuses
|
||||
@@ -387,6 +388,36 @@ export class CartComponent implements OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the just-paid cart as a backoffice AdminOrder (POST /orders) so it shows up
|
||||
* in Backoffice → Orders/Transactions. Best-effort and fire-and-forget: a failure here
|
||||
* must never affect the already-confirmed payment or block autoSubmitPurchase.
|
||||
*/
|
||||
private recordOrder(): void {
|
||||
const email = this.userEmail().trim();
|
||||
const phone = this.userPhone().replace(/\D/g, '');
|
||||
|
||||
this.apiService.createOrder({
|
||||
items: this.paidItems.map((item: CartItem) => ({
|
||||
productId: String(item.itemID),
|
||||
name: item.name,
|
||||
quantity: item.quantity,
|
||||
price: item.discount > 0 ? item.price * (1 - item.discount / 100) : item.price,
|
||||
})),
|
||||
customer: {
|
||||
name: this.getTelegramUsername() || 'Guest',
|
||||
email,
|
||||
phone,
|
||||
},
|
||||
payment: {
|
||||
method: this.selectedPaymentMethod(),
|
||||
currency: 'RUB',
|
||||
},
|
||||
}).subscribe({
|
||||
error: (err) => console.error('Error recording order:', err),
|
||||
});
|
||||
}
|
||||
|
||||
private autoSubmitPurchase(): void {
|
||||
setTimeout(() => {
|
||||
const lang = this.langService.currentLanguage();
|
||||
|
||||
Reference in New Issue
Block a user