Skip to content

Commit 869df15

Browse files
authored
fixed bug in loading view file redirectForm.blade.php (#270)
* fixed bug in loading view file `redirectForm.blade.php` && update README.md file and added docs for publishing vendor files * Code compression in method register from service provider * change style code
1 parent 299e2d9 commit 869df15

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ Via Composer
9595
$ composer require shetabit/payment
9696
```
9797

98+
## Publish Vendor Files
99+
100+
- **publish configuration files:**
101+
``` bash
102+
php artisan vendor:publish --tag=payment-config
103+
```
104+
105+
- **publish views for customization:**
106+
``` bash
107+
php artisan vendor:publish --tag=payment-views
108+
```
109+
98110
## Configure
99111

100112
If you are using `Laravel 5.5` or higher then you don't need to add the provider and alias. (Skip to b)
@@ -115,8 +127,6 @@ a. In your `config/app.php` file add these two lines.
115127
],
116128
```
117129

118-
b. then run `php artisan vendor:publish` to publish `config/payment.php` file in your config directory.
119-
120130
In the config file you can set the `default driver` to use for all your payments. But you can also change the driver at runtime.
121131

122132
Choose what gateway you would like to use in your application. Then make that as default driver so that you don't have to specify that everywhere. But, you can also use multiple gateways in a project.

src/Provider/PaymentServiceProvider.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace Shetabit\Payment\Provider;
44

5-
use Shetabit\Multipay\Payment;
6-
use Illuminate\Support\ServiceProvider;
5+
use Illuminate\Contracts\Foundation\Application;
6+
use Illuminate\Contracts\View\Factory;
77
use Illuminate\Support\Facades\Blade;
8+
use Illuminate\Support\ServiceProvider;
9+
use Illuminate\View\View;
10+
use Shetabit\Multipay\Payment;
811
use Shetabit\Multipay\Request;
912
use Shetabit\Payment\Events\InvoicePurchasedEvent;
1013
use Shetabit\Payment\Events\InvoiceVerifiedEvent;
@@ -18,7 +21,7 @@ class PaymentServiceProvider extends ServiceProvider
1821
*/
1922
public function boot()
2023
{
21-
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'shetabitPayment');
24+
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'shetabitPayment');
2225

2326
/**
2427
* Configurations that needs to be done by user.
@@ -35,9 +38,9 @@ public function boot()
3538
*/
3639
$this->publishes(
3740
[
38-
__DIR__.'/../../resources/views' => resource_path('views/vendor/shetabitPayment')
41+
__DIR__ . '/../../resources/views' => resource_path('views/vendor/shetabitPayment'),
3942
],
40-
'views'
43+
'payment-views'
4144
);
4245
}
4346

@@ -65,6 +68,9 @@ public function register()
6568

6669
// use blade to render redirection form
6770
Payment::setRedirectionFormViewRenderer(function ($view, $action, $inputs, $method) {
71+
if ($this->existCustomRedirectFormView()) {
72+
return $this->loadNormalRedirectForm($action, $inputs, $method);
73+
}
6874
return Blade::render(
6975
str_replace('</form>', '@csrf</form>', file_get_contents($view)),
7076
[
@@ -91,4 +97,31 @@ public function registerEvents()
9197
event(new InvoiceVerifiedEvent($reciept, $driver, $invoice));
9298
});
9399
}
100+
101+
/**
102+
* Checks whether the user has customized the view file called `redirectForm.blade.php` or not
103+
*
104+
* @return bool
105+
*/
106+
private function existCustomRedirectFormView()
107+
{
108+
return file_exists(resource_path('views/vendor/shetabitPayment') . '/redirectForm.blade.php');
109+
}
110+
111+
/**
112+
* @param $action
113+
* @param $inputs
114+
* @param $method
115+
* @return Application|Factory|View
116+
*/
117+
private function loadNormalRedirectForm($action, $inputs, $method)
118+
{
119+
return view('shetabitPayment::redirectForm')->with(
120+
[
121+
'action' => $action,
122+
'inputs' => $inputs,
123+
'method' => $method,
124+
]
125+
);
126+
}
94127
}

0 commit comments

Comments
 (0)