-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWaveCheckoutSession.php
More file actions
249 lines (231 loc) · 6.04 KB
/
Copy pathWaveCheckoutSession.php
File metadata and controls
249 lines (231 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
namespace Bow\Payment\IvoryCost\Wave;
/**
* Wave Checkout Session
* Represents a Wave checkout session object
*/
class WaveCheckoutSession
{
/**
* WaveCheckoutSession constructor
*
* @param string $id
* @param string $amount
* @param string $checkoutStatus
* @param string $paymentStatus
* @param string $currency
* @param string $businessName
* @param string $successUrl
* @param string $errorUrl
* @param string $waveLaunchUrl
* @param string|null $transactionId
* @param string|null $clientReference
* @param string|null $aggregatedMerchantId
* @param string|null $restrictPayerMobile
* @param array|null $lastPaymentError
* @param string $whenCreated
* @param string|null $whenCompleted
* @param string $whenExpires
*/
public function __construct(
private string $id,
private string $amount,
private string $checkoutStatus,
private string $paymentStatus,
private string $currency,
private string $businessName,
private string $successUrl,
private string $errorUrl,
private string $waveLaunchUrl,
private ?string $transactionId = null,
private ?string $clientReference = null,
private ?string $aggregatedMerchantId = null,
private ?string $restrictPayerMobile = null,
private ?array $lastPaymentError = null,
private string $whenCreated = '',
private ?string $whenCompleted = null,
private string $whenExpires = ''
) {
}
/**
* Create from API response
*
* @param array $data
* @return self
*/
public static function fromResponse(array $data): self
{
return new self(
id: $data['id'],
amount: $data['amount'],
checkoutStatus: $data['checkout_status'],
paymentStatus: $data['payment_status'],
currency: $data['currency'],
businessName: $data['business_name'],
successUrl: $data['success_url'],
errorUrl: $data['error_url'],
waveLaunchUrl: $data['wave_launch_url'],
transactionId: $data['transaction_id'] ?? null,
clientReference: $data['client_reference'] ?? null,
aggregatedMerchantId: $data['aggregated_merchant_id'] ?? null,
restrictPayerMobile: $data['restrict_payer_mobile'] ?? null,
lastPaymentError: $data['last_payment_error'] ?? null,
whenCreated: $data['when_created'],
whenCompleted: $data['when_completed'] ?? null,
whenExpires: $data['when_expires']
);
}
/**
* Get checkout session ID
*
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* Get amount
*
* @return string
*/
public function getAmount(): string
{
return $this->amount;
}
/**
* Get checkout status
*
* @return string
*/
public function getCheckoutStatus(): string
{
return $this->checkoutStatus;
}
/**
* Get payment status
*
* @return string
*/
public function getPaymentStatus(): string
{
return $this->paymentStatus;
}
/**
* Get Wave launch URL
*
* @return string
*/
public function getWaveLaunchUrl(): string
{
return $this->waveLaunchUrl;
}
/**
* Get transaction ID
*
* @return string|null
*/
public function getTransactionId(): ?string
{
return $this->transactionId;
}
/**
* Get client reference
*
* @return string|null
*/
public function getClientReference(): ?string
{
return $this->clientReference;
}
/**
* Check if checkout is open
*
* @return bool
*/
public function isOpen(): bool
{
return $this->checkoutStatus === 'open';
}
/**
* Check if checkout is complete
*
* @return bool
*/
public function isComplete(): bool
{
return $this->checkoutStatus === 'complete';
}
/**
* Check if checkout is expired
*
* @return bool
*/
public function isExpired(): bool
{
return $this->checkoutStatus === 'expired';
}
/**
* Check if payment succeeded
*
* @return bool
*/
public function isPaymentSucceeded(): bool
{
return $this->paymentStatus === 'succeeded';
}
/**
* Check if payment is processing
*
* @return bool
*/
public function isPaymentProcessing(): bool
{
return $this->paymentStatus === 'processing';
}
/**
* Check if payment is cancelled
*
* @return bool
*/
public function isPaymentCancelled(): bool
{
return $this->paymentStatus === 'cancelled';
}
/**
* Get last payment error
*
* @return array|null
*/
public function getLastPaymentError(): ?array
{
return $this->lastPaymentError;
}
/**
* Convert to array
*
* @return array
*/
public function toArray(): array
{
return [
'id' => $this->id,
'amount' => $this->amount,
'checkout_status' => $this->checkoutStatus,
'payment_status' => $this->paymentStatus,
'currency' => $this->currency,
'business_name' => $this->businessName,
'success_url' => $this->successUrl,
'error_url' => $this->errorUrl,
'wave_launch_url' => $this->waveLaunchUrl,
'transaction_id' => $this->transactionId,
'client_reference' => $this->clientReference,
'aggregated_merchant_id' => $this->aggregatedMerchantId,
'restrict_payer_mobile' => $this->restrictPayerMobile,
'last_payment_error' => $this->lastPaymentError,
'when_created' => $this->whenCreated,
'when_completed' => $this->whenCompleted,
'when_expires' => $this->whenExpires,
];
}
}