8
8
use Lunar \Models \Transaction ;
9
9
use Lunar \Opayo \Facades \Opayo ;
10
10
use Lunar \Opayo \Responses \PaymentAuthorize ;
11
+ use Lunar \Opayo \Responses \ThreeDSecureResponse ;
11
12
use Lunar \PaymentTypes \AbstractPayment ;
12
13
13
14
class OpayoPaymentType extends AbstractPayment
@@ -32,7 +33,7 @@ public function __construct()
32
33
*
33
34
* @return \Lunar\Base\DataTransferObjects\PaymentAuthorize
34
35
*/
35
- public function authorize (): PaymentAuthorize
36
+ public function authorize (): PaymentAuthorize | ThreeDSecureResponse
36
37
{
37
38
if (! $ this ->order ) {
38
39
if (! $ this ->order = $ this ->cart ->order ) {
@@ -59,6 +60,7 @@ public function authorize(): PaymentAuthorize
59
60
60
61
$ response = Opayo::api ()->post ('transactions ' , $ payload );
61
62
63
+
62
64
if (! $ response ->successful ()) {
63
65
return new PaymentAuthorize (
64
66
success: false ,
@@ -69,7 +71,7 @@ public function authorize(): PaymentAuthorize
69
71
$ response = $ response ->object ();
70
72
71
73
if ($ response ->status == '3DAuth ' ) {
72
- return new PaymentAuthorize (
74
+ return new ThreeDSecureResponse (
73
75
success: true ,
74
76
status: Opayo::THREE_D_AUTH ,
75
77
acsUrl: $ response ->acsUrl ,
@@ -88,8 +90,11 @@ public function authorize(): PaymentAuthorize
88
90
success: $ successful
89
91
);
90
92
93
+ $ status = $ this ->data ['status ' ] ?? null ;
94
+
91
95
if ($ successful ) {
92
96
$ this ->order ->update ([
97
+ 'status ' => $ status ?? ($ this ->config ['authorized ' ] ?? null ),
93
98
'placed_at ' => now (),
94
99
]);
95
100
}
@@ -160,6 +165,7 @@ public function refund(Transaction $transaction, int $amount = 0, $notes = null)
160
165
161
166
$ data = $ response ->object ();
162
167
168
+
163
169
if (! $ response ->successful () || isset ($ data ->code )) {
164
170
return new PaymentRefund (
165
171
success: false ,
@@ -189,7 +195,6 @@ public function refund(Transaction $transaction, int $amount = 0, $notes = null)
189
195
/**
190
196
* Handle the Three D Secure response.
191
197
*
192
- * @return void
193
198
*/
194
199
public function threedsecure ()
195
200
{
@@ -222,6 +227,16 @@ public function threedsecure()
222
227
$ data = $ response ->object ();
223
228
224
229
if (($ data ->statusCode ?? null ) == '4026 ' ) {
230
+ $ this ->order ->transactions ()->create ([
231
+ 'success ' => false ,
232
+ 'type ' => 'capture ' ,
233
+ 'driver ' => 'opayo ' ,
234
+ 'amount ' => $ data ->amount ?->totalAmount ?: 0 ,
235
+ 'reference ' => $ data ->transactionId ,
236
+ 'status ' => $ data ->status ,
237
+ 'notes ' => $ data ->statusDetail ,
238
+ 'card_type ' => 'unknown ' ,
239
+ ]);
225
240
return new PaymentAuthorize (
226
241
success: false ,
227
242
status: Opayo::THREED_SECURE_FAILED
@@ -244,8 +259,12 @@ public function threedsecure()
244
259
success: $ successful
245
260
);
246
261
262
+ $ status = $ this ->data ['status ' ] ?? null ;
263
+
264
+
247
265
if ($ successful ) {
248
266
$ this ->order ->update ([
267
+ 'status ' => $ status ?? ($ this ->config ['authorized ' ] ?? null ),
249
268
'placed_at ' => now (),
250
269
]);
251
270
}
@@ -322,9 +341,9 @@ protected function getAuthPayload($type = 'Payment')
322
341
'transType ' => 'GoodsAndServicePurchase ' ,
323
342
'browserLanguage ' => $ this ->data ['browserLanguage ' ] ?? null ,
324
343
'challengeWindowSize ' => $ this ->data ['challengeWindowSize ' ] ?? null ,
325
- 'browserIP ' => $ this ->data ['ip ' ] ?? null ,
344
+ 'browserIP ' => $ this ->data ['browserIP ' ] ?? null ,
326
345
'notificationURL ' => route ('opayo.threed.response ' ),
327
- 'browserAcceptHeader ' => $ this ->data ['accept ' ] ?? null ,
346
+ 'browserAcceptHeader ' => $ this ->data ['browserAcceptHeader ' ] ?? null ,
328
347
'browserJavascriptEnabled ' => true ,
329
348
'browserUserAgent ' => $ this ->data ['browserUserAgent ' ] ?? null ,
330
349
'browserJavaEnabled ' => (bool ) ($ this ->data ['browserJavaEnabled ' ] ?? null ),
0 commit comments