File: D:/HostingSpaces/SBogers10/shop.komma.nl/resources/js/services/checkoutService.js
import { axios } from '../../../vendor/komma/kms/resources/js/global/axiosBootstrapper';
/**
* The checkout service knows how to do api calls and handle the responses from the api.
* All related to the checkout process. It does not do anything with the DOM.
*/
class CheckoutService {
constructor() {
this._baseRoute = '/checkout/';
}
/**
* Adds a product to the shopping cart
*
* @param id
* @param street
* @param house_number
* @param postal_code
* @param city
* @param telephone
* @param country_iso3
* @return {Promise}
*/
setShippingAddress(id, street, house_number, postal_code, city, telephone, country_iso3) {
return axios.post(
this._baseRoute+'set_shipping_address',
{
'shipping_id' : id,
'shipping_street' : street,
'shipping_house_number' : house_number,
'shipping_postal_code' : postal_code,
'shipping_city' : city,
'shipping_telephone' : telephone,
'shipping_country' : country_iso3,
}
);
};
/**
* Adds a product to the shopping cart
*
* @param id
* @param street
* @param house_number
* @param postal_code
* @param city
* @param telephone
* @param country_iso3
* @return {Promise}
*/
setInvoiceAddress(id, street, house_number, postal_code, city, telephone, country_iso3) {
return axios.post(
this._baseRoute+'set_invoice_address',
{
'invoice_id' : id,
'invoice_street' : street,
'invoice_house_number' : house_number,
'invoice_postal_code' : postal_code,
'invoice_city' : city,
'invoice_telephone' : telephone,
'invoice_country' : country_iso3,
}
);
};
getCheckoutInformation() {
return axios.get(this._baseRoute+'information');
}
getCheckoutUser() {
return axios.get(this._baseRoute+'user')
}
/**
* Marks the given address as the invoice address for next orders if the user is logged in
*
* @param address
* @return {Promise<AxiosResponse<any>>}
*/
markAsInvoiceAddressForCheckout(address) {
return axios.patch('/checkout/address/mark/as_invoice_address/' + address.id);
}
/**
* Marks the given address as the invoice address for next orders if the user is logged in
*
* @param address
* @return {Promise<AxiosResponse<any>>}
*/
markAsShippingAddress(address) {
return axios.patch('/checkout/address/mark/as_shipping_address/' + address.id);
}
}
export { CheckoutService }