mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 13:54:30 -04:00
Razorpay: New payment flow (#79)
* pass livewirePaymentView & processPaymentView thru base driver * add paymentData to the interface * razorpay
This commit is contained in:
parent
5a5abdaeed
commit
503e95a691
@ -19,6 +19,7 @@ use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\Common\LivewireMethodInterface;
|
||||
use App\PaymentDrivers\Common\MethodInterface;
|
||||
use App\PaymentDrivers\RazorpayPaymentDriver;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@ -26,7 +27,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Razorpay\Api\Errors\SignatureVerificationError;
|
||||
|
||||
class Hosted implements MethodInterface
|
||||
class Hosted implements MethodInterface, LivewireMethodInterface
|
||||
{
|
||||
protected RazorpayPaymentDriver $razorpay;
|
||||
|
||||
@ -67,23 +68,7 @@ class Hosted implements MethodInterface
|
||||
*/
|
||||
public function paymentView(array $data): View
|
||||
{
|
||||
$order = $this->razorpay->gateway->order->create([
|
||||
'currency' => $this->razorpay->client->currency()->code,
|
||||
'amount' => $this->razorpay->convertToRazorpayAmount((float) $this->razorpay->payment_hash->data->amount_with_fee),
|
||||
]);
|
||||
|
||||
$this->razorpay->payment_hash->withData('order_id', $order->id);
|
||||
$this->razorpay->payment_hash->withData('order_amount', $order->amount);
|
||||
|
||||
$data['gateway'] = $this->razorpay;
|
||||
|
||||
$data['options'] = [
|
||||
'key' => $this->razorpay->company_gateway->getConfigField('apiKey'),
|
||||
'amount' => $this->razorpay->convertToRazorpayAmount((float) $this->razorpay->payment_hash->data->amount_with_fee),
|
||||
'currency' => $this->razorpay->client->currency()->code,
|
||||
'name' => $this->razorpay->company_gateway->company->present()->name(),
|
||||
'order_id' => $order->id,
|
||||
];
|
||||
$data = $this->paymentData($data);
|
||||
|
||||
return render('gateways.razorpay.hosted.pay', $data);
|
||||
}
|
||||
@ -174,4 +159,38 @@ class Hosted implements MethodInterface
|
||||
|
||||
throw new PaymentFailed($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function livewirePaymentView(array $data): string
|
||||
{
|
||||
return 'gateways.razorpay.hosted.pay_livewire';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function paymentData(array $data): array
|
||||
{
|
||||
$order = $this->razorpay->gateway->order->create([
|
||||
'currency' => $this->razorpay->client->currency()->code,
|
||||
'amount' => $this->razorpay->convertToRazorpayAmount((float) $this->razorpay->payment_hash->data->amount_with_fee),
|
||||
]);
|
||||
|
||||
$this->razorpay->payment_hash->withData('order_id', $order->id);
|
||||
$this->razorpay->payment_hash->withData('order_amount', $order->amount);
|
||||
|
||||
$data['gateway'] = $this->razorpay;
|
||||
|
||||
$data['options'] = [
|
||||
'key' => $this->razorpay->company_gateway->getConfigField('apiKey'),
|
||||
'amount' => $this->razorpay->convertToRazorpayAmount((float) $this->razorpay->payment_hash->data->amount_with_fee),
|
||||
'currency' => $this->razorpay->client->currency()->code,
|
||||
'name' => $this->razorpay->company_gateway->company->present()->name(),
|
||||
'order_id' => $order->id,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
54
resources/js/clients/payments/razorpay-aio.js
vendored
54
resources/js/clients/payments/razorpay-aio.js
vendored
@ -8,29 +8,35 @@
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
let options = JSON.parse(
|
||||
document.querySelector('meta[name=razorpay-options]')?.content
|
||||
);
|
||||
import { wait, instant } from '../wait';
|
||||
|
||||
options.handler = function (response) {
|
||||
document.getElementById('razorpay_payment_id').value =
|
||||
response.razorpay_payment_id;
|
||||
document.getElementById('razorpay_signature').value =
|
||||
response.razorpay_signature;
|
||||
document.getElementById('server-response').submit();
|
||||
};
|
||||
function boot() {
|
||||
let options = JSON.parse(
|
||||
document.querySelector('meta[name=razorpay-options]')?.content
|
||||
);
|
||||
|
||||
options.handler = function (response) {
|
||||
document.getElementById('razorpay_payment_id').value =
|
||||
response.razorpay_payment_id;
|
||||
document.getElementById('razorpay_signature').value =
|
||||
response.razorpay_signature;
|
||||
document.getElementById('server-response').submit();
|
||||
};
|
||||
|
||||
options.modal = {
|
||||
ondismiss: function () {
|
||||
payNowButton.disabled = false;
|
||||
},
|
||||
};
|
||||
|
||||
let razorpay = new Razorpay(options);
|
||||
let payNowButton = document.getElementById('pay-now');
|
||||
|
||||
payNowButton.onclick = function (event) {
|
||||
payNowButton.disabled = true;
|
||||
|
||||
razorpay.open();
|
||||
};
|
||||
}
|
||||
|
||||
options.modal = {
|
||||
ondismiss: function () {
|
||||
payNowButton.disabled = false;
|
||||
},
|
||||
};
|
||||
|
||||
let razorpay = new Razorpay(options);
|
||||
let payNowButton = document.getElementById('pay-now');
|
||||
|
||||
payNowButton.onclick = function (event) {
|
||||
payNowButton.disabled = true;
|
||||
|
||||
razorpay.open();
|
||||
};
|
||||
instant() ? boot() : wait('#razorpay-hosted-payment').then(() => boot());
|
||||
|
@ -3,6 +3,7 @@ ctrans('texts.aio_checkout')])
|
||||
|
||||
@section('gateway_head')
|
||||
<meta name="razorpay-options" content="{{ \json_encode($options) }}">
|
||||
<meta name="instant-payment" content="yes" />
|
||||
@endsection
|
||||
|
||||
@section('gateway_content')
|
||||
|
Loading…
x
Reference in New Issue
Block a user