¨4.0.1¨

This commit is contained in:
¨NW¨
2023-12-03 14:07:47 +00:00
parent c08b36d1b6
commit f35052522d
1112 changed files with 43019 additions and 24987 deletions

View File

@@ -1,11 +1,10 @@
/* eslint-disable */
import store from "../../store";
import Errors from "../../Errors";
import CartHelpersMixin from "../../mixins/CartHelpersMixin";
import ProductHelpersMixin from "../../mixins/ProductHelpersMixin";
import CartItemHelpersMixin from "../../mixins/CartItemHelpersMixin";
export default {
mixins: [CartHelpersMixin, ProductHelpersMixin],
mixins: [CartHelpersMixin, CartItemHelpersMixin],
props: [
"customerEmail",
@@ -78,17 +77,13 @@ export default {
return this.gateways[this.form.payment_method].instructions;
}
},
hasFreeShipping() {
return this.cart.coupon?.free_shipping ?? false;
},
},
watch: {
"form.billingAddressId": function () {
this.mergeSavedBillingAddress();
},
"form.shippingAddressId": function () {
this.mergeSavedShippingAddress();
},
"form.billing.city": function (newCity) {
if (newCity) {
this.addTaxes();
@@ -156,6 +151,9 @@ export default {
if (this.defaultAddress.address_id) {
this.form.billingAddressId = this.defaultAddress.address_id;
this.form.shippingAddressId = this.defaultAddress.address_id;
this.mergeSavedBillingAddress();
this.mergeSavedShippingAddress();
}
if (!this.hasAddress) {
@@ -181,6 +179,14 @@ export default {
},
methods: {
changeBillingAddress(address) {
if (this.form.billingAddressId === address.id) return;
this.form.billingAddressId = address.id;
this.mergeSavedBillingAddress();
},
addNewBillingAddress() {
this.resetAddressErrors("billing");
@@ -192,6 +198,14 @@ export default {
}
},
changeShippingAddress(address) {
if (this.form.shippingAddressId === address.id) return;
this.form.shippingAddressId = address.id;
this.mergeSavedShippingAddress();
},
addNewShippingAddress() {
this.resetAddressErrors("shipping");
@@ -257,8 +271,8 @@ export default {
return;
}
this.fetchStates(country, (states) => {
this.$set(this.states, "billing", states);
this.fetchStates(country, (response) => {
this.$set(this.states, "billing", response.data);
this.$set(this.form.billing, "state", "");
});
},
@@ -273,17 +287,16 @@ export default {
return;
}
this.fetchStates(country, (states) => {
this.$set(this.states, "shipping", states);
this.fetchStates(country, (response) => {
this.$set(this.states, "shipping", response.data);
this.$set(this.form.shipping, "state", "");
});
},
fetchStates(country, callback) {
$.ajax({
method: "GET",
url: route("countries.states.index", { code: country }),
}).then(callback);
axios
.get(route("countries.states.index", { code: country }))
.then(callback);
},
changeBillingState(state) {
@@ -302,21 +315,74 @@ export default {
this.$set(this.form, "shipping_method", shippingMethodName);
},
addTaxes() {
async addTaxes() {
this.loadingOrderSummary = true;
$.ajax({
method: "POST",
url: route("cart.taxes.store"),
data: this.form,
})
.then((cart) => {
store.updateCart(cart);
try {
const response = await axios.post(
route("cart.taxes.store", {
...(store.hasCoupon() && {
coupon_code: store.getCoupon(),
}),
}),
this.form
);
store.updateCart(response.data);
} catch (error) {
this.$notify(error.response.data.message);
} finally {
this.loadingOrderSummary = false;
}
},
updateCart(cartItem, qty) {
this.loadingOrderSummary = true;
axios
.put(
route("cart.items.update", {
cartItemId: cartItem.id,
...(store.hasCoupon() && {
coupon_code: store.getCoupon(),
}),
}),
{
qty: qty || 1,
}
)
.then((response) => {
store.updateCart(response.data);
})
.catch((xhr) => {
this.$notify(xhr.responseJSON.message);
.catch((error) => {
this.$notify(error.response.data.message);
})
.always(() => {
.finally(() => {
this.loadingOrderSummary = false;
});
},
removeCartItem(cartItem) {
this.loadingOrderSummary = true;
store.removeCartItem(cartItem);
axios
.delete(
route("cart.items.destroy", {
cartItemId: cartItem.id,
...(store.hasCoupon() && {
coupon_code: store.getCoupon(),
}),
})
)
.then((response) => {
store.updateCart(response.data);
})
.catch((error) => {
this.$notify(error.response.data.message);
})
.finally(() => {
this.loadingOrderSummary = false;
});
},
@@ -328,68 +394,72 @@ export default {
this.placingOrder = true;
$.ajax({
method: "POST",
url: route("checkout.create"),
data: {
...this.form,
ship_to_a_different_address:
+this.form.ship_to_a_different_address,
},
})
.then((response) => {
if (response.redirectUrl) {
window.location.href = response.redirectUrl;
axios
.post(
route("checkout.store", {
...(store.hasCoupon() && {
coupon_code: store.getCoupon(),
}),
}),
{
...this.form,
ship_to_a_different_address:
+this.form.ship_to_a_different_address,
}
)
.then(({ data }) => {
if (data.redirectUrl) {
window.location.href = data.redirectUrl;
} else if (this.form.payment_method === "stripe") {
this.confirmStripePayment(response);
this.confirmStripePayment(data);
} else if (this.form.payment_method === "paytm") {
this.confirmPaytmPayment(response);
this.confirmPaytmPayment(data);
} else if (this.form.payment_method === "razorpay") {
this.confirmRazorpayPayment(response);
this.confirmRazorpayPayment(data);
} else if (this.form.payment_method === "paystack") {
this.confirmPaystackPayment(response);
this.confirmPaystackPayment(data);
} else if (this.form.payment_method === "authorizenet") {
this.confirmAuthorizeNetPayment(response);
this.confirmAuthorizeNetPayment(data);
} else if (this.form.payment_method === "flutterwave") {
this.confirmFlutterWavePayment(response);
this.confirmFlutterWavePayment(data);
} else if (this.form.payment_method === "mercadopago") {
this.confirmMercadoPagoPayment(response);
this.confirmMercadoPagoPayment(data);
} else {
this.confirmOrder(
response.orderId,
data.orderId,
this.form.payment_method
);
}
})
.catch((xhr) => {
if (xhr.status === 422) {
this.errors.record(xhr.responseJSON.errors);
.catch(({ response }) => {
if (response.status === 422) {
this.errors.record(response.data.errors);
}
this.$notify(xhr.responseJSON.message);
this.$notify(response.data.message);
this.placingOrder = false;
});
},
confirmOrder(orderId, paymentMethod, params = {}) {
$.ajax({
method: "GET",
url: route("checkout.complete.store", {
orderId,
paymentMethod,
...params,
}),
})
axios
.get(
route("checkout.complete.store", {
orderId,
paymentMethod,
...params,
})
)
.then(() => {
window.location.href = route("checkout.complete.show");
})
.catch((xhr) => {
.catch((error) => {
this.placingOrder = false;
this.loadingOrderSummary = false;
this.deleteOrder(orderId);
this.$notify(xhr.responseJSON.message);
this.$notify(error.response.data.message);
});
},
@@ -398,12 +468,11 @@ export default {
return;
}
$.ajax({
method: "GET",
url: route("checkout.payment_canceled.store", { orderId }),
}).then((xhr) => {
this.$notify(xhr.message);
});
axios
.get(route("checkout.payment_canceled.store", { orderId }))
.then((response) => {
this.$notify(response.data.message);
});
},
renderPayPalButton() {
@@ -414,31 +483,36 @@ export default {
.Buttons({
async createOrder() {
try {
response = await $.ajax({
method: "POST",
url: route("checkout.create"),
data: vm.form,
});
response = await axios.post(
route("checkout.create"),
vm.form
);
return response.resourceId;
} catch (xhr) {
if (xhr.status === 422) {
vm.errors.record(xhr.responseJSON.errors);
} else {
vm.$notify(xhr.responseJSON.message);
return response.data.resourceId;
} catch ({ response }) {
if (response.status === 422) {
vm.errors.record(response.data.errors);
return;
}
vm.$notify(response.data.message);
}
},
onApprove() {
vm.loadingOrderSummary = true;
vm.confirmOrder(response.orderId, "paypal", response);
vm.confirmOrder(
response.data.orderId,
"paypal",
response.data
);
},
onError() {
vm.deleteOrder(response.orderId);
vm.deleteOrder(response.data.orderId);
},
onCancel() {
vm.deleteOrder(response.orderId);
vm.deleteOrder(response.data.orderId);
},
})
.render("#paypal-button-container");
@@ -593,8 +667,8 @@ export default {
}).openIframe();
},
confirmAuthorizeNetPayment(authorizeNetOrder) {
this.authorizeNetToken = authorizeNetOrder.token;
confirmAuthorizeNetPayment({ token }) {
this.authorizeNetToken = token;
this.$nextTick(() => {
this.$refs.authorizeNetForm.submit();
@@ -643,7 +717,7 @@ export default {
confirmMercadoPagoPayment(mercadoPagoOrder) {
this.placingOrder = false;
const supportedLocales = {
const SUPPORTED_LOCALES = {
en_US: "en-US",
es_AR: "es-AR",
es_CL: "es-CL",
@@ -657,7 +731,8 @@ export default {
const mercadoPago = new MercadoPago(mercadoPagoOrder.publicKey, {
locale:
supportedLocales[mercadoPagoOrder.currentLocale] || "en-US",
SUPPORTED_LOCALES[mercadoPagoOrder.currentLocale] ||
"en-US",
});
mercadoPago.checkout({