add laravel 13 support
This commit is contained in:
29
src/Events/InvoicePurchasedEvent.php
Normal file
29
src/Events/InvoicePurchasedEvent.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Shetabit\Multipay\Contracts\DriverInterface;
|
||||
use Shetabit\Multipay\Invoice;
|
||||
|
||||
class InvoicePurchasedEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $driver;
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* InvoicePurchasedEvent constructor.
|
||||
*
|
||||
* @param DriverInterface $driver
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(DriverInterface $driver, Invoice $invoice)
|
||||
{
|
||||
$this->driver = $driver;
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
||||
33
src/Events/InvoiceVerifiedEvent.php
Normal file
33
src/Events/InvoiceVerifiedEvent.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Events;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Shetabit\Multipay\Contracts\DriverInterface;
|
||||
use Shetabit\Multipay\Contracts\ReceiptInterface;
|
||||
use Shetabit\Multipay\Invoice;
|
||||
|
||||
class InvoiceVerifiedEvent
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
public $receipt;
|
||||
public $driver;
|
||||
public $invoice;
|
||||
|
||||
/**
|
||||
* InvoiceVerifiedEvent constructor.
|
||||
*
|
||||
* @param ReceiptInterface $receipt
|
||||
* @param DriverInterface $driver
|
||||
* @param Invoice $invoice
|
||||
*/
|
||||
public function __construct(ReceiptInterface $receipt, DriverInterface $driver, Invoice $invoice)
|
||||
{
|
||||
$this->receipt = $receipt;
|
||||
$this->driver = $driver;
|
||||
$this->invoice = $invoice;
|
||||
}
|
||||
}
|
||||
38
src/Facade/Payment.php
Normal file
38
src/Facade/Payment.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Facade;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Shetabit\Multipay\Invoice;
|
||||
use Shetabit\Multipay\Contracts\ReceiptInterface;
|
||||
use Shetabit\Multipay\Payment as MultipayPayment;
|
||||
|
||||
/**
|
||||
* Class Payment
|
||||
*
|
||||
* @method static MultipayPayment config($key, $value = null)
|
||||
* @method static MultipayPayment callbackUrl($url = null)
|
||||
* @method static MultipayPayment resetCallbackUrl()
|
||||
* @method static MultipayPayment amount($amount)
|
||||
* @method static MultipayPayment detail($key, $value = null)
|
||||
* @method static MultipayPayment transactionId($id)
|
||||
* @method static MultipayPayment via($driver)
|
||||
* @method static MultipayPayment purchase(Invoice $invoice = null, $finalizeCallback = null)
|
||||
* @method static mixed pay($initializeCallback = null)
|
||||
* @method static ReceiptInterface verify($finalizeCallback = null)
|
||||
*
|
||||
* @package Shetabit\Payment\Facade
|
||||
* @see \Shetabit\Multipay\Payment
|
||||
*/
|
||||
class Payment extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getFacadeAccessor()
|
||||
{
|
||||
return 'shetabit-payment';
|
||||
}
|
||||
}
|
||||
130
src/Provider/PaymentServiceProvider.php
Normal file
130
src/Provider/PaymentServiceProvider.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Shetabit\Payment\Provider;
|
||||
|
||||
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;
|
||||
|
||||
class PaymentServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Perform post-registration booting of services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
$this->loadViewsFrom(__DIR__ . '/../../resources/views', 'shetabitPayment');
|
||||
|
||||
/**
|
||||
* Configurations that needs to be done by user.
|
||||
*/
|
||||
$this->publishes(
|
||||
[
|
||||
Payment::getDefaultConfigPath() => config_path('payment.php'),
|
||||
],
|
||||
'payment-config'
|
||||
);
|
||||
|
||||
/**
|
||||
* Views that needs to be modified by user.
|
||||
*/
|
||||
$this->publishes(
|
||||
[
|
||||
__DIR__ . '/../../resources/views' => resource_path('views/vendor/shetabitPayment'),
|
||||
],
|
||||
'payment-views'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register any package services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
// Merge default config with user's config
|
||||
$this->mergeConfigFrom(Payment::getDefaultConfigPath(), 'payment');
|
||||
|
||||
Request::overwrite('input', function ($key) {
|
||||
return \request($key);
|
||||
});
|
||||
|
||||
/**
|
||||
* Bind to service container.
|
||||
*/
|
||||
$this->app->bind('shetabit-payment', function () {
|
||||
$config = config('payment') ?? [];
|
||||
|
||||
return new Payment($config);
|
||||
});
|
||||
|
||||
$this->registerEvents();
|
||||
|
||||
// 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)),
|
||||
[
|
||||
'action' => $action,
|
||||
'inputs' => $inputs,
|
||||
'method' => $method,
|
||||
]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Laravel events.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerEvents()
|
||||
{
|
||||
Payment::addPurchaseListener(function ($driver, $invoice) {
|
||||
event(new InvoicePurchasedEvent($driver, $invoice));
|
||||
});
|
||||
|
||||
Payment::addVerifyListener(function ($reciept, $driver, $invoice) {
|
||||
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,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user