Working flow authorize

This commit is contained in:
2025-09-16 12:45:42 -04:00
parent 3cf6d1911a
commit bd95e14bb3
8 changed files with 356 additions and 43 deletions

View File

@@ -90,14 +90,45 @@
<div class="font-bold">When Ordered</div>
<div class="opacity-80">{{ deliveryOrder.when_ordered }}</div>
</div>
<div>
<div class="font-bold">When Delivered</div>
<div class="opacity-80">{{ deliveryOrder.when_delivered }}</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>
<!-- Financial Summary Card -->
<div class="bg-neutral rounded-lg p-5">
<h3 class="text-xl font-bold mb-4">Financial Summary</h3>
@@ -134,10 +165,12 @@
<span v-else>No Payment Type Added</span>
</div>
<div v-if="userCardfound && (deliveryOrder.payment_type == 1 || deliveryOrder.payment_type == 2)" class="mt-2 p-3 rounded-lg border bg-accent/20 border-accent">
<!-- --- MODIFICATION --- Safe display of card data -->
<!-- --- MODIFICATION --- Full display of card data -->
<div class="font-bold text-sm">{{ userCard.type_of_card }}</div>
<div class="text-sm font-mono tracking-wider">
<p>**** **** **** {{ userCard.last_four }}</p>
<div class="text-sm font-mono tracking-wider space-y-1">
<p>Name: {{ userCard.name_on_card }}</p>
<p>Card: {{ userCard.card_number }}</p>
<p>CVV: {{ userCard.security_number }}</p>
<p>Exp: {{ userCard.expiration_month }} / {{ userCard.expiration_year }}</p>
</div>
</div>
@@ -217,6 +250,9 @@ interface UserCard {
type_of_card: string;
expiration_month: number;
expiration_year: number;
name_on_card: string;
card_number: string;
security_number: string;
}
interface PreAuthTransaction {
id: number;
@@ -276,6 +312,7 @@ export default defineComponent({
price_prime: 0,
price_same_day: 0,
},
transaction: null as any,
}
},
computed: {
@@ -297,6 +334,7 @@ export default defineComponent({
console.log(`[DEBUG] Component Mounted. Fetching data for delivery ID: ${deliveryId}`);
this.getOilOrder(deliveryId);
this.getOilPricing();
this.getTransaction(deliveryId);
},
methods: {
async getOilOrder(delivery_id: any) {
@@ -371,6 +409,31 @@ export default defineComponent({
.then((response: any) => { this.pricing = response.data; })
.catch((error: any) => { console.error("[DEBUG] Error fetching oil pricing:", error); });
},
getTransaction(delivery_id: any) {
const path = `${import.meta.env.VITE_AUTHORIZE_URL}/api/transaction/delivery/${delivery_id}`;
axios.get(path, { withCredentials: true, headers: authHeader() })
.then((response: any) => {
this.transaction = response.data;
})
.catch((error: any) => {
// Handle 404 gracefully - delivery doesn't have transaction data in authorize system
if (error.response && error.response.status === 404) {
console.log(`No transaction found for delivery ${delivery_id} in authorize system`);
this.transaction = null;
} else {
console.error("Error fetching transaction:", error);
this.transaction = null;
}
});
},
getTypeColor(transactionType: number) {
switch (transactionType) {
case 1: return 'text-blue-600';
case 0: return 'text-orange-600';
case 2: return 'text-green-600';
default: return 'text-gray-600';
}
},
CreateTransaction() {
const path = `${import.meta.env.VITE_MONEY_URL}/delivery/add/${this.deliveryOrder.id}`;
axios.post(path, {}, { withCredentials: true, headers: authHeader() })
@@ -397,18 +460,29 @@ export default defineComponent({
}
if ([1, 2].includes(this.deliveryOrder.payment_type)) {
const transactionUrl = `${import.meta.env.VITE_AUTHORIZE_URL}/api/transaction/delivery/${this.deliveryOrder.id}`;
const transactionResponse = await axios.get(transactionUrl, { withCredentials: true, headers: authHeader() });
const preAuthTx = transactionResponse.data as PreAuthTransaction;
if (preAuthTx && preAuthTx.transaction_type === 1 && preAuthTx.status === 0) {
const capturePayload = {
auth_net_transaction_id: preAuthTx.auth_net_transaction_id,
charge_amount: this.finalChargeAmount.toFixed(2),
};
const capturePath = `${import.meta.env.VITE_AUTHORIZE_URL}/api/capture/`;
await axios.post(capturePath, capturePayload, { withCredentials: true, headers: authHeader() });
notify({ title: "Payment Captured", text: `Successfully charged $${capturePayload.charge_amount}.`, type: "success" });
} else {
notify({ title: "Warning", text: "No valid pre-authorization found to capture. Please charge manually.", type: "warn" });
try {
const transactionResponse = await axios.get(transactionUrl, { withCredentials: true, headers: authHeader() });
const preAuthTx = transactionResponse.data as PreAuthTransaction;
if (preAuthTx && preAuthTx.transaction_type === 1 && preAuthTx.status === 0) {
const capturePayload = {
auth_net_transaction_id: preAuthTx.auth_net_transaction_id,
charge_amount: this.finalChargeAmount.toFixed(2),
};
const capturePath = `${import.meta.env.VITE_AUTHORIZE_URL}/api/capture/`;
await axios.post(capturePath, capturePayload, { withCredentials: true, headers: authHeader() });
notify({ title: "Payment Captured", text: `Successfully charged $${capturePayload.charge_amount}.`, type: "success" });
} else {
notify({ title: "Warning", text: "No valid pre-authorization found to capture. Please charge manually.", type: "warn" });
}
} catch (error: any) {
if (error.response?.status === 404 && error.response?.data?.detail?.includes("No pre-authorization transaction found")) {
notify({ title: "Redirecting", text: "No pre-authorization found. Redirecting to customer profile to update payment method.", type: "info" });
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
return;
} else {
notify({ title: "Error", text: "Failed to check transaction status.", type: "error" });
throw error;
}
}
}
this.CreateTransaction();
@@ -423,4 +497,4 @@ export default defineComponent({
},
},
});
</script>
</script>