| | |
| | | } |
| | | |
| | | try { |
| | | this.isActive = true; |
| | | this.payments = window.Square.payments( |
| | | this.config.application_id, |
| | | this.config.location_id |
| | |
| | | })); |
| | | |
| | | } catch (error) { |
| | | console.error('Failed to initialize Square payments:', error); |
| | | this.handleError(error); |
| | | this.isActive = false; |
| | | } |
| | | } |
| | | |
| | |
| | | throw new Error('Store is currently closed'); |
| | | } |
| | | |
| | | const response = await fetch(this.config.api_url + 'process-payment', { |
| | | const response = await window.auth.fetch(`${this.api}process-payment`, { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json', |
| | | 'X-WP-Nonce': this.config.nonce, |
| | | }, |
| | | body: JSON.stringify({ |
| | | source_id: sourceToken, |
| | |
| | | |
| | | async loadSavedCards() { |
| | | try { |
| | | const response = await fetch(this.config.api_url + 'saved-cards', { |
| | | method: 'GET', |
| | | headers: { 'X-WP-Nonce': this.config.nonce }, |
| | | const response = await window.auth.fetch(`${this.api}saved-cards`, { |
| | | method: 'POST', |
| | | }); |
| | | |
| | | const result = await response.json(); |