working auto
This commit is contained in:
@@ -269,8 +269,6 @@ export default defineComponent({
|
||||
this.userStatus();
|
||||
},
|
||||
mounted() {
|
||||
console.log('VITE_VOIPMS_URL:', import.meta.env.VITE_VOIPMS_URL);
|
||||
console.log('VITE_VOIPMS_TOKEN:', import.meta.env.VITE_VOIPMS_TOKEN);
|
||||
this.updatestatus();
|
||||
this.fetchCurrentPhone();
|
||||
},
|
||||
@@ -285,7 +283,6 @@ export default defineComponent({
|
||||
|
||||
})
|
||||
.then((response: any) => {
|
||||
console.log(this.user)
|
||||
if (response.data.ok) {
|
||||
this.user = response.data.user;
|
||||
} else {
|
||||
@@ -307,7 +304,6 @@ export default defineComponent({
|
||||
})
|
||||
},
|
||||
logout() {
|
||||
console.log("Logging out...");
|
||||
// Clear auth data
|
||||
const authStore = useAuthStore();
|
||||
authStore.clearAuth();
|
||||
@@ -331,9 +327,7 @@ export default defineComponent({
|
||||
});
|
||||
},
|
||||
routeTo(route: string): Promise<any> {
|
||||
console.log('Routing to:', route);
|
||||
const path = `${import.meta.env.VITE_VOIPMS_URL}/route/${route}`;
|
||||
console.log('API path:', path);
|
||||
return axios({
|
||||
method: 'post',
|
||||
url: path,
|
||||
@@ -342,13 +336,11 @@ export default defineComponent({
|
||||
},
|
||||
})
|
||||
.then((response: any) => {
|
||||
console.log('Success routing to:', route);
|
||||
this.routeResponse = response.data;
|
||||
// Find the corresponding label
|
||||
const option = this.routingOptions.find(opt => opt.value === route);
|
||||
if (option) {
|
||||
this.currentPhone = option.label;
|
||||
console.log('Updated currentPhone to:', this.currentPhone);
|
||||
}
|
||||
return response.data;
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<!-- Loop over the new 'sortedDeliveries' computed property -->
|
||||
<tr v-for="oil in sortedDeliveries" :key="oil.id" class="hover:bg-blue-600 hover:text-white">
|
||||
<tr v-for="oil in sortedDeliveries" :key="oil.id" class="hover:bg-blue-600 hover:text-white" :class="{ 'bg-yellow-400 text-black' : oil.auto_status == 3 }">
|
||||
<td>
|
||||
<div v-if="oil.last_fill === null" class="text-gray-500">New Auto</div>
|
||||
<div v-else class="flex items-center gap-3">
|
||||
@@ -76,8 +76,11 @@
|
||||
<td>{{ oil.customer_address }}, {{ oil.customer_town }}</td>
|
||||
<td class="text-right">
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<router-link :to="{ name: 'customerEdit', params: { id: oil.customer_id } }" class="btn btn-sm btn-secondary">Edit Customer</router-link>
|
||||
<router-link :to="{ name: 'finalizeTicketAuto', params: { id: oil['id'] } }">
|
||||
<!-- <router-link :to="{ name: 'customerEdit', params: { id: oil.customer_id } }" class="btn btn-sm btn-secondary">Edit Customer</router-link> -->
|
||||
<router-link v-if="oil.auto_status != 3" :to="{ name: 'payAutoAuthorize', params: { id: oil['id'] } }">
|
||||
<button class="btn btn-primary btn-sm">Preauthorize</button>
|
||||
</router-link>
|
||||
<router-link v-if="oil.auto_status == 3" :to="{ name: 'finalizeTicketAuto', params: { id: oil.open_ticket_id || oil['id'] } }">
|
||||
<button class="btn btn-secondary btn-sm">Finalize</button>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'TicketAuto', params: { id: oil['id'] } }">
|
||||
@@ -126,7 +129,10 @@
|
||||
|
||||
<div class="card-actions justify-end flex-wrap gap-2 mt-4">
|
||||
<router-link :to="{ name: 'customerEdit', params: { id: oil.customer_id } }" class="btn btn-sm btn-secondary">Edit Customer</router-link>
|
||||
<router-link :to="{ name: 'finalizeTicketAuto', params: { id: oil['id'] } }">
|
||||
<router-link v-if="oil.auto_status != 3" :to="{ name: 'payAutoAuthorize', params: { id: oil['id'] } }">
|
||||
<button class="btn btn-primary btn-sm">Preauthorize</button>
|
||||
</router-link>
|
||||
<router-link v-if="oil.auto_status == 3" :to="{ name: 'finalizeTicketAuto', params: { id: oil.open_ticket_id || oil['id'] } }">
|
||||
<button class="btn btn-secondary btn-sm">Finalize</button>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'TicketAuto', params: { id: oil['id'] } }">
|
||||
@@ -162,6 +168,8 @@ interface AutoDelivery {
|
||||
customer_town: string;
|
||||
house_factor: number;
|
||||
tank_size: number;
|
||||
auto_status: number;
|
||||
open_ticket_id?: number | null;
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
@@ -185,6 +193,15 @@ export default defineComponent({
|
||||
const sorted = [...this.deliveries];
|
||||
|
||||
sorted.sort((a, b) => {
|
||||
// First, prioritize auto_status = 3 to be at the top
|
||||
if (a.auto_status === 3 && b.auto_status !== 3) {
|
||||
return -1;
|
||||
}
|
||||
if (a.auto_status !== 3 && b.auto_status === 3) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Then sort by the selected key
|
||||
let valA: any;
|
||||
let valB: any;
|
||||
|
||||
@@ -200,7 +217,7 @@ export default defineComponent({
|
||||
// Handle nulls or different types if necessary
|
||||
if (valA === null) return 1;
|
||||
if (valB === null) return -1;
|
||||
|
||||
|
||||
// Comparison logic
|
||||
if (valA < valB) {
|
||||
return this.sortAsc ? -1 : 1;
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
|
||||
<!-- RIGHT COLUMN: Finalize Form -->
|
||||
<div class="space-y-4">
|
||||
<div class="bg-base-100 rounded-lg p-5">
|
||||
<div v-if="customer.id > 0" class="bg-base-100 rounded-lg p-5">
|
||||
<h2 class="text-2xl font-bold mb-4">Finalize Auto Delivery</h2>
|
||||
<form class="space-y-4" @submit.prevent="onSubmit">
|
||||
<div>
|
||||
@@ -107,6 +107,10 @@
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div v-else class="bg-base-100 rounded-lg p-5">
|
||||
<h2 class="text-2xl font-bold mb-4 text-error">Error</h2>
|
||||
<p>Customer information not found. Please check the automatic delivery data.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -201,26 +205,52 @@
|
||||
description: '',
|
||||
},
|
||||
|
||||
autoDelivery: {
|
||||
|
||||
autoTicket: {
|
||||
id: 0,
|
||||
customer_id: '',
|
||||
account_number: '',
|
||||
|
||||
customer_town : '',
|
||||
customer_state : '',
|
||||
customer_address : '',
|
||||
customer_zip: '',
|
||||
customer_full_name : '',
|
||||
|
||||
oil_prices_id : '',
|
||||
fill_date : '',
|
||||
gallons_delivered : '',
|
||||
price_per_gallon : '',
|
||||
|
||||
total_amount_customer : '',
|
||||
|
||||
payment_type : '',
|
||||
payment_card_id : '',
|
||||
payment_status : '',
|
||||
open_ticket_id: 0
|
||||
|
||||
},
|
||||
|
||||
autoDelivery: {
|
||||
id: 0,
|
||||
customer_id: 0,
|
||||
account_number: '',
|
||||
customer_town: '',
|
||||
customer_state: '',
|
||||
customer_state: 0,
|
||||
customer_address: '',
|
||||
customer_zip: '',
|
||||
customer_full_name: '',
|
||||
last_fill: '',
|
||||
days_since_last_fill: 0,
|
||||
last_updated: '',
|
||||
estimated_gallons_left: '',
|
||||
estimated_gallons_left_prev_day: '',
|
||||
estimated_gallons_left: 0,
|
||||
estimated_gallons_left_prev_day: 0,
|
||||
tank_height: '',
|
||||
tank_size: '',
|
||||
house_factor: '',
|
||||
auto_status: '',
|
||||
house_factor: 0,
|
||||
auto_status: 0,
|
||||
open_ticket_id: null,
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
@@ -231,12 +261,12 @@
|
||||
watch: {
|
||||
$route() {
|
||||
this.today_price_oil();
|
||||
this.getAutoDelivery(this.$route.params.id);
|
||||
this.getAutoTicket(this.$route.params.id);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.today_price_oil();
|
||||
this.getAutoDelivery(this.$route.params.id);
|
||||
this.getAutoTicket(this.$route.params.id);
|
||||
|
||||
|
||||
},
|
||||
@@ -290,11 +320,16 @@
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.userCards = response.data;
|
||||
if (this.userCards && this.userCards.length > 0) {
|
||||
this.userCardfound = true;
|
||||
this.userCard = this.userCards.find((card: any) => card.main_card) || this.userCards[0];
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
});
|
||||
},
|
||||
getCustomer(user_id: any) {
|
||||
if (!user_id || user_id === 'undefined') return;
|
||||
let path = import.meta.env.VITE_BASE_URL + "/customer/" + user_id;
|
||||
axios({
|
||||
method: "get",
|
||||
@@ -303,7 +338,9 @@
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.customer = response.data;
|
||||
|
||||
if (this.customer.id > 0) {
|
||||
this.getPaymentCards(this.customer.user_id || this.customer.id);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
@@ -311,6 +348,7 @@
|
||||
text: "Could not find customer",
|
||||
type: "error",
|
||||
});
|
||||
this.customer = { id: 0, user_id: 0, customer_address: '', customer_first_name: '', customer_last_name: '', customer_town: '', customer_state: 0, customer_zip: '', customer_apt: '', customer_home_type: 0, customer_phone_number: '' };
|
||||
});
|
||||
},
|
||||
getCustomerDescription(user_id: any) {
|
||||
@@ -331,16 +369,40 @@
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
getAutoDelivery(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/" + delivery_id;
|
||||
},//TODO STUCK HERE !!!!!!!!!
|
||||
getAutoTicket(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/autoticket/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
|
||||
this.autoTicket = response.data;
|
||||
this.getCustomer(this.autoTicket.customer_id)
|
||||
|
||||
this.getAutoDelivery(this.autoTicket.id)
|
||||
this.getCustomerDescription(this.autoTicket.customer_id)
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get automatic",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getAutoDelivery(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/finddelivery/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
|
||||
this.autoDelivery = response.data;
|
||||
this.getCustomer(this.autoDelivery.customer_id)
|
||||
this.getCustomerDescription(this.autoDelivery.customer_id)
|
||||
@@ -354,6 +416,7 @@
|
||||
});
|
||||
});
|
||||
},
|
||||
//TODO STUCK HERE !!!!!!!!!
|
||||
today_price_oil() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/info/price/oil'
|
||||
axios({
|
||||
@@ -398,10 +461,7 @@
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
ConfirmAuto(payload: {
|
||||
|
||||
gallons_delivered: string,
|
||||
}) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/confirm/auto/create/" + this.autoDelivery.id;
|
||||
@@ -414,15 +474,16 @@
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data) {
|
||||
|
||||
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "Auto Delivered",
|
||||
type: "success",
|
||||
});
|
||||
this.CreateTransaction(response.data['0']['auto_ticket_id'])
|
||||
this.$router.push({ name: "auto" });
|
||||
|
||||
this.updateTransactionDelivery(this.autoDelivery.id, response.data['0']['auto_ticket_id'])
|
||||
this.$router.push({ name: "payAutoCapture", params: { id: response.data['0']['auto_ticket_id'] } });
|
||||
|
||||
}
|
||||
if (response.data.error) {
|
||||
notify({
|
||||
@@ -439,6 +500,7 @@
|
||||
UpdateDeliveredAuto(payload: {
|
||||
gallons_delivered: string,
|
||||
}) {
|
||||
console.log(this.autoDelivery)
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/confirm/auto/update/" + this.autoDelivery.id;
|
||||
axios({
|
||||
method: "put",
|
||||
@@ -453,12 +515,19 @@
|
||||
title: "Success",
|
||||
text: "Auto Updated",
|
||||
type: "success",
|
||||
});
|
||||
});
|
||||
this.$router.push({ name: "payAutoCapture", params: { id: this.autoTicket.id } });
|
||||
}
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
updateTransactionDelivery(current_delivery_id: any, new_delivery_id: any) {
|
||||
const path = `${import.meta.env.VITE_AUTHORIZE_URL}/api/auto/transaction/delivery/${current_delivery_id}/update/${new_delivery_id}`;
|
||||
axios.put(path, {}, { withCredentials: true, headers: authHeader() })
|
||||
.then(() => console.log("Transaction auto_id updated"))
|
||||
.catch(() => console.error("Error updating transaction auto_id"));
|
||||
},
|
||||
|
||||
CreateTransaction(auto_ticket_id: string,) {
|
||||
let path = import.meta.env.VITE_MONEY_URL + "/delivery/add/auto/" + auto_ticket_id;
|
||||
axios({
|
||||
@@ -474,7 +543,6 @@
|
||||
type: 'positive',
|
||||
position: 'top'
|
||||
})
|
||||
this.$router.push({ name: "auto" });
|
||||
}
|
||||
else {
|
||||
notify({
|
||||
@@ -486,11 +554,11 @@
|
||||
})
|
||||
},
|
||||
onSubmit() {
|
||||
|
||||
let payload = {
|
||||
gallons_delivered: this.FinalizeOilOrderForm.gallons_delivered,
|
||||
};
|
||||
this.UpdateDeliveredAuto(payload);
|
||||
this.ConfirmAuto(payload);
|
||||
|
||||
},
|
||||
|
||||
@@ -498,4 +566,4 @@
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
<style scoped></style>
|
||||
|
||||
551
src/pages/pay/auto/authorize_precharge_autho.vue
Normal file
551
src/pages/pay/auto/authorize_precharge_autho.vue
Normal file
@@ -0,0 +1,551 @@
|
||||
<!-- src/pages/pay/auto/authorize_precharge_autho.vue -->
|
||||
<template>
|
||||
<div class="flex">
|
||||
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="flex-1 px-8 py-6">
|
||||
|
||||
<!-- Breadcrumbs & Header -->
|
||||
<div class="text-sm breadcrumbs mb-6">
|
||||
<ul>
|
||||
<li><router-link :to="{ name: 'home' }">Home</router-link></li>
|
||||
<li><router-link :to="{ name: 'auto' }">Automatic Deliveries</router-link></li>
|
||||
<li>Payment Authorization</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- 2x2 Grid Layout -->
|
||||
<div class="max-w-6xl">
|
||||
<h1 class="text-3xl font-bold mb-8">Payment Authorization Authorize.net</h1>
|
||||
|
||||
<!-- Top Row: Charge Breakdown and Payment Method -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8">
|
||||
<!-- Charge Breakdown -->
|
||||
<div class="bg-base-100 rounded-lg p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Charge Breakdown</h3>
|
||||
<div class="space-y-2">
|
||||
<div class="flex justify-between">
|
||||
<span>Gallons to Fill:</span>
|
||||
<span>{{ calculateGallonsToFill() }} gallons</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Price per Gallon:</span>
|
||||
<span>${{ pricing.price_for_customer || currentOilPrice }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between font-semibold">
|
||||
<span>Subtotal:</span>
|
||||
<span>${{ calculateSubtotal() }}</span>
|
||||
</div>
|
||||
<hr class="my-3">
|
||||
<div class="flex justify-between font-bold text-lg">
|
||||
<span>Estimated Total:</span>
|
||||
<span>${{ calculateTotalAmount() }}</span>
|
||||
</div>
|
||||
</div> <!-- close space-y-2 -->
|
||||
</div> <!-- close bg-base-100 -->
|
||||
|
||||
<!-- Credit Card Display -->
|
||||
<div class="bg-base-100 rounded-lg p-6">
|
||||
<h3 class="text-lg font-semibold mb-4">Payment Method</h3>
|
||||
<div v-if="selectedCard" class="bg-base-200 p-4 rounded-md">
|
||||
<div class="flex justify-between items-center mb-2">
|
||||
<div class="font-semibold">{{ selectedCard.type_of_card }}</div>
|
||||
<div v-if="selectedCard.main_card" class="badge badge-primary">Primary</div>
|
||||
</div>
|
||||
<div class="font-mono text-sm">
|
||||
<div> {{ selectedCard.card_number }}</div>
|
||||
<div>{{ selectedCard.name_on_card }}</div>
|
||||
<div>Expires: {{ selectedCard.expiration_month }}/{{ selectedCard.expiration_year }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="text-gray-500 p-4">
|
||||
No payment method selected
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error/Success Messages -->
|
||||
<div class="mb-6">
|
||||
<div v-if="error" class="alert alert-error">
|
||||
<span>{{ error }}</span>
|
||||
</div>
|
||||
<div v-if="success" class="alert alert-success">
|
||||
<span>{{ success }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Bottom Section: Charge Amount Input and Action Buttons -->
|
||||
<div class="bg-base-100 rounded-lg p-6">
|
||||
<div class="flex flex-col lg:flex-row lg:items-center gap-6">
|
||||
<!-- Charge Amount Input - Compact -->
|
||||
<div class="flex-1">
|
||||
<h3 class="text-lg font-semibold mb-2">Charge Amount</h3>
|
||||
<div class="flex">
|
||||
<span class="inline-flex items-center px-3 text-sm bg-base-200 rounded-l-lg border border-r-0">$</span>
|
||||
<input
|
||||
v-model="chargeAmount"
|
||||
type="number"
|
||||
step="0.01"
|
||||
class="input input-bordered flex-1 rounded-l-none"
|
||||
placeholder="Enter amount"
|
||||
:disabled="loading"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Action Buttons -->
|
||||
<div class="flex gap-3 align-bottom">
|
||||
<router-link :to="{ name: 'auto' }">
|
||||
<button class="btn btn-ghost">Cancel</button>
|
||||
</router-link>
|
||||
<button
|
||||
@click="handlePreauthorize"
|
||||
class="btn btn-success"
|
||||
:disabled="loading || !chargeAmount"
|
||||
v-show="!success"
|
||||
>
|
||||
<span v-if="loading && action === 'preauthorize'" class="loading loading-spinner loading-sm"></span>
|
||||
Preauthorize
|
||||
</button>
|
||||
<button
|
||||
@click="handleChargeNow"
|
||||
class="btn btn-warning text-black"
|
||||
:disabled="loading || !chargeAmount"
|
||||
v-show="!success"
|
||||
>
|
||||
<span v-if="loading && action === 'charge'" class="loading loading-spinner loading-sm"></span>
|
||||
Charge Now
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Charge Confirmation Modal -->
|
||||
<div class="modal" :class="{ 'modal-open': isChargeConfirmationModalVisible }">
|
||||
<div class="modal-box">
|
||||
<h3 class="font-bold text-lg text-warning">⚠️ Warning: Charge Now</h3>
|
||||
<p class="py-4">
|
||||
You are about to <strong>immediately charge</strong> this customer's card
|
||||
for <strong>${{ chargeAmount.toFixed(2) }}</strong>.
|
||||
<br><br>
|
||||
This action is <strong>not reversible</strong> and will debit the customer's account immediately.
|
||||
<br><br>
|
||||
Are you sure you want to proceed with the charge?
|
||||
</p>
|
||||
<div class="modal-action">
|
||||
<button @click="proceedWithCharge" class="btn btn-warning">
|
||||
Yes, Charge Now
|
||||
</button>
|
||||
<button @click="cancelCharge" class="btn btn-ghost">
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, watch } from 'vue'
|
||||
import axios from 'axios'
|
||||
import authHeader from '../../../services/auth.header'
|
||||
import { notify } from "@kyvg/vue3-notification"
|
||||
|
||||
export default defineComponent({
|
||||
name: 'AuthorizePrechargeAutho',
|
||||
|
||||
data() {
|
||||
return {
|
||||
deliveryId: this.$route.params.id as string,
|
||||
loaded: false,
|
||||
chargeAmount: 0,
|
||||
loading: false,
|
||||
action: '', // 'preauthorize' or 'charge'
|
||||
error: '',
|
||||
success: '',
|
||||
isChargeConfirmationModalVisible: false,
|
||||
transactionId: 0,
|
||||
user: {
|
||||
user_id: 0,
|
||||
},
|
||||
autoDelivery: {
|
||||
id: 0,
|
||||
customer_id: 0,
|
||||
customer_full_name: '',
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
customer_state: 0,
|
||||
customer_zip: '',
|
||||
tank_size: 0,
|
||||
estimated_gallons_left: 0,
|
||||
house_factor: 0,
|
||||
auto_status: 0,
|
||||
},
|
||||
credit_cards: [
|
||||
{
|
||||
id: 0,
|
||||
name_on_card: '',
|
||||
main_card: false,
|
||||
card_number: '',
|
||||
expiration_month: '',
|
||||
type_of_card: '',
|
||||
last_four_digits: '',
|
||||
expiration_year: '',
|
||||
security_number: '',
|
||||
|
||||
}
|
||||
],
|
||||
customer: {
|
||||
id: 0,
|
||||
user_id: 0,
|
||||
customer_first_name: '',
|
||||
customer_last_name: '',
|
||||
customer_town: '',
|
||||
customer_address: '',
|
||||
customer_state: 0,
|
||||
customer_zip: '',
|
||||
customer_apt: '',
|
||||
customer_home_type: 0,
|
||||
customer_phone_number: '',
|
||||
account_number: '',
|
||||
},
|
||||
pricing: {
|
||||
price_from_supplier: 0,
|
||||
price_for_customer: 0,
|
||||
price_for_employee: 0,
|
||||
price_same_day: 0,
|
||||
price_prime: 0,
|
||||
price_emergency: 0,
|
||||
date: "",
|
||||
},
|
||||
currentOilPrice: 0,
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
selectedCard(): any {
|
||||
return this.credit_cards.find((card: any) => card.main_card) || this.credit_cards[0]
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.loadData(this.deliveryId)
|
||||
},
|
||||
|
||||
created() {
|
||||
this.watchRoute()
|
||||
},
|
||||
|
||||
methods: {
|
||||
watchRoute() {
|
||||
watch(
|
||||
() => this.$route.params.id,
|
||||
(newId) => {
|
||||
if (newId !== this.deliveryId) {
|
||||
this.resetState()
|
||||
this.deliveryId = newId as string
|
||||
this.loadData(newId as string)
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
|
||||
resetState() {
|
||||
this.loading = false
|
||||
this.action = ''
|
||||
this.error = ''
|
||||
this.success = ''
|
||||
this.chargeAmount = 0
|
||||
},
|
||||
|
||||
loadData(deliveryId: string) {
|
||||
this.userStatus()
|
||||
this.getAutoDelivery(deliveryId)
|
||||
this.getOilPricing()
|
||||
this.getCurrentOilPrice()
|
||||
},
|
||||
|
||||
getCurrentOilPrice() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/info/price/oil'
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.currentOilPrice = response.data.price_for_customer;
|
||||
this.calculateDefaultChargeAmount()
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
calculateDefaultChargeAmount() {
|
||||
this.chargeAmount = this.calculateTotalAsNumber()
|
||||
},
|
||||
|
||||
userStatus() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/auth/whoami';
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
this.user = response.data.user;
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
getOilPricing() {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/info/price/oil/table";
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.pricing = response.data;
|
||||
this.calculateDefaultChargeAmount()
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getAutoDelivery(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/delivery/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data && response.data.customer_id) {
|
||||
this.autoDelivery = response.data;
|
||||
this.getCustomer(this.autoDelivery.customer_id)
|
||||
this.getCreditCards(this.autoDelivery.customer_id)
|
||||
} else {
|
||||
console.error("API Error:", response.data.error || "Failed to fetch auto delivery data.");
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error("API Error in getAutoDelivery:", error);
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get automatic delivery",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getCreditCards(user_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/payment/cards/' + user_id;
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
}).then((response: any) => {
|
||||
this.credit_cards = response.data
|
||||
})
|
||||
},
|
||||
|
||||
getCustomer(userid: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/customer/' + userid;
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
}).then((response: any) => {
|
||||
this.customer = response.data
|
||||
})
|
||||
},
|
||||
|
||||
calculateGallonsToFill() {
|
||||
return this.autoDelivery.tank_size - this.autoDelivery.estimated_gallons_left
|
||||
},
|
||||
|
||||
calculateSubtotal() {
|
||||
const gallons = this.calculateGallonsToFill()
|
||||
const pricePerGallon = this.pricing.price_for_customer || this.currentOilPrice
|
||||
return (gallons * pricePerGallon).toFixed(2)
|
||||
},
|
||||
|
||||
calculateTotalAmount() {
|
||||
const subtotal = parseFloat(this.calculateSubtotal())
|
||||
let total = subtotal
|
||||
|
||||
// No additional fees for auto preauthorization
|
||||
|
||||
return total.toFixed(2)
|
||||
},
|
||||
|
||||
calculateTotalAsNumber() {
|
||||
return parseFloat(this.calculateTotalAmount())
|
||||
},
|
||||
|
||||
async handlePreauthorize() {
|
||||
await this.processPayment('preauthorize')
|
||||
},
|
||||
|
||||
async handleChargeNow() {
|
||||
this.loading = true
|
||||
this.isChargeConfirmationModalVisible = true
|
||||
},
|
||||
|
||||
async proceedWithCharge() {
|
||||
this.isChargeConfirmationModalVisible = false
|
||||
await this.processPayment('charge')
|
||||
},
|
||||
|
||||
cancelCharge() {
|
||||
this.isChargeConfirmationModalVisible = false
|
||||
},
|
||||
|
||||
async processPayment(actionType: string) {
|
||||
if (!this.selectedCard) {
|
||||
this.error = 'No credit card found for this customer'
|
||||
return
|
||||
}
|
||||
|
||||
this.loading = true
|
||||
this.action = actionType
|
||||
this.error = ''
|
||||
this.success = ''
|
||||
|
||||
try {
|
||||
// Step 2: If payment method is credit, perform the pre-authorization
|
||||
if (actionType === 'preauthorize') {
|
||||
if (!this.chargeAmount || this.chargeAmount <= 0) {
|
||||
throw new Error("Pre-authorization amount must be greater than zero.");
|
||||
}
|
||||
|
||||
const authPayload = {
|
||||
card_id: (this.selectedCard as any).id,
|
||||
preauthorize_amount: this.chargeAmount.toFixed(2),
|
||||
delivery_id: null,
|
||||
auto_id: this.deliveryId,
|
||||
};
|
||||
|
||||
const authPath = `${import.meta.env.VITE_AUTHORIZE_URL}/api/payments/authorize/saved-card/${this.customer.id}`;
|
||||
|
||||
const response = await axios.post(authPath, authPayload, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
if (!response.data.auth_net_transaction_id || response.data.auth_net_transaction_id.trim() === '') {
|
||||
throw new Error("Failed transaction: No Authorize.net transaction ID received");
|
||||
}
|
||||
|
||||
this.transactionId = response.data.id;
|
||||
|
||||
// Update auto_delivery status to 3
|
||||
await axios.put(`${import.meta.env.VITE_AUTO_URL}/delivery/update_status/${this.deliveryId}`, {}, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
// Create Tickets_Auto_Delivery after successful preauthorize
|
||||
const ticketPayload = {
|
||||
gallons_delivered: 0,
|
||||
payment_type: 11, // 11 for preauthorize, 1 for charge
|
||||
payment_card_id: this.selectedCard.id,
|
||||
payment_status: 1 // Pre-authorized status (ready for capture)
|
||||
};
|
||||
const ticketUrl = `${import.meta.env.VITE_AUTO_URL}/confirm/auto/create/${this.deliveryId}`;
|
||||
const ticketResponse = await axios.post(ticketUrl, ticketPayload, { withCredentials: true, headers: authHeader() });
|
||||
console.log('Ticket response data:', ticketResponse.data, 'type:', typeof ticketResponse.data, 'keys:', ticketResponse.data ? Object.keys(ticketResponse.data) : 'no data');
|
||||
|
||||
// Update transaction auto_id to ticket ID
|
||||
if (this.transactionId && ticketResponse.data) {
|
||||
const data = Array.isArray(ticketResponse.data) ? ticketResponse.data[0] : ticketResponse.data;
|
||||
if (data && data.auto_ticket_id !== undefined) {
|
||||
await axios.put(`${import.meta.env.VITE_AUTHORIZE_URL}/api/transaction/${this.transactionId}/update_auto_id/${data.auto_ticket_id}`, {}, { withCredentials: true, headers: authHeader() });
|
||||
} else {
|
||||
console.error('auto_ticket_id is undefined in ticket response');
|
||||
}
|
||||
}
|
||||
|
||||
// On successful authorization, show success and redirect
|
||||
this.success = `Preauthorization successful! Transaction ID: ${response.data.auth_net_transaction_id}`;
|
||||
setTimeout(() => {
|
||||
this.$router.push({ name: "auto" });
|
||||
}, 2000);
|
||||
}
|
||||
else { // Handle 'charge' action
|
||||
if (!this.chargeAmount || this.chargeAmount <= 0) {
|
||||
throw new Error("Charge amount must be greater than zero.");
|
||||
}
|
||||
|
||||
const chargePayload = {
|
||||
card_id: (this.selectedCard as any).id,
|
||||
charge_amount: this.chargeAmount.toFixed(2),
|
||||
delivery_id: this.deliveryId,
|
||||
};
|
||||
|
||||
const chargePath = `${import.meta.env.VITE_AUTHORIZE_URL}/api/payments/charge/saved-card/${this.customer.id}`;
|
||||
|
||||
console.log('=== DEBUG: Charge payload ===');
|
||||
console.log('Calling endpoint:', chargePath);
|
||||
console.log('Final payload being sent:', chargePayload);
|
||||
|
||||
const response = await axios.post(chargePath, chargePayload, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
// Update auto_delivery status to 3
|
||||
await axios.put(`${import.meta.env.VITE_AUTO_URL}/delivery/update_status/${this.deliveryId}`, {}, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
// Status codes: 0 = APPROVED, 1 = DECLINED (based on backend TransactionStatus enum)
|
||||
if (response.data && response.data.status === 0) { // 0 = APPROVED
|
||||
if (!response.data.auth_net_transaction_id || response.data.auth_net_transaction_id.trim() === '') {
|
||||
throw new Error("Failed transaction: No Authorize.net transaction ID received");
|
||||
}
|
||||
this.transactionId = response.data.id;
|
||||
this.success = `Charge successful! Transaction ID: ${response.data.auth_net_transaction_id}`;
|
||||
|
||||
// Create Tickets_Auto_Delivery after successful charge
|
||||
const ticketPayload = {
|
||||
gallons_delivered: this.calculateGallonsToFill(),
|
||||
payment_type: 1, // 1 for charge, 11 for preauthorize
|
||||
payment_card_id: this.selectedCard.id,
|
||||
payment_status: response.data.status // 0 = APPROVED
|
||||
};
|
||||
const ticketUrl = `${import.meta.env.VITE_AUTO_URL}/confirm/auto/create/${this.deliveryId}`;
|
||||
console.log("POOOPP!")
|
||||
await axios.post(ticketUrl, ticketPayload, { withCredentials: true, headers: authHeader() });
|
||||
|
||||
setTimeout(() => {
|
||||
this.$router.push({ name: "auto" });
|
||||
}, 2000);
|
||||
} else {
|
||||
// The error message from your backend will be more specific now
|
||||
throw new Error(`Payment charge failed: ${response.data?.rejection_reason || 'Unknown error'}`);
|
||||
}
|
||||
}
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
this.error = error.response?.data?.detail || `Failed to ${actionType} payment`
|
||||
notify({
|
||||
title: "Error",
|
||||
text: this.error,
|
||||
type: "error",
|
||||
})
|
||||
} finally {
|
||||
this.loading = false
|
||||
this.action = ''
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
558
src/pages/pay/auto/capture_authorize_autho.vue
Normal file
558
src/pages/pay/auto/capture_authorize_autho.vue
Normal file
@@ -0,0 +1,558 @@
|
||||
<!-- src/pages/pay/auto/capture_authorize_autho.vue -->
|
||||
<template>
|
||||
<div class="flex">
|
||||
|
||||
<!-- Main container with responsive horizontal padding -->
|
||||
<div class="w-full px-4 md:px-6 py-4">
|
||||
<div class="text-sm breadcrumbs">
|
||||
<ul>
|
||||
<li><router-link :to="{ name: 'home' }">Home</router-link></li>
|
||||
<li><router-link :to="{ name: 'customer' }">Customers</router-link></li>
|
||||
<li v-if="customer && customer.id">
|
||||
<router-link :to="{ name: 'customerProfile', params: { id: customer.id } }">
|
||||
{{ customer.customer_first_name }} {{ customer.customer_last_name }}
|
||||
</router-link>
|
||||
</li>
|
||||
<li>Capture Auto Payment #{{ autoTicket.id }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Page Header -->
|
||||
<div class="flex flex-wrap justify-between items-center gap-2 mt-4">
|
||||
<h1 class="text-3xl font-bold">
|
||||
Capture Payment for Auto Ticket #{{ autoTicket.id }}
|
||||
</h1>
|
||||
<router-link v-if="autoTicket.id" :to="{ name: 'TicketAuto', params: { id: autoTicket.id } }">
|
||||
<button class="btn btn-sm btn-secondary">Back to Auto Ticket</button>
|
||||
</router-link>
|
||||
</div>
|
||||
|
||||
<!-- Main Content Grid -->
|
||||
<div v-if="autoTicket.id" class="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
|
||||
|
||||
<!-- LEFT COLUMN: Customer and Auto Ticket Details -->
|
||||
<div class="space-y-6">
|
||||
|
||||
<!-- Customer Info Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<div class="text-xl font-bold mb-2">Customer</div>
|
||||
<div>
|
||||
<div class="font-bold">{{ customer.customer_first_name }} {{ customer.customer_last_name }}</div>
|
||||
<div>{{ customer.customer_address }}</div>
|
||||
<div v-if="customer.customer_apt && customer.customer_apt !== 'None'">{{ customer.customer_apt }}</div>
|
||||
<div>
|
||||
{{ customer.customer_town }},
|
||||
<span v-if="customer.customer_state == 0">Massachusetts</span>
|
||||
<span v-else-if="customer.customer_state == 1">Rhode Island</span>
|
||||
<span v-else-if="customer.customer_state == 2">New Hampshire</span>
|
||||
<span v-else-if="customer.customer_state == 3">Maine</span>
|
||||
<span v-else-if="customer.customer_state == 4">Vermont</span>
|
||||
<span v-else-if="customer.customer_state == 5">Maine</span>
|
||||
<span v-else-if="customer.customer_state == 6">New York</span>
|
||||
<span v-else>Unknown state</span>
|
||||
{{ customer.customer_zip }}
|
||||
</div>
|
||||
<div class="mt-2 text-sm">
|
||||
{{ customer.customer_phone_number }}
|
||||
(<span v-if="customer.customer_home_type == 0">Residential</span>
|
||||
<span v-else-if="customer.customer_home_type == 1">apartment</span>
|
||||
<span v-else-if="customer.customer_home_type == 2">condo</span>
|
||||
<span v-else-if="customer.customer_home_type == 3">commercial</span>
|
||||
<span v-else-if="customer.customer_home_type == 4">business</span>
|
||||
<span v-else-if="customer.customer_home_type == 5">construction</span>
|
||||
<span v-else-if="customer.customer_home_type == 6">container</span>)
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Financial Summary Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Financial Summary</h3>
|
||||
<div class="space-y-2">
|
||||
<div class="flex justify-between">
|
||||
<span>Gallons Delivered:</span>
|
||||
<span>{{ gallonsDelivered || 0 }} gallons</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Price per Gallon:</span>
|
||||
<span>${{ autoTicket.price_per_gallon || 0 }}</span>
|
||||
</div>
|
||||
<hr class="my-3">
|
||||
<div class="flex justify-between font-bold text-lg">
|
||||
<span>Total:</span>
|
||||
<span>${{ autoTicket.total_amount_customer || 0 }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Auto Ticket Details Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Auto Ticket Details</h3>
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-3 text-sm">
|
||||
<div>
|
||||
<div class="font-bold">Fill Date</div>
|
||||
<div class="opacity-80">{{ autoTicket.fill_date }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-bold">Account Number</div>
|
||||
<div class="opacity-80">{{ autoTicket.account_number }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Transaction Summary -->
|
||||
<div v-if="transaction && transaction.auth_net_transaction_id" class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Transaction Summary</h3>
|
||||
<div class="space-y-3">
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-3 text-sm">
|
||||
<div class="flex justify-between">
|
||||
<span class="font-bold">Transaction ID:</span>
|
||||
<span class="font-mono">{{ transaction.auth_net_transaction_id }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="font-bold">Pre-Auth Amount:</span>
|
||||
<span>${{ transaction.preauthorize_amount || '0.00' }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="font-bold">Charge Amount:</span>
|
||||
<span>${{ transaction.charge_amount || '0.00' }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="font-bold">Type:</span>
|
||||
<span :class="getTypeColor(transaction.transaction_type)">{{ transaction.transaction_type === 0 ? 'Charge' : transaction.transaction_type === 1 ? 'Auth' : 'Capture' }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="font-bold">Date:</span>
|
||||
<span>{{ transaction.created_at }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="font-bold">Status:</span>
|
||||
<span :class="transaction.status === 0 ? 'text-success' : 'text-error'">
|
||||
{{ transaction.status === 0 ? 'Approved' : 'Declined' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Credit Card Details -->
|
||||
<div v-if="userCardfound" class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Payment Method</h3>
|
||||
<div class="p-2 rounded-lg border" :class="userCard.main_card ? 'bg-primary/10 border-primary' : 'bg-base-200 border-base-300'">
|
||||
<div class="flex justify-between items-start">
|
||||
<div>
|
||||
<div class="font-bold text-sm">{{ userCard.name_on_card }}</div>
|
||||
<div class="text-xs opacity-70">{{ userCard.type_of_card }}</div>
|
||||
</div>
|
||||
<div v-if="userCard.main_card" class="badge badge-primary badge-sm">Primary</div>
|
||||
</div>
|
||||
<div class="mt-1 text-sm font-mono tracking-wider">
|
||||
<p>**** **** **** {{ userCard.last_four_digits }}</p>
|
||||
<p>Exp: <span v-if="Number(userCard.expiration_month) < 10">0</span>{{ userCard.expiration_month }} / {{ userCard.expiration_year }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<!-- RIGHT COLUMN: Capture Form -->
|
||||
<div class="space-y-6">
|
||||
|
||||
<!-- Gallons Delivered Display -->
|
||||
<div class="bg-base-100 rounded-lg p-5">
|
||||
<h2 class="text-2xl font-bold mb-4">Gallons Delivered</h2>
|
||||
<div class="text-center">
|
||||
<div class="text-4xl font-bold text-success">{{ gallonsDelivered || '0.00' }}</div>
|
||||
<div class="text-sm opacity-70">gallons</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Capture Payment Form -->
|
||||
<div class="bg-base-100 rounded-lg p-5">
|
||||
<h2 class="text-2xl font-bold mb-4">Capture Payment</h2>
|
||||
<div class="space-y-4">
|
||||
<div class="form-control">
|
||||
<label class="label">
|
||||
<span class="label-text font-bold">Capture Amount</span>
|
||||
</label>
|
||||
<div v-if="captureAmount > preAuthAmount" class="text-sm text-error mb-2">
|
||||
Cannot capture more than the preauthorization amount.
|
||||
</div>
|
||||
<input
|
||||
v-model="captureAmount"
|
||||
class="input input-bordered input-sm w-full"
|
||||
type="number"
|
||||
step="0.01"
|
||||
placeholder="0.00"
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="flex gap-4">
|
||||
<button
|
||||
v-if="Number(autoTicket.payment_status) === 1"
|
||||
@click="capturePayment"
|
||||
:class="`btn flex-1 ${captureAmount > 0 ? 'btn-success' : 'btn-error'}`"
|
||||
:disabled="loading || !captureAmount || captureAmount > preAuthAmount"
|
||||
>
|
||||
<span v-if="loading" class="loading loading-spinner loading-sm"></span>
|
||||
Capture Payment
|
||||
</button>
|
||||
<button
|
||||
@click="cancelCapture"
|
||||
class="btn btn-ghost"
|
||||
:disabled="loading"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="text-center p-10">
|
||||
Loading capture details...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue'
|
||||
import axios from 'axios'
|
||||
import authHeader from '../../../services/auth.header'
|
||||
import { notify } from "@kyvg/vue3-notification"
|
||||
|
||||
export default defineComponent({
|
||||
name: 'captureAuthorizeAuto',
|
||||
|
||||
data() {
|
||||
return {
|
||||
loading: false,
|
||||
userCardfound: false,
|
||||
gallonsDelivered: '',
|
||||
captureAmount: 0,
|
||||
preAuthAmount: 0,
|
||||
transaction: null as any,
|
||||
|
||||
userCard: {
|
||||
date_added: '',
|
||||
user_id: '',
|
||||
card_number: '',
|
||||
last_four_digits: '',
|
||||
name_on_card: '',
|
||||
expiration_month: '',
|
||||
expiration_year: '',
|
||||
type_of_card: '',
|
||||
security_number: '',
|
||||
accepted_or_declined: '',
|
||||
main_card: '',
|
||||
},
|
||||
customerDescription: {
|
||||
customer_id: 0,
|
||||
account_number: '',
|
||||
company_id: 0,
|
||||
fill_location: 0,
|
||||
description: '',
|
||||
},
|
||||
customer: {
|
||||
id: 0,
|
||||
user_id: 0,
|
||||
customer_address: '',
|
||||
customer_first_name: '',
|
||||
customer_last_name: '',
|
||||
customer_town: '',
|
||||
customer_state: 0,
|
||||
customer_zip: '',
|
||||
customer_apt: '',
|
||||
customer_home_type: 0,
|
||||
customer_phone_number: '',
|
||||
},
|
||||
autoDelivery: {
|
||||
id: 0,
|
||||
customer_id: 0,
|
||||
account_number: '',
|
||||
customer_town: '',
|
||||
customer_state: 0,
|
||||
customer_address: '',
|
||||
customer_zip: '',
|
||||
customer_full_name: '',
|
||||
last_fill: '',
|
||||
days_since_last_fill: 0,
|
||||
last_updated: '',
|
||||
estimated_gallons_left: 0,
|
||||
estimated_gallons_left_prev_day: 0,
|
||||
tank_height: '',
|
||||
tank_size: '',
|
||||
house_factor: 0,
|
||||
auto_status: 0,
|
||||
open_ticket_id: null,
|
||||
},
|
||||
autoTicket: {
|
||||
id: 0,
|
||||
customer_id: '',
|
||||
account_number: '',
|
||||
|
||||
customer_town : '',
|
||||
customer_state : '',
|
||||
customer_address : '',
|
||||
customer_zip: '',
|
||||
customer_full_name : '',
|
||||
|
||||
oil_prices_id : '',
|
||||
fill_date : '',
|
||||
gallons_delivered : '',
|
||||
price_per_gallon : '',
|
||||
|
||||
total_amount_customer : '',
|
||||
|
||||
payment_type : '',
|
||||
payment_card_id : '',
|
||||
payment_status : 0,
|
||||
open_ticket_id: 0
|
||||
|
||||
},
|
||||
|
||||
pricing: {
|
||||
price_from_supplier: 0,
|
||||
price_for_customer: 0,
|
||||
price_for_employee: 0,
|
||||
price_same_day: 0,
|
||||
price_prime: 0,
|
||||
price_emergency: 0,
|
||||
date: "",
|
||||
},
|
||||
|
||||
total_amount: 0,
|
||||
discount: 0,
|
||||
total_amount_after_discount: 0,
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.getAutoTicket(this.$route.params.id)
|
||||
this.getTransaction()
|
||||
},
|
||||
|
||||
methods: {
|
||||
getAutoTicket(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/autoticket/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.autoTicket = response.data;
|
||||
console.log(this.autoTicket)
|
||||
this.gallonsDelivered = this.autoTicket.gallons_delivered;
|
||||
this.captureAmount = parseFloat(this.autoTicket.total_amount_customer || '0');
|
||||
this.getCustomer(this.autoTicket.customer_id)
|
||||
|
||||
this.getAutoDelivery(this.autoTicket.id)
|
||||
this.getCustomerDescription(this.autoTicket.customer_id)
|
||||
if (this.autoTicket.payment_card_id) {
|
||||
this.getPaymentCard(this.autoTicket.payment_card_id)
|
||||
}
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get automatic",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getAutoDelivery(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/finddelivery/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
|
||||
this.autoDelivery = response.data;
|
||||
this.getCustomer(this.autoDelivery.customer_id)
|
||||
this.getCustomerDescription(this.autoDelivery.customer_id)
|
||||
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get automatic",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getPaymentCard(card_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/payment/card/" + card_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.userCard.card_number === ''){
|
||||
this.userCardfound = false;
|
||||
}
|
||||
else{
|
||||
this.userCard = response.data;
|
||||
this.userCardfound = true;
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
});
|
||||
},
|
||||
getCustomer(user_id: any) {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/customer/${user_id}`;
|
||||
axios.get(path, { withCredentials: true })
|
||||
.then((response: any) => {
|
||||
this.customer = response.data;
|
||||
})
|
||||
.catch((error: any) => {
|
||||
notify({ title: "Error", text: "Could not find customer", type: "error" });
|
||||
console.error("Error fetching customer:", error);
|
||||
});
|
||||
},
|
||||
getCustomerDescription(user_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/customer/description/" + user_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
this.customerDescription = response.data;
|
||||
this.loading = false
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not find customer",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
getTransaction() {
|
||||
const path = `${import.meta.env.VITE_AUTHORIZE_URL}/api/auto/transaction/delivery/${this.$route.params.id}`;
|
||||
axios.get(path, { withCredentials: true, headers: authHeader() })
|
||||
.then((response: any) => {
|
||||
this.transaction = response.data;
|
||||
this.preAuthAmount = parseFloat(response.data.preauthorize_amount || 0);
|
||||
if (response.data.status !== 0) { // Not approved
|
||||
this.preAuthAmount = 0;
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
if (error.response && error.response.status === 404) {
|
||||
notify({ title: "Info", text: "No pre-authorization found. Redirecting to customer profile to update payment method.", type: "info" });
|
||||
console.log("No transaction found for Automatic - redirecting to customer profile");
|
||||
this.$router.push({ name: 'customerProfile', params: { id: this.customer.id } });
|
||||
} else {
|
||||
notify({ title: "Error", text: "No pre-authorized transaction found", type: "error" });
|
||||
this.$router.push({ name: 'finalizeTicketAuto', params: { id: this.$route.params.id } });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
async capturePayment() {
|
||||
if (this.autoTicket.payment_status !== 1) {
|
||||
notify({ title: "Error", text: "Payment already captured or not ready for capture", type: "error" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.transaction || !this.captureAmount) {
|
||||
notify({ title: "Error", text: "Invalid capture amount or transaction data", type: "error" });
|
||||
return;
|
||||
}
|
||||
|
||||
this.loading = true;
|
||||
|
||||
try {
|
||||
const payload = {
|
||||
charge_amount: this.captureAmount,
|
||||
auth_net_transaction_id: this.transaction.auth_net_transaction_id
|
||||
};
|
||||
|
||||
const url = `${import.meta.env.VITE_AUTHORIZE_URL}/api/capture/`;
|
||||
|
||||
const response = await axios.post(
|
||||
url,
|
||||
payload,
|
||||
{ withCredentials: true, headers: authHeader() }
|
||||
);
|
||||
|
||||
if (response.data && response.data.status === 0) {
|
||||
this.autoTicket.payment_status = 3; // Update local status immediately
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "Payment captured successfully!",
|
||||
type: "success",
|
||||
});
|
||||
// Close the ticket and unassign from delivery
|
||||
this.closeTicket(this.autoTicket.id);
|
||||
this.$router.push({ name: 'auto' });
|
||||
} else if (response.data && response.data.status === 1) {
|
||||
const reason = response.data.rejection_reason || "The payment was declined by the gateway.";
|
||||
notify({
|
||||
title: "Payment Declined",
|
||||
text: reason,
|
||||
type: "warn",
|
||||
});
|
||||
} else {
|
||||
throw new Error("Invalid response from server during capture.");
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
const detail = error.response?.data?.detail || "Failed to capture payment due to a server error.";
|
||||
notify({
|
||||
title: "Error",
|
||||
text: detail,
|
||||
type: "error",
|
||||
});
|
||||
console.error("Capture Payment Error:", error);
|
||||
} finally {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
|
||||
cancelCapture() {
|
||||
this.$router.push({ name: 'finalizeTicketAuto', params: { id: this.$route.params.id } });
|
||||
},
|
||||
|
||||
async closeTicket(ticket_id: number) {
|
||||
const path = `${import.meta.env.VITE_AUTO_URL}/confirm/auto/close_ticket/${ticket_id}`;
|
||||
axios.put(path, {}, { withCredentials: true })
|
||||
.then(() => {
|
||||
console.log("Ticket closed successfully");
|
||||
})
|
||||
.catch((error: any) => {
|
||||
notify({
|
||||
title: "Warning",
|
||||
text: "Payment captured, but failed to close ticket. Check manually.",
|
||||
type: "warn",
|
||||
});
|
||||
console.error("Error closing ticket:", error);
|
||||
});
|
||||
},
|
||||
|
||||
getTypeColor(transactionType: number) {
|
||||
switch (transactionType) {
|
||||
case 1: return 'text-blue-600'; // Auth
|
||||
case 0: return 'text-orange-600'; // Charge
|
||||
case 2: return 'text-purple-600'; // Capture
|
||||
case 3: return 'text-green-600'; // Delivery/Other
|
||||
default: return 'text-gray-600';
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
@@ -6,9 +6,11 @@ import CaptureAuthorize from './oil/capture_authorize.vue';
|
||||
import PayService from './service/pay_service.vue';
|
||||
import AuthorizeServicePreauthCharge from './service/authorize_preauthcharge.vue';
|
||||
import ChargeServiceAuthorize from './service/capture_authorize.vue';
|
||||
import AuthorizePrechargeAutho from './auto/authorize_precharge_autho.vue';
|
||||
import CaptureAuthorizeAutho from './auto/capture_authorize_autho.vue';
|
||||
|
||||
const payRoutes = [
|
||||
|
||||
// This is for oil delivery
|
||||
{
|
||||
path: '/pay/oil/:id',
|
||||
name: 'payOil',
|
||||
@@ -19,14 +21,15 @@ const payRoutes = [
|
||||
name: 'authorizePreauthCharge',
|
||||
component: AuthorizePreauthCharge,
|
||||
},
|
||||
// This is for oil delivery
|
||||
{
|
||||
path: '/pay/capture/authorize/:id',
|
||||
name: 'captureAuthorize',
|
||||
component: CaptureAuthorize,
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
// this is for service
|
||||
{
|
||||
path: '/pay/service/:id',
|
||||
name: 'payService',
|
||||
@@ -37,13 +40,25 @@ const payRoutes = [
|
||||
name: 'authorizeServicePreauthCharge',
|
||||
component: AuthorizeServicePreauthCharge,
|
||||
},
|
||||
// this is for service
|
||||
|
||||
{
|
||||
path: '/pay/service/capture/authorize/:id',
|
||||
name: 'chargeServiceAuthorize',
|
||||
component: ChargeServiceAuthorize,
|
||||
},
|
||||
|
||||
// this is for auto
|
||||
{
|
||||
path: '/pay/auto/authorize/:id',
|
||||
name: 'payAutoAuthorize',
|
||||
component: AuthorizePrechargeAutho,
|
||||
},
|
||||
{
|
||||
path: '/pay/auto/capture/:id',
|
||||
name: 'payAutoCapture',
|
||||
component: CaptureAuthorizeAutho,
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
export default payRoutes
|
||||
|
||||
@@ -230,7 +230,7 @@ export default defineComponent({
|
||||
|
||||
methods: {
|
||||
getAutoOrder(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/" + delivery_id;
|
||||
let path = import.meta.env.VITE_AUTO_URL + "/delivery/delivery/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
|
||||
Reference in New Issue
Block a user