Updated charge close to working
This commit is contained in:
518
src/pages/pay/oil/authorize_preauthcharge.vue
Normal file
518
src/pages/pay/oil/authorize_preauthcharge.vue
Normal file
@@ -0,0 +1,518 @@
|
||||
<!-- src/pages/pay/oil/authorize_preauthcharge.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: 'payOil', params: { id: deliveryId } }">Payment Confirmation</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 Ordered:</span>
|
||||
<span>{{ delivery.gallons_ordered || 0 }} gallons</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Price per Gallon:</span>
|
||||
<span>${{ delivery.customer_price || 0 }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between font-semibold">
|
||||
<span>Subtotal:</span>
|
||||
<span>${{ calculateSubtotal() }}</span>
|
||||
</div>
|
||||
<div v-if="delivery.prime == 1" class="flex justify-between text-sm">
|
||||
<span>Prime Fee:</span>
|
||||
<span>+ ${{ pricing.price_prime || 0 }}</span>
|
||||
</div>
|
||||
<div v-if="delivery.same_day == 1" class="flex justify-between text-sm">
|
||||
<span>Same Day Fee:</span>
|
||||
<span>+ ${{ pricing.price_same_day || 0 }}</span>
|
||||
</div>
|
||||
<div v-if="delivery.emergency == 1" class="flex justify-between text-sm">
|
||||
<span>Emergency Fee:</span>
|
||||
<span>+ ${{ pricing.price_emergency || 0 }}</span>
|
||||
</div>
|
||||
<div v-if="promo_active" class="flex justify-between text-success">
|
||||
<span>{{ promo.name_of_promotion }}:</span>
|
||||
<span>- ${{ discount }}</span>
|
||||
</div>
|
||||
<hr class="my-3">
|
||||
<div class="flex justify-between font-bold text-lg">
|
||||
<span>Total:</span>
|
||||
<span>${{ promo_active ? total_amount_after_discount : total_amount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 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: 'payOil', params: { id: deliveryId } }">
|
||||
<button class="btn btn-ghost">Cancel</button>
|
||||
</router-link>
|
||||
<button
|
||||
@click="handlePreauthorize"
|
||||
class="btn btn-warning"
|
||||
:disabled="loading || !chargeAmount"
|
||||
>
|
||||
<span v-if="loading && action === 'preauthorize'" class="loading loading-spinner loading-sm"></span>
|
||||
Preauthorize
|
||||
</button>
|
||||
<button
|
||||
@click="handleChargeNow"
|
||||
class="btn btn-primary"
|
||||
:disabled="loading || !chargeAmount"
|
||||
>
|
||||
<span v-if="loading && action === 'charge'" class="loading loading-spinner loading-sm"></span>
|
||||
Charge Now
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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: 'AuthorizePreauthCharge',
|
||||
|
||||
data() {
|
||||
return {
|
||||
deliveryId: this.$route.params.id as string,
|
||||
loaded: false,
|
||||
chargeAmount: 0,
|
||||
loading: false,
|
||||
action: '', // 'preauthorize' or 'charge'
|
||||
error: '',
|
||||
success: '',
|
||||
user: {
|
||||
user_id: 0,
|
||||
},
|
||||
delivery: {
|
||||
id: 0,
|
||||
customer_id: 0,
|
||||
customer_name: '',
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
customer_state: 0,
|
||||
customer_zip: '',
|
||||
gallons_ordered: 0,
|
||||
customer_asked_for_fill: 0,
|
||||
gallons_delivered: 0,
|
||||
customer_filled: 0,
|
||||
delivery_status: 0,
|
||||
when_ordered: '',
|
||||
when_delivered: '',
|
||||
expected_delivery_date: '',
|
||||
automatic: 0,
|
||||
oil_id: 0,
|
||||
supplier_price: 0,
|
||||
customer_price: 0,
|
||||
customer_temperature: 0,
|
||||
dispatcher_notes: '',
|
||||
prime: 0,
|
||||
promo_id: 0,
|
||||
emergency: 0,
|
||||
same_day: 0,
|
||||
payment_type: 0,
|
||||
payment_card_id: 0,
|
||||
driver_employee_id: 0,
|
||||
driver_first_name: '',
|
||||
driver_last_name: '',
|
||||
pre_charge_amount: 0,
|
||||
total_price: 0,
|
||||
service_id: null,
|
||||
},
|
||||
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: "",
|
||||
},
|
||||
promo_active: false,
|
||||
promo: {
|
||||
name_of_promotion: '',
|
||||
description: '',
|
||||
money_off_delivery: 0,
|
||||
text_on_ticket: ''
|
||||
},
|
||||
total_amount: 0,
|
||||
discount: 0,
|
||||
total_amount_after_discount: 0,
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
selectedCard(): any {
|
||||
return this.credit_cards.find((card: any) => card.id === this.delivery.payment_card_id)
|
||||
}
|
||||
},
|
||||
|
||||
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
|
||||
this.promo_active = false
|
||||
this.total_amount = 0
|
||||
this.discount = 0
|
||||
this.total_amount_after_discount = 0
|
||||
this.deliveryId = this.$route.params.id as string
|
||||
},
|
||||
|
||||
loadData(deliveryId: string) {
|
||||
this.userStatus()
|
||||
this.getOilOrder(deliveryId)
|
||||
this.sumdelivery(deliveryId)
|
||||
this.getOilPricing()
|
||||
this.updatestatus()
|
||||
},
|
||||
|
||||
updatestatus() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/delivery/updatestatus';
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
}).then((response: any) => {
|
||||
if (response.data.update)
|
||||
console.log("Updated Status of Deliveries")
|
||||
})
|
||||
},
|
||||
|
||||
sumdelivery(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.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;
|
||||
|
||||
// Auto-populate charge amount with the calculated total
|
||||
if (this.promo_active) {
|
||||
this.chargeAmount = this.total_amount_after_discount;
|
||||
} else {
|
||||
this.chargeAmount = this.total_amount;
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getPromo(promo_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/promo/" + promo_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data) {
|
||||
this.promo = response.data
|
||||
this.promo_active = true
|
||||
|
||||
// Update charge amount when promo is applied
|
||||
if (this.total_amount_after_discount > 0) {
|
||||
this.chargeAmount = this.total_amount_after_discount
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
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;
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
getOilOrder(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/order/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data && response.data.ok) {
|
||||
this.delivery = response.data.delivery;
|
||||
this.getCustomer(this.delivery.customer_id)
|
||||
this.getCreditCards(this.delivery.customer_id)
|
||||
if (this.delivery.promo_id != null) {
|
||||
this.getPromo(this.delivery.promo_id);
|
||||
this.promo_active = true;
|
||||
}
|
||||
} else {
|
||||
console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error("API Error in getOilOrder:", error);
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get 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
|
||||
})
|
||||
},
|
||||
|
||||
calculateSubtotal() {
|
||||
const gallons = this.delivery.gallons_ordered || 0
|
||||
const pricePerGallon = this.delivery.customer_price || 0
|
||||
return (gallons * pricePerGallon).toFixed(2)
|
||||
},
|
||||
|
||||
async handlePreauthorize() {
|
||||
await this.processPayment('preauthorize')
|
||||
},
|
||||
|
||||
async handleChargeNow() {
|
||||
await this.processPayment('charge')
|
||||
},
|
||||
|
||||
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 {
|
||||
const endpoint = actionType === 'preauthorize' ? 'authorize' : 'charge'
|
||||
const payload = {
|
||||
card_number: (this.selectedCard as any).card_number,
|
||||
expiration_date: `${(this.selectedCard as any).expiration_month}${(this.selectedCard as any).expiration_year}`,
|
||||
cvv: (this.selectedCard as any).security_number,
|
||||
[actionType === 'preauthorize' ? 'preauthorize_amount' : 'charge_amount']: this.chargeAmount.toString(),
|
||||
transaction_type: actionType === 'preauthorize' ? 1 : 0,
|
||||
service_id: this.delivery.service_id || null,
|
||||
delivery_id: this.delivery.id,
|
||||
card_id: (this.selectedCard as any).id
|
||||
}
|
||||
|
||||
console.log('=== DEBUG: Payment payload ===')
|
||||
console.log('Delivery ID:', this.delivery.id)
|
||||
console.log('Final payload being sent:', payload)
|
||||
|
||||
const response = await axios.post(
|
||||
`${import.meta.env.VITE_AUTHORIZE_URL}/api/${endpoint}/?customer_id=${this.customer.id}`,
|
||||
payload,
|
||||
{ withCredentials: true }
|
||||
)
|
||||
|
||||
if (response.data && response.data.status === 0) {
|
||||
this.success = `${actionType === 'preauthorize' ? 'Preauthorization' : 'Charge'} successful! Transaction ID: ${response.data.auth_net_transaction_id || 'N/A'}`
|
||||
setTimeout(() => {
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
}, 2000)
|
||||
} else {
|
||||
throw new Error(`Payment ${actionType} failed: ${response.data?.status || 'Unknown error'}`)
|
||||
}
|
||||
} catch (error: any) {
|
||||
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>
|
||||
492
src/pages/pay/oil/capture_authorize.vue
Normal file
492
src/pages/pay/oil/capture_authorize.vue
Normal file
@@ -0,0 +1,492 @@
|
||||
<!-- src/pages/pay/capture_authorize.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 Payment #{{ deliveryOrder.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 #{{ deliveryOrder.id }}
|
||||
</h1>
|
||||
<router-link v-if="deliveryOrder.id" :to="{ name: 'finalizeTicket', params: { id: deliveryOrder.id } }">
|
||||
<button class="btn btn-sm btn-secondary">Back to Finalize</button>
|
||||
</router-link>
|
||||
</div>
|
||||
|
||||
<!-- Main Content Grid -->
|
||||
<div v-if="deliveryOrder.id" class="grid grid-cols-1 lg:grid-cols-2 gap-6 mt-6">
|
||||
|
||||
<!-- LEFT COLUMN: Customer and Delivery 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-3">
|
||||
<!-- Pricing & Gallons -->
|
||||
<div class="grid grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<div class="font-bold">Price / Gallon</div>
|
||||
<div class="opacity-80">${{ Number(deliveryOrder.customer_price).toFixed(2) }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-bold">Gallons Delivered</div>
|
||||
<div class="opacity-80">{{ gallonsDelivered || '0.00' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Fees -->
|
||||
<div class="text-sm space-y-1 border-t border-base-100 pt-3">
|
||||
<div v-if="deliveryOrder.prime == 1" class="flex justify-between">
|
||||
<span>Prime Fee</span>
|
||||
<span>${{ Number(pricing.price_prime).toFixed(2) }}</span>
|
||||
</div>
|
||||
<div v-if="deliveryOrder.same_day === 1" class="flex justify-between">
|
||||
<span>Same Day Fee</span>
|
||||
<span>${{ Number(pricing.price_same_day).toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Total -->
|
||||
<div class="flex justify-between items-center border-t border-base-100 pt-3">
|
||||
<span class="text-lg font-bold">Total Amount</span>
|
||||
<span class="text-2xl font-bold text-success">${{ Number(captureAmount).toFixed(2) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delivery Details Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Delivery Details</h3>
|
||||
<div class="grid grid-cols-2 gap-x-4 gap-y-3 text-sm">
|
||||
<div>
|
||||
<div class="font-bold">Status</div>
|
||||
<div class="opacity-80">
|
||||
<span v-if="deliveryOrder.delivery_status == 0">waiting</span>
|
||||
<span v-else-if="deliveryOrder.delivery_status == 1">delivered</span>
|
||||
<span v-else-if="deliveryOrder.delivery_status == 2">Today</span>
|
||||
<span v-else-if="deliveryOrder.delivery_status == 3">Tomorrow</span>
|
||||
<span v-else-if="deliveryOrder.delivery_status == 4">Partial Delivery</span>
|
||||
<span v-else-if="deliveryOrder.delivery_status == 5">misdelivery</span>
|
||||
<span v-else-if="deliveryOrder.delivery_status == 6">unknown</span>
|
||||
<span v-else-if="deliveryOrder.delivery_status == 10">Finalized</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-bold">Scheduled Date</div>
|
||||
<div class="opacity-80">{{ deliveryOrder.expected_delivery_date }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<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>
|
||||
|
||||
<!-- 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-primary">{{ 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
|
||||
@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>
|
||||
<Footer />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue'
|
||||
import axios from 'axios'
|
||||
import authHeader from '../../../services/auth.header'
|
||||
import Header from '../../../layouts/headers/headerauth.vue'
|
||||
import SideBar from '../../../layouts/sidebar/sidebar.vue'
|
||||
import Footer from '../../../layouts/footers/footer.vue'
|
||||
import { notify } from "@kyvg/vue3-notification"
|
||||
|
||||
export default defineComponent({
|
||||
name: 'captureAuthorize',
|
||||
|
||||
components: {
|
||||
Header,
|
||||
SideBar,
|
||||
Footer,
|
||||
},
|
||||
|
||||
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: '',
|
||||
},
|
||||
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: '',
|
||||
},
|
||||
deliveryOrder: {
|
||||
id: '',
|
||||
customer_id: 0,
|
||||
customer_name: '',
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
customer_state: 0,
|
||||
customer_zip: '',
|
||||
gallons_ordered: 0,
|
||||
customer_asked_for_fill: 0,
|
||||
gallons_delivered: '',
|
||||
customer_filled: 0,
|
||||
delivery_status: 0,
|
||||
when_ordered: '',
|
||||
when_delivered: '',
|
||||
expected_delivery_date: '',
|
||||
automatic: 0,
|
||||
oil_id: 0,
|
||||
supplier_price: '',
|
||||
customer_price: '',
|
||||
customer_temperature: '',
|
||||
dispatcher_notes: '',
|
||||
prime: 0,
|
||||
same_day: 0,
|
||||
payment_type: 0,
|
||||
payment_card_id: '',
|
||||
driver_employee_id: 0,
|
||||
driver_first_name: '',
|
||||
driver_last_name: '',
|
||||
total_price: 0,
|
||||
},
|
||||
pricing: {
|
||||
price_from_supplier: 0,
|
||||
price_for_customer: 0,
|
||||
price_for_employee: 0,
|
||||
price_same_day: 0,
|
||||
price_prime: 0,
|
||||
date: "",
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.getOilOrder(this.$route.params.id)
|
||||
this.getOilPricing()
|
||||
this.getTransaction()
|
||||
},
|
||||
|
||||
methods: {
|
||||
getOilOrder(delivery_id: any) {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/delivery/order/${delivery_id}`;
|
||||
axios.get(path, { withCredentials: true, headers: authHeader() })
|
||||
.then((response: any) => {
|
||||
if (response.data && response.data.ok) {
|
||||
this.deliveryOrder = response.data.delivery;
|
||||
this.gallonsDelivered = this.deliveryOrder.gallons_delivered;
|
||||
this.getCustomer(this.deliveryOrder.customer_id);
|
||||
|
||||
if ([1, 2, 3].includes(this.deliveryOrder.payment_type)) {
|
||||
this.getPaymentCard(this.deliveryOrder.payment_card_id);
|
||||
}
|
||||
|
||||
// Calculate capture amount if pricing is already loaded
|
||||
this.calculateCaptureAmount();
|
||||
} else {
|
||||
console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
|
||||
}
|
||||
})
|
||||
.catch((error: any) => console.error("Error fetching oil order:", error));
|
||||
},
|
||||
|
||||
getPaymentCard(card_id: any) {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/payment/card/${card_id}`;
|
||||
axios.get(path, { withCredentials: true })
|
||||
.then((response: any) => {
|
||||
if (response.data.userCard && response.data.userCard.card_number !== '') {
|
||||
this.userCard = response.data;
|
||||
this.userCardfound = true;
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
this.userCardfound = false;
|
||||
console.error("Error fetching payment card:", error);
|
||||
});
|
||||
},
|
||||
|
||||
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);
|
||||
});
|
||||
},
|
||||
|
||||
getOilPricing() {
|
||||
const path = `${import.meta.env.VITE_BASE_URL}/info/price/oil/table`;
|
||||
axios.get(path, { withCredentials: true })
|
||||
.then((response: any) => {
|
||||
this.pricing = response.data;
|
||||
// Calculate capture amount if delivery order is already loaded
|
||||
this.calculateCaptureAmount();
|
||||
})
|
||||
.catch((error: any) => {
|
||||
notify({ title: "Error", text: "Could not get oil pricing", type: "error" });
|
||||
console.error("Error fetching oil pricing:", error);
|
||||
});
|
||||
},
|
||||
|
||||
getTransaction() {
|
||||
const path = `${import.meta.env.VITE_AUTHORIZE_URL}/api/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) => {
|
||||
notify({ title: "Error", text: "No pre-authorized transaction found", type: "error" });
|
||||
console.error("Error fetching transaction:", error);
|
||||
this.$router.push({ name: 'finalizeTicket', params: { id: this.$route.params.id } });
|
||||
});
|
||||
},
|
||||
|
||||
async capturePayment() {
|
||||
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, // FastAPI handles string/number conversion
|
||||
auth_net_transaction_id: this.transaction.auth_net_transaction_id
|
||||
};
|
||||
|
||||
// ✅ FIX: Cleaned up URL, removing the unnecessary customer_id query parameter.
|
||||
const url = `${import.meta.env.VITE_AUTHORIZE_URL}/api/capture/`;
|
||||
|
||||
const response = await axios.post(
|
||||
url,
|
||||
payload,
|
||||
{ withCredentials: true, headers: authHeader() }
|
||||
);
|
||||
|
||||
// ✅ FIX: Improved logic to handle both success and declines properly.
|
||||
if (response.data && response.data.status === 0) {
|
||||
// This is the APPROVED case
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "Payment captured successfully!",
|
||||
type: "success",
|
||||
});
|
||||
this.$router.push({ name: 'deliveryOrder', params: { id: this.$route.params.id } });
|
||||
|
||||
} else if (response.data && response.data.status === 1) {
|
||||
// This is the DECLINED case
|
||||
const reason = response.data.rejection_reason || "The payment was declined by the gateway.";
|
||||
notify({
|
||||
title: "Payment Declined",
|
||||
text: reason,
|
||||
type: "warn", // Use 'warn' for declines instead of 'error'
|
||||
});
|
||||
|
||||
} else {
|
||||
// This handles unexpected responses from the backend.
|
||||
throw new Error("Invalid response from server during capture.");
|
||||
}
|
||||
|
||||
} catch (error: any) {
|
||||
// This 'catch' block now only handles network errors or server crashes (500 errors).
|
||||
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;
|
||||
}
|
||||
},
|
||||
|
||||
calculateCaptureAmount() {
|
||||
// Only calculate if we have both delivery order and pricing data
|
||||
if (this.deliveryOrder.id && this.pricing.price_for_customer) {
|
||||
const gallons = typeof this.gallonsDelivered === 'string' ? parseFloat(this.gallonsDelivered) : Number(this.gallonsDelivered) || 0;
|
||||
const pricePerGallon = typeof this.deliveryOrder.customer_price === 'string' ? parseFloat(this.deliveryOrder.customer_price) : Number(this.deliveryOrder.customer_price) || 0;
|
||||
let total = gallons * pricePerGallon;
|
||||
|
||||
// Add prime fee if applicable
|
||||
if (this.deliveryOrder.prime == 1) {
|
||||
const primeFee = typeof this.pricing.price_prime === 'string' ? parseFloat(this.pricing.price_prime) : Number(this.pricing.price_prime) || 0;
|
||||
total += primeFee;
|
||||
}
|
||||
|
||||
// Add same day fee if applicable
|
||||
if (this.deliveryOrder.same_day === 1) {
|
||||
const sameDayFee = typeof this.pricing.price_same_day === 'string' ? parseFloat(this.pricing.price_same_day) : Number(this.pricing.price_same_day) || 0;
|
||||
total += sameDayFee;
|
||||
}
|
||||
|
||||
this.captureAmount = total;
|
||||
}
|
||||
},
|
||||
|
||||
cancelCapture() {
|
||||
this.$router.push({ name: 'finalizeTicket', params: { id: this.$route.params.id } });
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
521
src/pages/pay/oil/pay_oil.vue
Executable file
521
src/pages/pay/oil/pay_oil.vue
Executable file
@@ -0,0 +1,521 @@
|
||||
<!-- src/pages/pay/pay_oil.vue -->
|
||||
<template>
|
||||
<div class="flex">
|
||||
|
||||
<div class="w-full px-4 md:px-10 py-4">
|
||||
<!-- Breadcrumbs & Title -->
|
||||
<div class="text-sm breadcrumbs">
|
||||
<ul>
|
||||
<li><router-link :to="{ name: 'home' }">Home</router-link></li>
|
||||
<!-- Add a link to the customer's profile if the data is available -->
|
||||
<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>Confirm Payment</li>
|
||||
</ul>
|
||||
</div>
|
||||
<h1 class="text-3xl font-bold mt-4 border-b border-gray-600 pb-2">
|
||||
Confirm Delivery #{{ delivery.id }}
|
||||
</h1>
|
||||
|
||||
<!-- Main Content Grid -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 my-6">
|
||||
|
||||
<!-- LEFT COLUMN: Customer and Delivery Details -->
|
||||
<div class="space-y-6">
|
||||
|
||||
<!-- Customer Info Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<div class="flex justify-between items-center mb-4">
|
||||
<div>
|
||||
<div class="text-xl font-bold">{{ customer.customer_first_name }} {{ customer.customer_last_name }}</div>
|
||||
<div class="text-sm text-gray-400">Account: {{ customer.account_number }}</div>
|
||||
</div>
|
||||
<router-link v-if="customer && customer.id" :to="{ name: 'customerProfile', params: { id: customer.id } }" class="btn btn-secondary btn-sm">
|
||||
View Profile
|
||||
</router-link>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<div>{{ customer.customer_address }}</div>
|
||||
<div v-if="customer.customer_apt && customer.customer_apt !== 'None'">Apt: {{ customer.customer_apt }}</div>
|
||||
<div>{{ customer.customer_town }}, {{ customer.customer_state === 0 ? 'MA' : 'RI' }} {{ customer.customer_zip }}</div>
|
||||
<div class="mt-2">{{ customer.customer_phone_number }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delivery Details Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Delivery Details</h3>
|
||||
<div class="space-y-3">
|
||||
<div>
|
||||
<div class="font-bold text-sm">Current Status</div>
|
||||
<div class="badge" :class="{ 'badge-info': delivery.delivery_status === 0, 'badge-success': delivery.delivery_status === 1, 'badge-warning': delivery.delivery_status > 1 }">
|
||||
<span v-if="delivery.delivery_status == 0">Waiting</span>
|
||||
<span v-else-if="delivery.delivery_status == 1">Delivered</span>
|
||||
<span v-else-if="delivery.delivery_status == 2">Out_for_Delivery</span>
|
||||
<span v-else-if="delivery.delivery_status == 3">Tomorrow_Delivery</span>
|
||||
<span v-else-if="delivery.delivery_status == 4">Partial Delivery</span>
|
||||
<span v-else-if="delivery.delivery_status == 5">Issue</span>
|
||||
<span v-else-if="delivery.delivery_status == 9">Pending</span>
|
||||
<span v-else-if="delivery.delivery_status == 10">Finalized</span>
|
||||
<span v-else>Pending</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-bold text-sm">Scheduled Date</div>
|
||||
<div>{{ delivery.expected_delivery_date }}</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-bold text-sm">Gallons Ordered</div>
|
||||
<div>
|
||||
<span v-if="delivery.customer_asked_for_fill == 1" class="badge badge-info">FILL (250 gal estimate)</span>
|
||||
<span v-else>{{ delivery.gallons_ordered }} Gallons</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- RIGHT COLUMN: Payment and Pricing Details -->
|
||||
<div class="space-y-6">
|
||||
|
||||
<!-- Payment & Pricing Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<h3 class="text-xl font-bold mb-4">Payment & Pricing</h3>
|
||||
<div class="space-y-4">
|
||||
<!-- Payment Method -->
|
||||
<div>
|
||||
<div class="font-bold text-sm">Payment Method</div>
|
||||
<div class="text-lg">
|
||||
<span v-if="delivery.payment_type == 0">Cash</span>
|
||||
<span v-else-if="delivery.payment_type == 1">Credit Card</span>
|
||||
<span v-else-if="delivery.payment_type == 2">Credit Card / Cash</span>
|
||||
<span v-else-if="delivery.payment_type == 3">Check</span>
|
||||
<span v-else-if="delivery.payment_type == 4">Other</span>
|
||||
</div>
|
||||
<!-- Show the selected card if payment is by credit -->
|
||||
<div v-if="delivery.payment_type == 1 || delivery.payment_type == 3" class="mt-2">
|
||||
<div v-for="card in credit_cards" :key="card.id">
|
||||
<div v-if="card.id === delivery.payment_card_id" class="bg-base-100 p-3 rounded-md text-sm">
|
||||
<div class="font-mono font-semibold">{{ card.type_of_card }} ending in {{ card.last_four_digits }}</div>
|
||||
<div>{{ card.name_on_card }}</div>
|
||||
<div>Expires: {{ card.expiration_month }}/{{ card.expiration_year }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pricing Breakdown -->
|
||||
<div class="space-y-2 pt-2">
|
||||
<div class="flex justify-between text-sm">
|
||||
<span>Price per Gallon</span>
|
||||
<span>${{ delivery.customer_price }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-sm">
|
||||
<span>Gallons Ordered</span>
|
||||
<span>
|
||||
<span v-if="delivery.customer_asked_for_fill == 1" class="badge badge-info">FILL (250 gal estimate)</span>
|
||||
<span v-else>{{ delivery.gallons_ordered }} Gallons</span>
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="delivery.prime == 1" class="flex justify-between text-sm">
|
||||
<span>Prime Fee</span>
|
||||
<span>+ ${{ pricing.price_prime }}</span>
|
||||
</div>
|
||||
<div v-if="delivery.emergency == 1" class="flex justify-between text-sm">
|
||||
<span>Emergency Fee</span>
|
||||
<span>+ ${{ pricing.price_emergency }}</span>
|
||||
</div>
|
||||
<div v-if="delivery.same_day == 1" class="flex justify-between text-sm">
|
||||
<span>Same Day Fee</span>
|
||||
<span>+ ${{ pricing.price_same_day }}</span>
|
||||
</div>
|
||||
<div v-if="promo_active" class="flex justify-between text-sm text-success">
|
||||
<span>Promo: {{ promo.name_of_promotion }}</span>
|
||||
<span>- ${{ discount }}</span>
|
||||
</div>
|
||||
|
||||
<div class="divider my-1"></div>
|
||||
|
||||
<div class="flex justify-between items-center">
|
||||
<span class="text-lg font-bold">Total to be Charged</span>
|
||||
<span class="text-2xl font-bold text-accent">
|
||||
${{ promo_active ? total_amount_after_discount : total_amount }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions Card -->
|
||||
<div class="bg-neutral rounded-lg p-5">
|
||||
<div class="flex flex-wrap gap-4 justify-between items-center">
|
||||
<!-- Pay Authorize Button -->
|
||||
<button class="btn btn-warning" @click="$router.push({ name: 'authorizePreauthCharge', params: { id: $route.params.id } })">
|
||||
Pay Authorize.net
|
||||
</button>
|
||||
<!-- A single confirm button is cleaner -->
|
||||
<button class="btn btn-primary" @click="checkoutOilUpdatePayment(delivery.payment_type)">
|
||||
Pay Tiger
|
||||
</button>
|
||||
<router-link v-if="delivery && delivery.id" :to="{ name: 'deliveryEdit', params: { id: delivery.id } }">
|
||||
<button class="btn btn-sm btn-ghost">Edit Delivery</button>
|
||||
</router-link>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Footer />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue'
|
||||
import axios from 'axios'
|
||||
import authHeader from '../../../services/auth.header'
|
||||
import Header from '../../../layouts/headers/headerauth.vue'
|
||||
import SideBar from '../../../layouts/sidebar/sidebar.vue'
|
||||
import Footer from '../../../layouts/footers/footer.vue'
|
||||
|
||||
import useValidate from "@vuelidate/core";
|
||||
import { notify } from "@kyvg/vue3-notification"
|
||||
import { minLength, required } from "@vuelidate/validators";
|
||||
|
||||
export default defineComponent({
|
||||
name: 'PayOil',
|
||||
|
||||
components: {
|
||||
Header,
|
||||
SideBar,
|
||||
Footer,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
v$: useValidate(),
|
||||
loaded: false,
|
||||
user: {
|
||||
user_id: 0,
|
||||
},
|
||||
delivery: {
|
||||
id: 0,
|
||||
customer_id: 0,
|
||||
customer_name: '',
|
||||
customer_address: '',
|
||||
customer_town: '',
|
||||
customer_state: 0,
|
||||
customer_zip: '',
|
||||
gallons_ordered: 0,
|
||||
customer_asked_for_fill: 0,
|
||||
gallons_delivered: 0,
|
||||
customer_filled: 0,
|
||||
delivery_status: 0,
|
||||
when_ordered: '',
|
||||
when_delivered: '',
|
||||
expected_delivery_date: '',
|
||||
automatic: 0,
|
||||
oil_id: 0,
|
||||
supplier_price: 0,
|
||||
customer_price: 0,
|
||||
customer_temperature: 0,
|
||||
dispatcher_notes: '',
|
||||
prime: 0,
|
||||
promo_id: 0,
|
||||
emergency: 0,
|
||||
same_day: 0,
|
||||
payment_type: 0,
|
||||
payment_card_id: 0,
|
||||
driver_employee_id: 0,
|
||||
driver_first_name: '',
|
||||
driver_last_name: '',
|
||||
pre_charge_amount: 0,
|
||||
total_price: 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: '',
|
||||
|
||||
}
|
||||
],
|
||||
|
||||
stripe: null,
|
||||
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: "",
|
||||
},
|
||||
promo_active: false,
|
||||
promo: {
|
||||
name_of_promotion: '',
|
||||
description: '',
|
||||
money_off_delivery: 0,
|
||||
text_on_ticket: ''
|
||||
},
|
||||
priceprime: 0,
|
||||
pricesameday: 0,
|
||||
priceemergency: 0,
|
||||
total_amount: 0,
|
||||
discount: 0,
|
||||
total_amount_after_discount: 0,
|
||||
}
|
||||
},
|
||||
validations() {
|
||||
return {
|
||||
CreateOilOrderForm: {
|
||||
basicInfo: {
|
||||
gallons_ordered: { required, minLength: minLength(1) },
|
||||
expected_delivery_date: { required },
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.userStatus()
|
||||
|
||||
},
|
||||
watch: {
|
||||
$route() {
|
||||
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.getOilOrder(this.$route.params.id)
|
||||
this.sumdelivery(this.$route.params.id);
|
||||
this.getOilPricing()
|
||||
this.updatestatus();
|
||||
|
||||
},
|
||||
|
||||
methods: {
|
||||
updatestatus() {
|
||||
let path = import.meta.env.VITE_BASE_URL + '/delivery/updatestatus';
|
||||
axios({
|
||||
method: 'get',
|
||||
url: path,
|
||||
headers: authHeader(),
|
||||
}).then((response: any) => {
|
||||
if (response.data.update)
|
||||
console.log("Updated Status of Deliveries")
|
||||
})
|
||||
},
|
||||
sumdelivery(delivery_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/total/" + delivery_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
console.log('%%%%%%%%%%%%%%%')
|
||||
console.log(response.data)
|
||||
|
||||
this.priceprime = response.data.priceprime;
|
||||
this.pricesameday = response.data.pricesameday;
|
||||
this.priceemergency = response.data.priceemergency;
|
||||
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(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing 1",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
getPromo(promo_id: any) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/promo/" + promo_id;
|
||||
axios({
|
||||
method: "get",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
headers: authHeader(),
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data) {
|
||||
this.promo = response.data
|
||||
|
||||
}
|
||||
})
|
||||
},
|
||||
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;
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get oil pricing 2",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
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",
|
||||
url: path,
|
||||
withCredentials: true,
|
||||
})
|
||||
.then((response: any) => {
|
||||
console.log("=== DEBUG: API Response:", response.data);
|
||||
if (response.data && response.data.ok) {
|
||||
console.log("=== DEBUG: Delivery data from API:", response.data.delivery);
|
||||
console.log("=== DEBUG: Delivery ID from API:", response.data.delivery?.id);
|
||||
this.delivery = response.data.delivery;
|
||||
console.log("=== DEBUG: Delivery object after assignment:", this.delivery);
|
||||
console.log("=== DEBUG: Delivery ID after assignment:", this.delivery.id);
|
||||
this.getCustomer(this.delivery.customer_id)
|
||||
this.getCreditCards(this.delivery.customer_id)
|
||||
if (this.delivery.promo_id != null) {
|
||||
this.getPromo(this.delivery.promo_id);
|
||||
this.promo_active = true;
|
||||
}
|
||||
} else {
|
||||
console.error("API Error:", response.data.error || "Failed to fetch delivery data.");
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error("=== DEBUG: API Error in getOilOrder:", error);
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not get 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
|
||||
})
|
||||
},
|
||||
checkoutOilUpdatePayment(payment_type: number) {
|
||||
let path = import.meta.env.VITE_BASE_URL + "/delivery/cash/" + this.delivery.id + '/' + payment_type;
|
||||
axios({
|
||||
method: "PUT",
|
||||
url: path,
|
||||
})
|
||||
.then((response: any) => {
|
||||
if (response.data.ok) {
|
||||
if (payment_type == 0) {
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "marked payment as cash (COD)",
|
||||
type: "success",
|
||||
});
|
||||
}
|
||||
if (payment_type == 1) {
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "marked payment as credit card",
|
||||
type: "success",
|
||||
});
|
||||
}
|
||||
|
||||
if (payment_type == 2) {
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "marked payment as cash (COD) and credit card partial payment",
|
||||
type: "success",
|
||||
});
|
||||
}
|
||||
if (payment_type == 3) {
|
||||
notify({
|
||||
title: "Success",
|
||||
text: "marked payment as check with credit card hold",
|
||||
type: "success",
|
||||
});
|
||||
}
|
||||
this.$router.push({ name: "customerProfile", params: { id: this.customer.id } });
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
notify({
|
||||
title: "Error",
|
||||
text: "Could not update wth cash",
|
||||
type: "error",
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
Reference in New Issue
Block a user