1 | <!DOCTYPE html>
|
---|
2 | <html lang="en">
|
---|
3 | <head>
|
---|
4 | <meta charset="UTF-8">
|
---|
5 | <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
---|
6 | <title>Complete Your Payment</title>
|
---|
7 | <link rel="stylesheet" href="/css/main.css">
|
---|
8 | <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
|
---|
9 | </head>
|
---|
10 | <body>
|
---|
11 |
|
---|
12 | <div id="app" class="transaction-container">
|
---|
13 | <div class="transaction-box">
|
---|
14 | <h2>Complete Your Payment</h2>
|
---|
15 |
|
---|
16 | <form @submit.prevent="processPayment">
|
---|
17 | <div class="input-group">
|
---|
18 | <label for="cardholder">Cardholder Name</label>
|
---|
19 | <input type="text" id="cardholder" v-model="cardholder" placeholder="John Doe" required />
|
---|
20 | </div>
|
---|
21 |
|
---|
22 | <div class="input-group">
|
---|
23 | <label for="cardNumber">Card Number</label>
|
---|
24 | <input type="text"
|
---|
25 | id="cardNumber"
|
---|
26 | v-model="cardNumber"
|
---|
27 | maxlength="16"
|
---|
28 | placeholder="1234 5678 9012 3456"
|
---|
29 | required />
|
---|
30 | </div>
|
---|
31 |
|
---|
32 | <div class="input-group">
|
---|
33 | <label for="expiration">Expiration Date</label>
|
---|
34 | <input type="month" id="expiration" v-model="expiration" required />
|
---|
35 | </div>
|
---|
36 |
|
---|
37 | <div class="button-group">
|
---|
38 | <button type="submit" class="pay-btn">Pay</button>
|
---|
39 | <button type="button" class="cancel-btn" @click="cancelPayment">Cancel</button>
|
---|
40 | </div>
|
---|
41 | </form>
|
---|
42 |
|
---|
43 | <div v-if="paymentSuccess" class="success-message">
|
---|
44 | ✅ Payment successful! Redirecting...
|
---|
45 | </div>
|
---|
46 | </div>
|
---|
47 | </div>
|
---|
48 |
|
---|
49 | <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
|
---|
50 | <script>
|
---|
51 |
|
---|
52 | new Vue({
|
---|
53 | el: '#app',
|
---|
54 | data: {
|
---|
55 | bookingId: '',
|
---|
56 | cardholder: '',
|
---|
57 | cardNumber: '',
|
---|
58 | expiration: '',
|
---|
59 | amount: '',
|
---|
60 | paymentSuccess: false
|
---|
61 | },
|
---|
62 | created(){
|
---|
63 | const urlParams = new URLSearchParams(window.location.search);
|
---|
64 | this.flightId = urlParams.get('flightId');
|
---|
65 | this.amount = urlParams.get('amount');
|
---|
66 | this.bookingId = urlParams.get('bookingId')
|
---|
67 |
|
---|
68 | const user = JSON.parse(localStorage.getItem("user"));
|
---|
69 | if(user){
|
---|
70 | this.userId = user.id;
|
---|
71 | }
|
---|
72 | },
|
---|
73 | methods: {
|
---|
74 | processPayment() {
|
---|
75 | const paymentDate = new Date().toISOString().split('T')[0];
|
---|
76 | const transaction = {
|
---|
77 | transaction_date:paymentDate,
|
---|
78 | payment_status:'SUCCESS',
|
---|
79 | amount:this.amount,
|
---|
80 | userId:this.userId,
|
---|
81 | bookingId:this.bookingId
|
---|
82 | };
|
---|
83 | console.log(transaction);
|
---|
84 | axios.post('api/payments', transaction)
|
---|
85 | .then(response => {
|
---|
86 | console.log(response.data);
|
---|
87 | this.paymentSuccess = true;
|
---|
88 | setTimeout(() => window.location.href = '/flights',2000);
|
---|
89 | })
|
---|
90 | .catch(error => console.error("Payment failed", error));
|
---|
91 | },
|
---|
92 | cancelPayment() {
|
---|
93 | window.location.href = '/flights'; // Redirecting to flight search on cancel
|
---|
94 | },
|
---|
95 | validateForm() {
|
---|
96 | return (
|
---|
97 | this.cardholder.trim().length > 0 &&
|
---|
98 | this.cardNumber.length === 16 &&
|
---|
99 | this.expiration.length > 0
|
---|
100 | );
|
---|
101 | }
|
---|
102 | }
|
---|
103 | });
|
---|
104 | </script>
|
---|
105 |
|
---|
106 | </body>
|
---|
107 | </html>
|
---|