@@ -23,7 +23,7 @@ class CompletePurchaseMiddleware
23
23
* @param \Closure $next
24
24
* @return mixed
25
25
*/
26
- public function handle ($ request , Closure $ next , string $ gateway , $ successHandle , $ failureHandle = null )
26
+ public function handle ($ request , Closure $ next , string $ gateway , $ failureHandle = null )
27
27
{
28
28
/** @var AbstractGateway $gateway */
29
29
$ gateway = app ('omnipay ' )->gateway ($ gateway );
@@ -34,14 +34,16 @@ public function handle($request, Closure $next, string $gateway, $successHandle,
34
34
35
35
$ response = $ gateway ->completePurchase ()->send ();
36
36
37
- if ($ response ->isSuccessful ()) {
38
- return app ()->call ($ successHandle , [$ response ]);
39
- }
37
+ $ request ->attributes ->set ('completePurchaseResponse ' , $ response );
38
+
39
+ if (!$ response ->isSuccessful ()) {
40
+ if ($ failureHandle ) {
41
+ return app ()->call ($ failureHandle , [$ response ]);
42
+ }
40
43
41
- if ($ failureHandle ) {
42
- return app ()->call ($ failureHandle , [$ response ]);
44
+ throw new BadRequestHttpException ('Bad request ' );
43
45
}
44
46
45
- throw new BadRequestHttpException ( ' Bad request' );
47
+ return $ next ( $ request );
46
48
}
47
49
}
0 commit comments