mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Payfast: New payment flow (#78)
* pass livewirePaymentView & processPaymentView thru base driver * add paymentData to the interface * payfast
This commit is contained in:
parent
dd3e98eb30
commit
398e9d3a98
@ -18,12 +18,13 @@ use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\Common\LivewireMethodInterface;
|
||||
use App\PaymentDrivers\PayFastPaymentDriver;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CreditCard
|
||||
class CreditCard implements LivewireMethodInterface
|
||||
{
|
||||
public $payfast;
|
||||
|
||||
@ -158,24 +159,9 @@ class CreditCard
|
||||
|
||||
public function paymentView($data)
|
||||
{
|
||||
$payfast_data = [
|
||||
'merchant_id' => $this->payfast->company_gateway->getConfigField('merchantId'),
|
||||
'merchant_key' => $this->payfast->company_gateway->getConfigField('merchantKey'),
|
||||
'return_url' => route('client.payments.index'),
|
||||
'cancel_url' => route('client.payment_methods.index'),
|
||||
'notify_url' => $this->payfast->genericWebhookUrl(),
|
||||
'm_payment_id' => $data['payment_hash'],
|
||||
'amount' => $data['amount_with_fee'],
|
||||
'item_name' => 'purchase',
|
||||
'item_description' => ctrans('texts.invoices').': '.collect($data['invoices'])->pluck('invoice_number'),
|
||||
'passphrase' => $this->payfast->company_gateway->getConfigField('passphrase'),
|
||||
];
|
||||
$data = $this->paymentData($data);
|
||||
|
||||
$payfast_data['signature'] = $this->payfast->generateSignature($payfast_data);
|
||||
$payfast_data['gateway'] = $this->payfast;
|
||||
$payfast_data['payment_endpoint_url'] = $this->payfast->endpointUrl();
|
||||
|
||||
return render('gateways.payfast.pay', array_merge($data, $payfast_data));
|
||||
return render('gateways.payfast.pay', array_merge($data));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -263,4 +249,36 @@ class CreditCard
|
||||
|
||||
throw new PaymentFailed('Failed to process the payment.', 500);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function livewirePaymentView(array $data): string
|
||||
{
|
||||
return 'gateways.payfast.pay_livewire';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function paymentData(array $data): array
|
||||
{
|
||||
$payfast_data = [
|
||||
'merchant_id' => $this->payfast->company_gateway->getConfigField('merchantId'),
|
||||
'merchant_key' => $this->payfast->company_gateway->getConfigField('merchantKey'),
|
||||
'return_url' => route('client.payments.index'),
|
||||
'cancel_url' => route('client.payment_methods.index'),
|
||||
'notify_url' => $this->payfast->genericWebhookUrl(),
|
||||
'm_payment_id' => $data['payment_hash'],
|
||||
'amount' => $data['amount_with_fee'],
|
||||
'item_name' => 'purchase',
|
||||
'item_description' => ctrans('texts.invoices').': '.collect($data['invoices'])->pluck('invoice_number'),
|
||||
'passphrase' => $this->payfast->company_gateway->getConfigField('passphrase'),
|
||||
];
|
||||
|
||||
$payfast_data['signature'] = $this->payfast->generateSignature($payfast_data);
|
||||
$payfast_data['gateway'] = $this->payfast;
|
||||
$payfast_data['payment_endpoint_url'] = $this->payfast->endpointUrl();
|
||||
|
||||
return array_merge($data, $payfast_data);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
@section('gateway_head')
|
||||
<meta name="contact-email" content="{{ $contact->email }}">
|
||||
<meta name="client-postal-code" content="{{ $contact->client->postal_code }}">
|
||||
<meta name="instant-payment" content="yes" />
|
||||
@endsection
|
||||
|
||||
@section('gateway_content')
|
||||
|
@ -0,0 +1,65 @@
|
||||
<div class="rounded-lg border bg-card text-card-foreground shadow-sm overflow-hidden py-5 bg-white sm:gap-4"
|
||||
id="payfast-credit-card-payment">
|
||||
<meta name="contact-email" content="{{ $contact->email }}">
|
||||
<meta name="client-postal-code" content="{{ $contact->client->postal_code }}">
|
||||
|
||||
<form action="{{ $payment_endpoint_url }}" method="post" id="server_response">
|
||||
<input type="hidden" name="merchant_id" value="{{ $merchant_id }}">
|
||||
<input type="hidden" name="merchant_key" value="{{ $merchant_key }}">
|
||||
<input type="hidden" name="return_url" value="{{ $return_url }}">
|
||||
<input type="hidden" name="cancel_url" value="{{ $cancel_url }}">
|
||||
<input type="hidden" name="notify_url" value="{{ $notify_url }}">
|
||||
<input type="hidden" name="m_payment_id" value="{{ $m_payment_id }}">
|
||||
<input type="hidden" name="amount" value="{{ $amount }}">
|
||||
<input type="hidden" name="item_name" value="{{ $item_name }}">
|
||||
<input type="hidden" name="item_description" value="{{ $item_description}}">
|
||||
<input type="hidden" name="passphrase" value="{{ $passphrase }}">
|
||||
<input type="hidden" name="signature" value="{{ $signature }}">
|
||||
|
||||
<div class="alert alert-failure mb-4" hidden id="errors"></div>
|
||||
|
||||
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.method')])
|
||||
{{ ctrans('texts.credit_card') }}
|
||||
@endcomponent
|
||||
|
||||
@include('portal.ninja2020.gateways.includes.payment_details')
|
||||
|
||||
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')])
|
||||
@if(count($tokens) > 0)
|
||||
@foreach($tokens as $token)
|
||||
<label class="mr-4">
|
||||
<input
|
||||
type="radio"
|
||||
data-token="{{ $token->token }}"
|
||||
name="payment-type"
|
||||
class="form-radio cursor-pointer toggle-payment-with-token"/>
|
||||
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
|
||||
</label>
|
||||
@endforeach
|
||||
@endisset
|
||||
|
||||
<label>
|
||||
<input
|
||||
type="radio"
|
||||
id="toggle-payment-with-credit-card"
|
||||
class="form-radio cursor-pointer"
|
||||
name="payment-type"
|
||||
checked/>
|
||||
<span class="ml-1 cursor-pointer">{{ __('texts.new_card') }}</span>
|
||||
</label>
|
||||
@endcomponent
|
||||
|
||||
@include('portal.ninja2020.gateways.includes.save_card')
|
||||
|
||||
@include('portal.ninja2020.gateways.includes.pay_now')
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@script
|
||||
<script>
|
||||
document.getElementById('pay-now').addEventListener('click', function() {
|
||||
document.getElementById('server_response').submit();
|
||||
});
|
||||
</script>
|
||||
@endscript
|
Loading…
x
Reference in New Issue
Block a user