1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Merge pull request #3881 from beganovich/v2-0307-payment-methods-dropdown

Adding payment methods from menu
This commit is contained in:
David Bomba 2020-07-04 08:35:17 +10:00 committed by GitHub
commit 3ea736dcb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 82 additions and 16 deletions

View File

@ -1,4 +1,5 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
@ -15,6 +16,7 @@ use App\Events\Payment\Methods\MethodDeleted;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\CreatePaymentMethodRequest;
use App\Models\ClientGatewayToken;
use App\Models\CompanyGateway;
use App\Models\GatewayType;
use App\PaymentDrivers\AuthorizePaymentDriver;
use App\Utils\Traits\MakesDates;
@ -42,13 +44,13 @@ class PaymentMethodController extends Controller
*/
public function create(CreatePaymentMethodRequest $request)
{
$gateway = auth()->user()->client->getCreditCardGateway();
$gateway = $this->getClientGateway();
$data['gateway'] = $gateway;
return $gateway
->driver(auth()->user()->client)
->setPaymentMethod(GatewayType::CREDIT_CARD)
->setPaymentMethod($request->query('method'))
->authorizeView($data);
}
@ -60,11 +62,11 @@ class PaymentMethodController extends Controller
*/
public function store(Request $request)
{
$gateway = auth()->user()->client->getCreditCardGateway();
$gateway = $this->getClientGateway();
return $gateway
->driver(auth()->user()->client)
->setPaymentMethod(GatewayType::CREDIT_CARD)
->setPaymentMethod($request->query('method'))
->authorizeResponse($request);
}
@ -106,21 +108,21 @@ class PaymentMethodController extends Controller
public function verify(ClientGatewayToken $payment_method)
{
$gateway = auth()->user()->client->getCreditCardGateway();
$gateway = $this->getClientGateway();
return $gateway
->driver(auth()->user()->client)
->setPaymentMethod(GatewayType::BANK_TRANSFER)
->setPaymentMethod(request()->query('method'))
->verificationView($payment_method);
}
public function processVerification(ClientGatewaytoken $payment_method)
{
$gateway = auth()->user()->client->getCreditCardGateway();
$gateway = $this->getClientGateway();
return $gateway
->driver(auth()->user()->client)
->setPaymentMethod(GatewayType::BANK_TRANSFER)
->setPaymentMethod(request()->query('method'))
->processVerification($payment_method);
}
@ -144,4 +146,17 @@ class PaymentMethodController extends Controller
->route('client.payment_methods.index')
->withSuccess('Payment method has been successfully removed.');
}
private function getClientGateway()
{
if (request()->query('method') == GatewayType::CREDIT_CARD) {
return $gateway = auth()->user()->client->getCreditCardGateway();
}
if (request()->query('method') == GatewayType::BANK_TRANSFER) {
return $gateway = auth()->user()->client->getBankTransferGateway();
}
return abort(404);
}
}

View File

@ -400,6 +400,17 @@ class Client extends BaseModel implements HasLocalePreference
return null;
}
public function getBankTransferMethodType()
{
if ($this->currency()->code == 'USD') {
return GatewayType::BANK_TRANSFER;
}
if ($this->currency()->code == 'EUR') {
return GatewayType::SEPA;
}
}
public function getCurrencyCode()
{
if ($this->currency()) {

View File

@ -82,6 +82,11 @@ class CheckoutComPaymentDriver extends BasePaymentDriver
}
}
public function authorizeView($data)
{
return render('gateways.checkout.authorize');
}
public function processPaymentView(array $data)
{
$data['gateway'] = $this;

View File

@ -87,7 +87,7 @@ class ACH
$client_gateway_token->save();
}
return redirect()->route('client.payment_methods.verification', $client_gateway_token->hashed_id);
return redirect()->route('client.payment_methods.verification', ['id' => $client_gateway_token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
}
public function verificationView(ClientGatewayToken $token)
@ -168,7 +168,7 @@ class ACH
return $this->processUnsuccessfulPayment($state);
} catch (\Exception $e) {
if ($e instanceof \Stripe\Exception\CardException) {
return redirect()->route('client.payment_methods.verification', ClientGatewayToken::first()->hashed_id);
return redirect()->route('client.payment_methods.verification', ['id' => ClientGatewayToken::first()->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
}
}
}

View File

@ -3234,4 +3234,6 @@ return [
'enable_only_for_development' => 'Enable only for development',
'test_pdf' => 'Test PDF',
'checkout_authorize_label' => 'Checkout.com can be can saved as payment method for future use, once you complete your first transaction. Don\'t forget to check "Save card" during payment process.',
];

View File

@ -9,10 +9,24 @@
<option>20</option>
</select>
</div>
@if($client->getCreditCardGateway())
<a href="{{ route('client.payment_methods.create') }}" id="add-payment-method"
class="button button-primary">{{ ctrans('texts.add_payment_method') }}</a>
@endif
<div class="relative" x-data="{ open: false }" x-on:click.away="open = false">
<button x-on:click="open = !open" class="button button-primary">{{ ctrans('texts.add_payment_method') }}</button>
<div x-show="open" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" class="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg">
<div class="py-1 rounded-md bg-white shadow-xs">
@if($client->getCreditCardGateway())
<a href="{{ route('client.payment_methods.create', ['method' => App\Models\GatewayType::CREDIT_CARD]) }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 transition ease-in-out duration-150">
{{ ctrans('texts.credit_card') }}
</a>
@endif
@if($client->getBankTransferGateway())
<a href="{{ route('client.payment_methods.create', ['method' => $client->getBankTransferMethodType()]) }}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 transition ease-in-out duration-150">
{{ ctrans('texts.bank_account') }}
</a>
@endif
</div>
</div>
</div>
</div>
<div class="-my-2 py-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
<div class="align-middle inline-block min-w-full overflow-hidden rounded">

View File

@ -0,0 +1,19 @@
@extends('portal.ninja2020.layout.app')
@section('meta_title', ctrans('texts.checkout_com'))
@section('body')
<div class="container mx-auto">
<div class="grid grid-cols-6 gap-4">
<div class="col-span-6 md:col-start-2 md:col-span-4">
<div class="alert alert-failure mb-4" hidden id="errors"></div>
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
<div class="bg-white px-4 py-5 sm:px-6 flex items-center">
<dt class="text-sm leading-5 font-medium text-gray-500 mr-4">
{{ ctrans('texts.checkout_authorize_label') }}
</dt>
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -6,7 +6,7 @@
@endpush
@section('body')
<form action="{{ route('client.payment_methods.store') }}" method="post" id="server_response">
<form action="{{ route('client.payment_methods.store', ['method' => App\Models\GatewayType::BANK_TRANSFER]) }}" method="post" id="server_response">
@csrf
<input type="hidden" name="company_gateway_id" value="{{ $gateway->id }}">
<input type="hidden" name="gateway_type_id" value="2">

View File

@ -6,7 +6,7 @@
@endpush
@section('body')
<form action="{{ route('client.payment_methods.store') }}" method="post" id="server_response">
<form action="{{ route('client.payment_methods.store', ['method' => App\Models\GatewayType::CREDIT_CARD]) }}" method="post" id="server_response">
@csrf
<input type="hidden" name="company_gateway_id" value="{{ $gateway->gateway_id }}">
<input type="hidden" name="payment_method_id" value="1">