PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.2.7
Yatra – Travel Booking & Tour Operator Software v3.0.2.7
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / app / PaymentGateways / Gateways / PayLater / PayLaterGateway.php

PayLaterGateway.php in Yatra – Travel Booking & Tour Operator Software 3.0.2.7, at app/PaymentGateways/Gateways/PayLater/PayLaterGateway.php

135 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\PaymentGateways\Gateways\PayLater;
6
7 use Yatra\PaymentGateways\AbstractPaymentGateway;
8
9 class PayLaterGateway extends AbstractPaymentGateway
10 {
11 protected string $id = 'pay_later';
12 protected string $title = 'Book Now, Pay Later';
13 protected string $description = 'Reserve now and pay before the trip';
14 protected string $icon = 'pay-later.svg';
15 protected bool $isOffline = true;
16 protected array $supports = ['pay_later', 'reservation'];
17
18 public function getConfigFields(): array
19 {
20 return [
21 [
22 'id' => 'payment_deadline_days',
23 'type' => 'number',
24 'label' => __('Payment Deadline (Days Before Trip)', 'yatra'),
25 'description' => __('Number of days before the trip when full payment is required', 'yatra'),
26 'placeholder' => '7',
27 'default' => '7',
28 'min' => 1,
29 'max' => 60,
30 ],
31 [
32 'id' => 'auto_cancel_days',
33 'type' => 'number',
34 'label' => __('Auto-Cancel After (Days)', 'yatra'),
35 'description' => __('Automatically cancel unpaid bookings after this many days (0 to disable)', 'yatra'),
36 'placeholder' => '3',
37 'default' => '3',
38 'min' => 0,
39 'max' => 30,
40 ],
41 [
42 'id' => 'require_deposit',
43 'type' => 'checkbox',
44 'label' => __('Require Small Deposit', 'yatra'),
45 'description' => __('Collect a small deposit to confirm the booking', 'yatra'),
46 'default' => false,
47 ],
48 [
49 'id' => 'deposit_amount',
50 'type' => 'number',
51 'label' => __('Deposit Amount (%)', 'yatra'),
52 'description' => __('Percentage of total amount required as deposit', 'yatra'),
53 'placeholder' => '10',
54 'default' => '10',
55 'min' => 1,
56 'max' => 50,
57 'condition' => 'require_deposit',
58 ],
59 [
60 'id' => 'reminder_days',
61 'type' => 'text',
62 'label' => __('Payment Reminder Days', 'yatra'),
63 'description' => __('Send payment reminders X days before deadline (comma-separated, e.g., 7,3,1)', 'yatra'),
64 'placeholder' => '7,3,1',
65 'default' => '7,3,1',
66 ],
67 ];
68 }
69
70 public function processPayment(array $paymentData): array
71 {
72 $bookingId = $paymentData['booking_id'] ?? 0;
73 $tripDate = $paymentData['trip_date'] ?? '';
74 $amount = (float) ($paymentData['amount'] ?? 0);
75
76 $deadlineDays = (int) ($this->config['payment_deadline_days'] ?? 7);
77 $requireDeposit = !empty($this->config['require_deposit']);
78 $depositPercentage = (int) ($this->config['deposit_amount'] ?? 10);
79
80 // Calculate payment deadline
81 $paymentDeadline = null;
82 if (!empty($tripDate)) {
83 $tripDateTime = strtotime($tripDate);
84 $paymentDeadline = date('Y-m-d', strtotime("-{$deadlineDays} days", $tripDateTime));
85 }
86
87 $depositAmount = 0;
88 if ($requireDeposit) {
89 $depositAmount = ($amount * $depositPercentage) / 100;
90 }
91
92 return [
93 'success' => true,
94 'payment_method' => 'pay_later',
95 'status' => $requireDeposit ? 'deposit_required' : 'reserved',
96 'booking_id' => $bookingId,
97 'total_amount' => $amount,
98 'deposit_required' => $requireDeposit,
99 'deposit_amount' => $depositAmount,
100 'remaining_amount' => $amount - $depositAmount,
101 'payment_deadline' => $paymentDeadline,
102 'deadline_days' => $deadlineDays,
103 'message' => $requireDeposit
104 ? sprintf(__('A deposit of %s is required to confirm your booking. Full payment is due %d days before your trip.', 'yatra'),
105 number_format($depositAmount, 2), $deadlineDays)
106 : sprintf(__('Your booking is reserved! Full payment of %s is due %d days before your trip.', 'yatra'),
107 number_format($amount, 2), $deadlineDays),
108 ];
109 }
110
111 public function verifyPayment(string $transactionId): array
112 {
113 // Pay later doesn't need verification at checkout
114 return ['success' => true, 'status' => 'reserved'];
115 }
116
117 /**
118 * Get auto-cancel days setting
119 */
120 public function getAutoCancelDays(): int
121 {
122 return (int) ($this->config['auto_cancel_days'] ?? 3);
123 }
124
125 /**
126 * Get reminder days as array
127 */
128 public function getReminderDays(): array
129 {
130 $reminderStr = $this->config['reminder_days'] ?? '7,3,1';
131 return array_map('intval', array_filter(explode(',', $reminderStr)));
132 }
133 }
134
135