Removed BACS-Support as Stripe dropped it

This commit is contained in:
Lars Kusch 2021-10-12 16:18:13 +02:00
parent 175552b77f
commit e63fbd68e6
7 changed files with 1 additions and 320 deletions

View File

@ -80,8 +80,6 @@ class GatewayType extends StaticModel
return ctrans('texts.giropay');
case self::EPS:
return ctrans('texts.eps');
case self::BACS:
return ctrans('text.bacs');
case self::BECS:
return ctrans('tets.becs');
default:

View File

@ -50,8 +50,7 @@ class PaymentType extends StaticModel
const GIROPAY = 39;
const PRZELEWY24 = 40;
const EPS = 41;
const BACS = 43;
const BECS = 44;
const BECS = 43;
public static function parseCardType($cardName)
{

View File

@ -1,163 +0,0 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\PaymentDrivers\Stripe;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\PaymentDrivers\StripePaymentDriver;
use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\Exceptions\PaymentFailed;
class BACS
{
/** @var StripePaymentDriver */
public StripePaymentDriver $stripe;
public function __construct(StripePaymentDriver $stripe)
{
$this->stripe = $stripe;
}
public function authorizeView($data)
{
return render('gateways.stripe.bacs.authorize', $data);
}
public function paymentView(array $data) {
$data['gateway'] = $this->stripe;
$data['payment_method_id'] = GatewayType::BACS;
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
$data['client'] = $this->stripe->client;
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
$data['country'] = $this->stripe->client->country->iso_3166_2;
$data['payment_hash'] = $this->stripe->payment_hash->hash;
$intent = \Stripe\PaymentIntent::create([
'amount' => $data['stripe_amount'],
'currency' => 'eur',
'payment_method_types' => ['bacs_debit'],
'customer' => $this->stripe->findOrCreateCustomer(),
'description' => $this->stripe->decodeUnicodeString(ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number')),
]);
$data['pi_client_secret'] = $intent->client_secret;
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
$this->stripe->payment_hash->save();
return render('gateways.stripe.bacs.pay', $data);
}
public function paymentResponse(PaymentResponseRequest $request)
{
$gateway_response = json_decode($request->gateway_response);
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all());
$this->stripe->payment_hash->save();
if (property_exists($gateway_response, 'status') && $gateway_response->status == 'processing') {
$this->stripe->init();
$this->storePaymentMethod($gateway_response);
return $this->processSuccessfulPayment($gateway_response->id);
}
return $this->processUnsuccessfulPayment();
}
public function processSuccessfulPayment(string $payment_intent)
{
$this->stripe->init();
$data = [
'payment_method' => $payment_intent,
'payment_type' => PaymentType::BACS,
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
'transaction_reference' => $payment_intent,
'gateway_type_id' => GatewayType::BACS,
];
$this->stripe->createPayment($data, Payment::STATUS_PENDING);
SystemLogger::dispatch(
['response' => $this->stripe->payment_hash->data, 'data' => $data],
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_SUCCESS,
SystemLog::TYPE_STRIPE,
$this->stripe->client,
$this->stripe->client->company,
);
return redirect()->route('client.payments.index');
}
public function processUnsuccessfulPayment()
{
$server_response = $this->stripe->payment_hash->data;
PaymentFailureMailer::dispatch(
$this->stripe->client,
$server_response,
$this->stripe->client->company,
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
);
$message = [
'server_response' => $server_response,
'data' => $this->stripe->payment_hash->data,
];
SystemLogger::dispatch(
$message,
SystemLog::CATEGORY_GATEWAY_RESPONSE,
SystemLog::EVENT_GATEWAY_FAILURE,
SystemLog::TYPE_STRIPE,
$this->stripe->client,
$this->stripe->client->company,
);
throw new PaymentFailed('Failed to process the payment.', 500);
}
private function storePaymentMethod($intent)
{
try {
$method = $this->stripe->getStripePaymentMethod($intent->payment_method);
$payment_meta = new \stdClass;
$payment_meta->brand = (string) \sprintf('%s (%s)', $method->sepa_debit->bank_code, ctrans('texts.bacs'));
$payment_meta->last4 = (string) $method->sepa_debit->last4;
$payment_meta->state = 'authorized';
$payment_meta->type = GatewayType::BACS;
$data = [
'payment_meta' => $payment_meta,
'token' => $intent->payment_method,
'payment_method_id' => GatewayType::BACS,
];
$this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $method->customer]);
} catch (\Exception $e) {
return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
}
}
}

View File

@ -39,7 +39,6 @@ use App\PaymentDrivers\Stripe\iDeal;
use App\PaymentDrivers\Stripe\EPS;
use App\PaymentDrivers\Stripe\Bancontact;
use App\PaymentDrivers\Stripe\BECS;
use App\PaymentDrivers\Stripe\BACS;
use App\PaymentDrivers\Stripe\UpdatePaymentMethods;
use App\PaymentDrivers\Stripe\Utilities;
use App\Utils\Traits\MakesHash;
@ -89,7 +88,6 @@ class StripePaymentDriver extends BaseDriver
GatewayType::IDEAL => iDeal::class,
GatewayType::EPS => EPS::class,
GatewayType::BANCONTACT => Bancontact::class,
GatewayType::BACS => BACS::class,
GatewayType::BECS => BECS::class,
];
@ -204,13 +202,6 @@ class StripePaymentDriver extends BaseDriver
&& in_array($this->client->country->iso_3166_3, ["BEL"]))
$types[] = GatewayType::BANCONTACT;
if ($this->client
&& $this->client->currency()
&& ($this->client->currency()->code == 'GBR')
&& isset($this->client->country)
&& in_array($this->client->country->iso_3166_3, ["GBP", "DEU"]))
$types[] = GatewayType::BACS;
if ($this->client
&& $this->client->currency()
&& ($this->client->currency()->code == 'AUD')
@ -253,8 +244,6 @@ class StripePaymentDriver extends BaseDriver
return 'gateways.stripe.eps';
case GatewayType::BANCONTACT:
return 'gateways.stripe.bancontact';
case GatewayType::BACS:
return 'gateways.stripe.bacs';
case GatewayType::BECS:
return 'gateways.stripe.becs';
default:

View File

@ -1,84 +0,0 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'SEPA', 'card_title' => 'SEPA-Lastschrift'])
@section('gateway_head')
@if($gateway->company_gateway->getConfigField('account_id'))
<meta name="stripe-account-id" content="{{ $gateway->company_gateway->getConfigField('account_id') }}">
<meta name="stripe-publishable-key" content="{{ config('ninja.ninja_stripe_publishable_key') }}">
@else
<meta name="stripe-publishable-key" content="{{ $gateway->company_gateway->getPublishableKey() }}">
@endif
@endsection
@section('gateway_content')
@if(session()->has('sepa_error'))
<div class="alert alert-failure mb-4">
<p>{{ session('sepa_error') }}</p>
</div>
@endif
<form action="{{ route('client.payment_methods.store', ['method' => App\Models\GatewayType::SEPA]) }}" method="post" id="server_response">
@csrf
<input type="hidden" name="company_gateway_id" value="{{ $gateway->company_gateway->id }}">
<input type="hidden" name="gateway_type_id" value="{{ $payment_method_id }}">
<input type="hidden" name="gateway_response" id="gateway_response">
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="is_default" id="is_default">
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.account_holder_type')])
<span class="flex items-center mr-4">
<input class="form-radio mr-2" type="radio" value="individual" name="account-holder-type" checked>
<span>{{ __('texts.individual_account') }}</span>
</span>
<span class="flex items-center">
<input class="form-radio mr-2" type="radio" value="company" name="account-holder-type">
<span>{{ __('texts.company_account') }}</span>
</span>
@endcomponent
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.account_holder_name')])
<input class="input w-full" id="account-holder-name" type="text" placeholder="{{ ctrans('texts.name') }}" required>
@endcomponent
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.country')])
<select name="countries" id="country" class="form-select input w-full" required>
@foreach($countries as $country)
<option value="{{ $country->iso_3166_2 }}">{{ $country->iso_3166_2 }} ({{ $country->name }})</option>
@endforeach
</select>
@endcomponent
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.currency')])
<select name="currencies" id="currency" class="form-select input w-full">
@foreach($currencies as $currency)
<option value="{{ $currency->code }}">{{ $currency->code }} ({{ $currency->name }})</option>
@endforeach
</select>
@endcomponent
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.routing_number')])
<input class="input w-full" id="routing-number" type="text" required>
@endcomponent
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.account_number')])
<input class="input w-full" id="account-number" type="text" required>
@endcomponent
@component('portal.ninja2020.components.general.card-element-single')
<input type="checkbox" class="form-checkbox mr-1" id="accept-terms" required>
<label for="accept-terms" class="cursor-pointer">{{ ctrans('texts.ach_authorization', ['company' => auth()->user()->company->present()->name, 'email' => auth('contact')->user()->client->company->settings->email]) }}</label>
@endcomponent
@component('portal.ninja2020.gateways.includes.pay_now', ['id' => 'save-button'])
{{ ctrans('texts.add_payment_method') }}
@endcomponent
@endsection
@section('gateway_footer')
<script src="https://js.stripe.com/v3/"></script>
<script src="{{ asset('js/clients/payments/stripe-sepa.js') }}"></script>
@endsection

View File

@ -1,29 +0,0 @@
<div id="stripe--payment-container">
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.name')])
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
@csrf
<input type="hidden" name="gateway_response">
<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="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="store_card">
<label for="bacs-name">
<input class="input w-full" id="bacs-name" type="text" placeholder="{{ ctrans('texts.bank_account_holder') }}">
</label>
<label for="bacs-email" >
<input class="input w-full" id="bacs-email-address" type="email" placeholder="{{ ctrans('texts.email') }}">
</label>
<label>
<div class="border p-4 rounded">
<div id="bacs-iban"></div>
</div>
</label>
<div id="mandate-acceptance">
<input type="checkbox" id="bacs-mandate-acceptance" class="input mr-4">
<label for="bacs-mandate-acceptance">{{ctrans('texts.bacs_mandat')}}</label>
</div>
</form>
@endcomponent
</div>

View File

@ -1,29 +0,0 @@
@extends('portal.ninja2020.layout.payments', ['gateway_title' => 'BACS', 'card_title' => 'BACS'])
@section('gateway_head')
<meta name="stripe-publishable-key" content="{{ $gateway->getPublishableKey() }}">
<meta name="stripe-account-id" content="{{ $gateway->company_gateway->getConfigField('account_id') }}">
<meta name="amount" content="{{ $stripe_amount }}">
<meta name="country" content="{{ $country }}">
<meta name="customer" content="{{ $customer }}">
<meta name="pi-client-secret" content="{{ $pi_client_secret }}">
@endsection
@section('gateway_content')
<div class="alert alert-failure mb-4" hidden id="errors"></div>
@include('portal.ninja2020.gateways.includes.payment_details')
@component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.payment_type')])
{{ ctrans('texts.bacs') }} ({{ ctrans('texts.bank_transfer') }})
@endcomponent
@include('portal.ninja2020.gateways.stripe.bacs.bacs_debit')
@include('portal.ninja2020.gateways.includes.save_card')
@include('portal.ninja2020.gateways.includes.pay_now')
@endsection
@push('footer')
<script src="https://js.stripe.com/v3/"></script>
<script src="{{ asset('js/clients/payments/stripe-bacs.js') }}"></script>
@endpush