Cash
- Credit Card
+ Tiger Card Machine
+ Authorize.net PCI Card API
Credit Card & Cash
Check
Other
@@ -513,7 +557,7 @@ export default defineComponent({
.then((response: any) => {
this.pricing = response.data;
})
- .catch(() => {
+ .catch((error: any) => {
notify({
title: "Error",
text: "Could not get oil pricing",
@@ -522,26 +566,22 @@ export default defineComponent({
});
},
getCustomer(user_id: any) {
- return new Promise((resolve, reject) => {
- let path = import.meta.env.VITE_BASE_URL + "/customer/" + user_id;
- axios({
- method: "get",
- url: path,
- withCredentials: true,
+ let path = import.meta.env.VITE_BASE_URL + "/customer/" + user_id;
+ axios({
+ method: "get",
+ url: path,
+ withCredentials: true,
+ })
+ .then((response: any) => {
+ this.customer = response.data;
})
- .then((response: any) => {
- this.customer = response.data;
- resolve(response.data);
- })
.catch((error: any) => {
notify({
title: "Error",
text: "Could not find customer",
type: "error",
});
- reject(error);
});
- });
},
getPaymentCard(card_id: any) {
@@ -572,26 +612,25 @@ export default defineComponent({
}
},
- async getOilOrder(delivery_id: any) {
+ getOilOrder(delivery_id: any) {
if (!delivery_id) { // Add a guard to prevent calls with an undefined ID
console.error("getOilOrder called with no ID.");
return;
}
let path = import.meta.env.VITE_BASE_URL + "/delivery/" + delivery_id;
- try {
- const response = await axios({
- method: "get",
- url: path,
- withCredentials: true,
- headers: authHeader(),
- });
-
+ axios({
+ method: "get",
+ url: path,
+ withCredentials: true,
+ headers: authHeader(),
+ })
+ .then((response: any) => {
// FIX: Check for the 'ok' flag and access the nested 'delivery' object
if (response.data && response.data.ok) {
this.deliveryOrder = response.data.delivery; // <-- THIS IS THE CRITICAL CHANGE
// Now that this.deliveryOrder is the correct object, the rest of the logic will work.
- await this.getCustomer(this.deliveryOrder.customer_id);
+ this.getCustomer(this.deliveryOrder.customer_id);
if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) {
this.getPaymentCard(this.deliveryOrder.payment_card_id);
@@ -600,16 +639,19 @@ export default defineComponent({
this.getPromo(this.deliveryOrder.promo_id);
}
- // Now that customer is loaded, we can fetch transactions directly
- this.getTransaction(delivery_id);
+ // Only fetch transactions for Authorize.net payments
+ if (this.deliveryOrder.payment_type == 11) {
+ this.getTransaction(delivery_id);
+ }
} else {
- console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
- notify({ title: "Error", text: "Could not load delivery details.", type: "error" });
+ console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
+ notify({ title: "Error", text: "Could not load delivery details.", type: "error" });
}
- } catch (error) {
+ })
+ .catch((error: any) => {
console.error("Error fetching delivery order:", error);
- }
+ });
},
getOilOrderMoney(delivery_id: any) {
let path = import.meta.env.VITE_MONEY_URL + "/delivery/order/money/" + delivery_id;
@@ -637,9 +679,9 @@ export default defineComponent({
this.priceprime = response.data.priceprime || 0;
this.pricesameday = response.data.pricesameday || 0;
this.priceemergency = response.data.priceemergency || 0;
- this.total_amount = response.data.total_amount || 0;
- this.discount = response.data.discount || 0;
- this.total_amount_after_discount = response.data.total_amount_after_discount || 0;
+ this.total_amount = parseFloat(response.data.total_amount) || 0;
+ this.discount = parseFloat(response.data.discount) || 0;
+ this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0;
} else {
// Fallback calculation if API doesn't return expected data
this.calculateFallbackTotal();
@@ -690,9 +732,12 @@ export default defineComponent({
})
.then((response: any) => {
if (response.data) {
- this.promo = response.data
+ this.promo = response.data;
}
})
+ .catch((error: any) => {
+ console.error('Error fetching promo:', error);
+ })
},
calculateDeliveryTotal() {
@@ -716,59 +761,46 @@ export default defineComponent({
return total.toFixed(2);
},
+ calculateEstimatedTotal() {
+ if (!this.deliveryOrder.gallons_ordered || !this.pricing.price_for_customer) {
+ return 0;
+ }
+
+ const gallons = Number(this.deliveryOrder.gallons_ordered);
+ const pricePerGallon = Number(this.pricing.price_for_customer);
+ let total = gallons * pricePerGallon;
+
+ if (this.deliveryOrder.prime == 1) {
+ total += Number(this.pricing.price_prime) || 0;
+ }
+ if (this.deliveryOrder.same_day == 1) {
+ total += Number(this.pricing.price_same_day) || 0;
+ }
+ if (this.deliveryOrder.emergency == 1) {
+ total += Number(this.pricing.price_emergency) || 0;
+ }
+
+ return total;
+ },
getTransaction(delivery_id: any) {
- // Fix: Use customer transaction endpoint to get transactions for this delivery's customer
- // The API seems to work with customer-centric endpoints
- if (this.customer && this.customer.id) {
- const path = `${import.meta.env.VITE_BASE_URL}/payment/transactions/customer/${this.customer.id}/1`;
- axios.get(path, { withCredentials: true, headers: authHeader() })
- .then((response: any) => {
- console.log("Transaction API response:", response.data); // Debug log to see actual response structure
- // Handle both single transaction object and array responses
- if (response.data && Array.isArray(response.data) && response.data.length > 0) {
- // Find the transaction for this specific delivery
- const deliveryTransaction = response.data.find((txn: any) =>
- txn.delivery_id === parseInt(delivery_id) ||
- txn.transaction_id === delivery_id ||
- txn.delivery_number === delivery_id
- );
- this.transaction = deliveryTransaction || null;
- } else if (response.data && !Array.isArray(response.data)) {
- // If single transaction, check if it's for this delivery
- const txn = response.data;
- if (txn.delivery_id === parseInt(delivery_id) ||
- txn.transaction_id === delivery_id ||
- txn.delivery_number === delivery_id) {
- this.transaction = txn;
- } else {
- this.transaction = null;
- }
- } else {
- this.transaction = null;
- }
-
- if (!this.transaction) {
- console.log(`No transaction found for delivery ${delivery_id} among customer transactions`);
- }
- })
- .catch((error: any) => {
- // Handle various error responses gracefully
- if (error.response && error.response.status === 404) {
- console.log(`No transactions found for customer ${this.customer.id}`);
- this.transaction = null;
- } else if (error.response && error.response.status === 400) {
- console.log(`Bad request for customer transactions: ${error.response.data?.detail || error.message}`);
- this.transaction = null;
- } else {
- console.error("Error fetching transaction:", error);
- this.transaction = null;
- }
- });
- } else {
- console.log("Customer data not available, cannot fetch transactions");
+ // Simple endpoint to get transaction directly by delivery_id
+ const path = `${import.meta.env.VITE_BASE_URL}/payment/transaction/delivery/${delivery_id}`;
+ axios.get(path, {
+ withCredentials: true,
+ headers: authHeader()
+ }).then((response: any) => {
+ if (response.data.ok) {
+ this.transaction = response.data.transaction;
+ console.log("Transaction loaded:", this.transaction);
+ } else {
+ console.log("No transaction found for delivery:", delivery_id);
+ this.transaction = null;
+ }
+ }).catch((error: any) => {
+ console.error("Error fetching transaction:", error);
this.transaction = null;
- }
+ });
},
},
})
diff --git a/src/pages/pay/oil/authorize_preauthcharge.vue b/src/pages/pay/oil/authorize_preauthcharge.vue
index e947f23..0c6b0a4 100644
--- a/src/pages/pay/oil/authorize_preauthcharge.vue
+++ b/src/pages/pay/oil/authorize_preauthcharge.vue
@@ -315,9 +315,9 @@ export default defineComponent({
})
.then((response: any) => {
if (response.data.ok) {
- this.total_amount = response.data.total_amount;
- this.discount = response.data.discount;
- this.total_amount_after_discount = response.data.total_amount_after_discount;
+ this.total_amount = parseFloat(response.data.total_amount) || 0;
+ this.discount = parseFloat(response.data.discount) || 0;
+ this.total_amount_after_discount = parseFloat(response.data.total_amount_after_discount) || 0;
// Auto-populate charge amount with the calculated total
if (this.promo_active) {
@@ -513,8 +513,8 @@ export default defineComponent({
const response = await axios.post(chargePath, chargePayload, { withCredentials: true, headers: authHeader() });
- // Assuming your backend charge response has the same structure
- if (response.data && response.data.status === 'APPROVED') { // Adjust based on your actual response
+ // Status codes: 0 = APPROVED, 1 = DECLINED (based on backend TransactionStatus enum)
+ if (response.data && response.data.status === 0) { // 0 = APPROVED
this.success = `Charge successful! Transaction ID: ${response.data.auth_net_transaction_id || 'N/A'}`;
setTimeout(() => {
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
@@ -525,6 +525,7 @@ export default defineComponent({
}
}
} catch (error: any) {
+ console.log(error)
this.error = error.response?.data?.detail || `Failed to ${actionType} payment`
notify({
title: "Error",
diff --git a/src/pages/pay/oil/pay_oil.vue b/src/pages/pay/oil/pay_oil.vue
index a9003e6..93110d8 100755
--- a/src/pages/pay/oil/pay_oil.vue
+++ b/src/pages/pay/oil/pay_oil.vue
@@ -339,8 +339,7 @@ export default defineComponent({
})
.then((response: any) => {
if (response.data.ok) {
- console.log('%%%%%%%%%%%%%%%')
- console.log(response.data)
+
this.priceprime = response.data.priceprime;
this.pricesameday = response.data.pricesameday;
@@ -348,7 +347,7 @@ export default defineComponent({
this.total_amount = response.data.total_amount;
this.discount = response.data.discount;
this.total_amount_after_discount = response.data.total_amount_after_discount;
- console.log('%%%%%%%%%%%%%%%')
+
}
})
.catch(() => {
@@ -408,7 +407,6 @@ export default defineComponent({
});
},
getOilOrder(delivery_id: any) {
- console.log("=== DEBUG: getOilOrder called with delivery_id:", delivery_id);
let path = import.meta.env.VITE_BASE_URL + "/delivery/order/" + delivery_id;
axios({
method: "get",
@@ -500,6 +498,13 @@ export default defineComponent({
type: "success",
});
}
+ if (payment_type == 11) {
+ notify({
+ title: "Success",
+ text: "marked payment as CC - Authorize (API)",
+ type: "success",
+ });
+ }
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
}
})