mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Square: New payment flow (#75)
* pass livewirePaymentView & processPaymentView thru base driver * square
This commit is contained in:
parent
b63e413d6e
commit
dc401a4da6
@ -21,6 +21,7 @@ use App\Models\Invoice;
|
|||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentType;
|
use App\Models\PaymentType;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
|
use App\PaymentDrivers\Common\LivewireMethodInterface;
|
||||||
use App\PaymentDrivers\Common\MethodInterface;
|
use App\PaymentDrivers\Common\MethodInterface;
|
||||||
use App\PaymentDrivers\SquarePaymentDriver;
|
use App\PaymentDrivers\SquarePaymentDriver;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
@ -29,7 +30,7 @@ use Illuminate\Http\Request;
|
|||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use Square\Http\ApiResponse;
|
use Square\Http\ApiResponse;
|
||||||
|
|
||||||
class CreditCard implements MethodInterface
|
class CreditCard implements MethodInterface, LivewireMethodInterface
|
||||||
{
|
{
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
|
||||||
@ -64,10 +65,7 @@ class CreditCard implements MethodInterface
|
|||||||
|
|
||||||
public function paymentView($data)
|
public function paymentView($data)
|
||||||
{
|
{
|
||||||
$data['gateway'] = $this->square_driver;
|
$data = $this->paymentData($data);
|
||||||
$data['amount'] = $this->square_driver->payment_hash->data->amount_with_fee;
|
|
||||||
$data['currencyCode'] = $this->square_driver->client->getCurrencyCode();
|
|
||||||
$data['square_contact'] = $this->buildClientObject();
|
|
||||||
|
|
||||||
return render('gateways.square.credit_card.pay', $data);
|
return render('gateways.square.credit_card.pay', $data);
|
||||||
}
|
}
|
||||||
@ -238,5 +236,24 @@ class CreditCard implements MethodInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function livewirePaymentView(array $data): string
|
||||||
|
{
|
||||||
|
return 'gateways.square.credit_card.pay_livewire';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function paymentData(array $data): array
|
||||||
|
{
|
||||||
|
$data['gateway'] = $this->square_driver;
|
||||||
|
$data['amount'] = $this->square_driver->payment_hash->data->amount_with_fee;
|
||||||
|
$data['currencyCode'] = $this->square_driver->client->getCurrencyCode();
|
||||||
|
$data['square_contact'] = $this->buildClientObject();
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
* @license https://www.elastic.co/licensing/elastic-license
|
* @license https://www.elastic.co/licensing/elastic-license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { wait, instant } from '../wait';
|
||||||
|
|
||||||
class SquareCreditCard {
|
class SquareCreditCard {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.appId = document.querySelector('meta[name=square-appId]').content;
|
this.appId = document.querySelector('meta[name=square-appId]').content;
|
||||||
@ -180,4 +182,9 @@ class SquareCreditCard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
new SquareCreditCard().handle();
|
function boot() {
|
||||||
|
new SquareCreditCard().handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
instant() ? boot() : wait('#square-credit-card-payment').then(() => boot());
|
||||||
|
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
<meta name="square_contact" content="{{ json_encode($square_contact) }}">
|
<meta name="square_contact" content="{{ json_encode($square_contact) }}">
|
||||||
<meta name="amount" content="{{ $amount }}">
|
<meta name="amount" content="{{ $amount }}">
|
||||||
<meta name="currencyCode" content="{{ $currencyCode }}">
|
<meta name="currencyCode" content="{{ $currencyCode }}">
|
||||||
|
<meta name="instant-payment" content="yes" />
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.loader {
|
.loader {
|
||||||
border-top-color: #3498db;
|
border-top-color: #3498db;
|
||||||
|
@ -0,0 +1,113 @@
|
|||||||
|
<div class="rounded-lg border bg-card text-card-foreground shadow-sm overflow-hidden py-5 bg-white sm:gap-4"
|
||||||
|
id="square-credit-card-payment">
|
||||||
|
<meta name="square-appId" content="{{ $gateway->company_gateway->getConfigField('applicationId') }}">
|
||||||
|
<meta name="square-locationId" content="{{ $gateway->company_gateway->getConfigField('locationId') }}">
|
||||||
|
<meta name="square_contact" content="{{ json_encode($square_contact) }}">
|
||||||
|
<meta name="amount" content="{{ $amount }}">
|
||||||
|
<meta name="currencyCode" content="{{ $currencyCode }}">
|
||||||
|
<style>
|
||||||
|
.loader {
|
||||||
|
border-top-color: #3498db;
|
||||||
|
-webkit-animation: spinner 1.5s linear infinite;
|
||||||
|
animation: spinner 1.5s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@-webkit-keyframes spinner {
|
||||||
|
0% {
|
||||||
|
-webkit-transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
-webkit-transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spinner {
|
||||||
|
0% {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
100% {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<form action="{{ route('client.payments.response') }}" method="post" id="server_response">
|
||||||
|
@csrf
|
||||||
|
<input type="hidden" name="store_card">
|
||||||
|
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
|
||||||
|
|
||||||
|
<input type="hidden" name="company_gateway_id" value="{{ $gateway->getCompanyGatewayId() }}">
|
||||||
|
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}">
|
||||||
|
|
||||||
|
<input type="hidden" name="token">
|
||||||
|
<input type="hidden" name="sourceId" id="sourceId">
|
||||||
|
<input type="hidden" name="verificationToken" id="verificationToken">
|
||||||
|
<input type="hidden" name="idempotencyKey" value="{{ \Illuminate\Support\Str::uuid() }}">
|
||||||
|
</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')])
|
||||||
|
<div class="flex flex-col" id="loader">
|
||||||
|
<div class="loader ease-linear rounded-full border-4 border-t-4 border-gray-200 h-12 w-12 mb-4"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ul class="list-none hover:list-disc " id="payment-list">
|
||||||
|
@if (count($tokens) > 0)
|
||||||
|
@foreach($tokens as $token)
|
||||||
|
<li class="py-2 hover:text-blue hover:bg-blue-600">
|
||||||
|
<label class="mr-4">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
data-token="{{ $token->token }}"
|
||||||
|
name="payment-type"
|
||||||
|
class="form-check-input text-indigo-600 rounded-full cursor-pointer toggle-payment-with-token toggle-payment-with-token"
|
||||||
|
/>
|
||||||
|
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }} - {{ $token->meta?->exp_month ?? 'xx' }}/{{ $token->meta?->exp_year ?? 'xx' }}</span>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
|
@endisset
|
||||||
|
|
||||||
|
<li class="py-2 hover:text-blue hover:bg-blue-600">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
id="toggle-payment-with-credit-card"
|
||||||
|
class="form-check-input text-indigo-600 rounded-full cursor-pointer"
|
||||||
|
name="payment-type"
|
||||||
|
checked/>
|
||||||
|
<span class="ml-1 cursor-pointer">{{ __('texts.new_card') }}</span>
|
||||||
|
</label>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
@endcomponent
|
||||||
|
|
||||||
|
@include('portal.ninja2020.gateways.includes.save_card')
|
||||||
|
|
||||||
|
@component('portal.ninja2020.components.general.card-element-single')
|
||||||
|
<div id="card-container"></div>
|
||||||
|
<div id="payment-status-container"></div>
|
||||||
|
@endcomponent
|
||||||
|
|
||||||
|
@include('portal.ninja2020.gateways.includes.pay_now')
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@assets
|
||||||
|
@if ($gateway->company_gateway->getConfigField('testMode'))
|
||||||
|
<script type="text/javascript" src="https://sandbox.web.squarecdn.com/v1/square.js"></script>
|
||||||
|
@else
|
||||||
|
<script type="text/javascript" src="https://web.squarecdn.com/v1/square.js"></script>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@vite('resources/js/clients/payments/square-credit-card.js')
|
||||||
|
@endassets
|
Loading…
x
Reference in New Issue
Block a user