Skip to content

Commit

Permalink
Add fail url + Add payment failed messages (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbclaudio authored Feb 7, 2024
1 parent dff2c04 commit 2e4cc3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions config/rapidez/paynl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

return [
'fail_url' => 'cart',
'state_message' => [
'-63' => 'Payment rejected, try another option',
'-90' => 'Payment canceled'
]
];
9 changes: 7 additions & 2 deletions src/Http/Controllers/FinishTransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __invoke(Request $request)
{
$orderId = $request->get('orderId');
if (empty($orderId)) {
return redirect('cart');
return redirect(config('rapidez.paynl.fail_url', 'cart'));
}

$url = config('rapidez.magento_url').'/graphql';
Expand All @@ -31,7 +31,12 @@ public function __invoke(Request $request)
->object();

if (!optional($response->data->paynlFinishTransaction)->isSuccess ?? false) {
return redirect('cart');
$stateMessage = __(config('rapidez.paynl.state_message.'.$response->data->paynlFinishTransaction->state, 'Payment failed'));
return redirect(config('rapidez.paynl.fail_url', 'cart'))->with(['notification' => [
'message' => $stateMessage,
'type' => 'info',
'show' => true
]]);
}

return view('paynl::success');
Expand Down
6 changes: 6 additions & 0 deletions src/PaynlServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function boot()

$this->loadViewsFrom(__DIR__.'/../resources/views', 'paynl');

$this->mergeConfigFrom(__DIR__.'/../config/rapidez/paynl.php', 'rapidez.paynl');

if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/paynl'),
Expand All @@ -25,6 +27,10 @@ public function boot()
$this->publishes([
__DIR__.'/../resources/payment-icons' => public_path('payment-icons'),
], 'payment-icons');

$this->publishes([
__DIR__.'/../config/rapidez/paynl.php' => config_path('rapidez/paynl.php'),
], 'config');
}
}
}

0 comments on commit 2e4cc3e

Please sign in to comment.