1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Paytrace: New payment flow (#74)

* pass livewirePaymentView & processPaymentView thru base driver

* add paymentData to the interface

* paytrace
This commit is contained in:
Benjamin Beganović 2024-08-09 01:08:36 +02:00 committed by GitHub
parent 398e9d3a98
commit 6351e209d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 100 additions and 5 deletions

View File

@ -18,12 +18,13 @@ use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\PaytracePaymentDriver;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class CreditCard
class CreditCard implements LivewireMethodInterface
{
use MakesHash;
@ -36,8 +37,7 @@ class CreditCard
public function authorizeView($data)
{
$data['client_key'] = $this->paytrace->getAuthToken();
$data['gateway'] = $this->paytrace;
$data = $this->paymentData($data);
return render('gateways.paytrace.authorize', $data);
}
@ -240,4 +240,23 @@ class CreditCard
return $this->paytrace->processUnsuccessfulTransaction($data);
}
/**
* @inheritDoc
*/
public function livewirePaymentView(array $data): string
{
return 'gateways.paytrace.pay_livewire';
}
/**
* @inheritDoc
*/
public function paymentData(array $data): array
{
$data['client_key'] = $this->paytrace->getAuthToken();
$data['gateway'] = $this->paytrace;
return $data;
}
}

View File

@ -8,6 +8,8 @@
* @license https://www.elastic.co/licensing/elastic-license
*/
import { instant, wait } from '../wait';
class PayTraceCreditCard {
constructor() {
this.clientKey = document.querySelector(
@ -217,7 +219,15 @@ class PayTraceCreditCard {
return this.handlePaymentWithToken(e);
});
if (Array.from(document.getElementsByClassName('toggle-payment-with-token')).length === 0 && !instant()) {
document.getElementById('toggle-payment-with-credit-card').click();
}
}
}
function boot() {
new PayTraceCreditCard().handle();
}
instant() ? boot() : wait('#paytrace-credit-card-payment').then(() => boot())

View File

@ -6,6 +6,7 @@
<meta name="ctrans-cvv" content="{{ ctrans('texts.cvv') }}">
<meta name="ctrans-card_number" content="{{ ctrans('texts.card_number') }}">
<meta name="ctrans-expires" content="{{ ctrans('texts.expires') }}">
<meta name="instant-payment" content="yes" />
@endsection
@section('gateway_content')

View File

@ -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="paytrace-credit-card-payment">
<meta name="paytrace-client-key" content="{{ $client_key }}">
<meta name="ctrans-cvv" content="{{ ctrans('texts.cvv') }}">
<meta name="ctrans-card_number" content="{{ ctrans('texts.card_number') }}">
<meta name="ctrans-expires" content="{{ ctrans('texts.expires') }}">
<form action="{{ route('client.payments.response') }}" method="post" id="server_response">
@csrf
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="company_gateway_id" value="{{ $gateway->company_gateway->id }}">
<input type="hidden" name="payment_method_id" value="1">
<input type="hidden" name="token" id="token" />
<input type="hidden" name="store_card" id="store_card" />
<input type="hidden" name="amount_with_fee" id="amount_with_fee" value="{{ $total['amount_with_fee'] }}" />
<input type="txt" id="HPF_Token" name="HPF_Token" hidden>
<input type="txt" id="enc_key" name="enc_key" hidden>
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')])
{{ 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->hashed_id }}" 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')
@component('portal.ninja2020.components.general.card-element-single')
<div class="items-center" id="paytrace--credit-card-container">
<div id="pt_hpf_form"></div>
</div>
@endcomponent
@include('portal.ninja2020.gateways.includes.pay_now')
</div>
@assets
@if($gateway->company_gateway->getConfigField('testMode'))
<script src='https://protect.sandbox.paytrace.com/js/protect.min.js'></script>
@else
<script src='https://protect.paytrace.com/js/protect.min.js'></script>
@endif
@vite('resources/js/clients/payments/paytrace-credit-card.js')
@endassets