| | |
| | | if (squareConfig.isOpen !== '1') { |
| | | return; |
| | | } |
| | | const response = await fetch(this.config.api_url + 'checkout', { |
| | | |
| | | // Square Web Payments SDK handles EVERYTHING |
| | | // We just need to track the order for status updates |
| | | const response = await fetch(this.config.api_url + 'save-order', { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | 'X-WP-Nonce': this.config.nonce |
| | | }, |
| | | body: JSON.stringify({ |
| | | source_id: token, |
| | | amount: orderData.total, |
| | | items: orderData.items, |
| | | order_id: token.orderId, // From Square SDK response |
| | | payment_id: token.paymentId, // From Square SDK response |
| | | customer: orderData.customer, |
| | | note: orderData.note, |
| | | currency: this.config.currency, |
| | | items: orderData.items, |
| | | action: 'jvb_integration_action', |
| | | service: 'square', |
| | | integration_action: 'process_order' |
| | | integration_action: 'save_order' |
| | | }) |
| | | }); |
| | | |
| | | const result = await response.json(); |
| | | |
| | | if (!response.ok) { |
| | | throw new Error(result.message || 'Payment failed'); |
| | | throw new Error(result.message || 'Failed to save order'); |
| | | } |
| | | |
| | | return result; |