Files
InvoiceShelf/resources/scripts/customer/stores/payment.js
Darko Gjorgjijoski 691178857f Add HTTP client wrapper and upgrade Axios to v1 (#594)
* refactor: add HTTP client wrapper and upgrade axios to v1

Introduce a thin HTTP wrapper (resources/scripts/http) that centralizes
axios configuration, interceptors, and auth header injection. All 43
files now import from the wrapper instead of axios directly, making
future library swaps a single-file change. Upgrade axios from 0.30.0
to 1.14.0.

* fix: restore window.Ls assignment removed during axios refactor

company.js uses window.Ls.set() to persist selected company,
which broke after the axios plugin (that set window.Ls) was deleted.
2026-04-02 15:08:23 +02:00

76 lines
1.9 KiB
JavaScript
Vendored

import { handleError } from '@/scripts/customer/helpers/error-handling'
const { defineStore } = window.pinia
import http from '@/scripts/http'
export const usePaymentStore = defineStore({
id: 'customerPaymentStore',
state: () => ({
payments: [],
selectedViewPayment: [],
totalPayments: 0,
}),
actions: {
fetchPayments(params, slug) {
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${slug}/customer/payments`, { params })
.then((response) => {
this.payments = response.data.data
this.totalPayments = response.data.meta.paymentTotalCount
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
fetchViewPayment(params, slug) {
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${slug}/customer/payments/${params.id}`)
.then((response) => {
this.selectedViewPayment = response.data.data
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
searchPayment(params, slug) {
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${slug}/customer/payments`, { params })
.then((response) => {
this.payments = response.data
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
fetchPaymentModes(params, slug) {
return new Promise((resolve, reject) => {
http
.get(`/api/v1/${slug}/customer/payment-method`, { params })
.then((response) => {
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
},
})