Skip to content

Commit

Permalink
fixed bug in loading view file redirectForm.blade.php (#270)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mohamadtsn authored Mar 5, 2023
1 parent 299e2d9 commit 869df15
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ Via Composer
$ composer require shetabit/payment
```

## Publish Vendor Files

- **publish configuration files:**
``` bash
php artisan vendor:publish --tag=payment-config
```

- **publish views for customization:**
``` bash
php artisan vendor:publish --tag=payment-views
```

## Configure

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

b. then run `php artisan vendor:publish` to publish `config/payment.php` file in your config directory.

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.

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.
Expand Down
43 changes: 38 additions & 5 deletions src/Provider/PaymentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Shetabit\Payment\Provider;

use Shetabit\Multipay\Payment;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\View;
use Shetabit\Multipay\Payment;
use Shetabit\Multipay\Request;
use Shetabit\Payment\Events\InvoicePurchasedEvent;
use Shetabit\Payment\Events\InvoiceVerifiedEvent;
Expand All @@ -18,7 +21,7 @@ class PaymentServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'shetabitPayment');
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'shetabitPayment');

/**
* Configurations that needs to be done by user.
Expand All @@ -35,9 +38,9 @@ public function boot()
*/
$this->publishes(
[
__DIR__.'/../../resources/views' => resource_path('views/vendor/shetabitPayment')
__DIR__ . '/../../resources/views' => resource_path('views/vendor/shetabitPayment'),
],
'views'
'payment-views'
);
}

Expand Down Expand Up @@ -65,6 +68,9 @@ public function register()

// use blade to render redirection form
Payment::setRedirectionFormViewRenderer(function ($view, $action, $inputs, $method) {
if ($this->existCustomRedirectFormView()) {
return $this->loadNormalRedirectForm($action, $inputs, $method);
}
return Blade::render(
str_replace('</form>', '@csrf</form>', file_get_contents($view)),
[
Expand All @@ -91,4 +97,31 @@ public function registerEvents()
event(new InvoiceVerifiedEvent($reciept, $driver, $invoice));
});
}

/**
* Checks whether the user has customized the view file called `redirectForm.blade.php` or not
*
* @return bool
*/
private function existCustomRedirectFormView()
{
return file_exists(resource_path('views/vendor/shetabitPayment') . '/redirectForm.blade.php');
}

/**
* @param $action
* @param $inputs
* @param $method
* @return Application|Factory|View
*/
private function loadNormalRedirectForm($action, $inputs, $method)
{
return view('shetabitPayment::redirectForm')->with(
[
'action' => $action,
'inputs' => $inputs,
'method' => $method,
]
);
}
}

0 comments on commit 869df15

Please sign in to comment.