mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Merge pull request #6163 from beganovich/v5-2906-payment-methods-enabled-check
(v5) Check for enabled payment methods
This commit is contained in:
commit
1693086fbb
@ -14,7 +14,7 @@ namespace App\Http\Controllers\ClientPortal;
|
||||
|
||||
use App\Events\Payment\Methods\MethodDeleted;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\ClientPortal\CreatePaymentMethodRequest;
|
||||
use App\Http\Requests\ClientPortal\PaymentMethod\CreatePaymentMethodRequest;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\ClientGatewayToken;
|
||||
use App\Models\GatewayType;
|
||||
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\ClientPortal;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreatePaymentMethodRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->client->getCreditCardGateway() ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\ClientPortal\PaymentMethod;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\Client;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use function auth;
|
||||
use function collect;
|
||||
|
||||
class CreatePaymentMethodRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
/** @var Client $client */
|
||||
$client = auth()->user()->client;
|
||||
|
||||
$available_methods = [];
|
||||
|
||||
collect($client->service()->getPaymentMethods(1))
|
||||
->filter(function ($method) use (&$available_methods) {
|
||||
$available_methods[] = $method['gateway_type_id'];
|
||||
});
|
||||
|
||||
if (in_array($this->query('method'), $available_methods)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -56,9 +56,11 @@ class AuthorizePaymentDriver extends BaseDriver
|
||||
*/
|
||||
public function gatewayTypes(): array
|
||||
{
|
||||
$types = [
|
||||
GatewayType::CREDIT_CARD,
|
||||
];
|
||||
$types = [];
|
||||
|
||||
if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) {
|
||||
$types[] = GatewayType::CREDIT_CARD;
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ use App\Models\PaymentType;
|
||||
use App\Models\SystemLog;
|
||||
use App\PaymentDrivers\Braintree\CreditCard;
|
||||
use App\PaymentDrivers\Braintree\PayPal;
|
||||
use Braintree\Gateway;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BraintreePaymentDriver extends BaseDriver
|
||||
@ -36,7 +38,7 @@ class BraintreePaymentDriver extends BaseDriver
|
||||
public $can_authorise_credit_card = true;
|
||||
|
||||
/**
|
||||
* @var \Braintree\Gateway;
|
||||
* @var Gateway;
|
||||
*/
|
||||
public $gateway;
|
||||
|
||||
@ -49,7 +51,7 @@ class BraintreePaymentDriver extends BaseDriver
|
||||
|
||||
public function init(): void
|
||||
{
|
||||
$this->gateway = new \Braintree\Gateway([
|
||||
$this->gateway = new Gateway([
|
||||
'environment' => $this->company_gateway->getConfigField('testMode') ? 'sandbox' : 'production',
|
||||
'merchantId' => $this->company_gateway->getConfigField('merchantId'),
|
||||
'publicKey' => $this->company_gateway->getConfigField('publicKey'),
|
||||
@ -68,10 +70,15 @@ class BraintreePaymentDriver extends BaseDriver
|
||||
|
||||
public function gatewayTypes(): array
|
||||
{
|
||||
return [
|
||||
GatewayType::CREDIT_CARD,
|
||||
$types = [
|
||||
GatewayType::PAYPAL,
|
||||
];
|
||||
|
||||
if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) {
|
||||
$types[] = GatewayType::CREDIT_CARD;
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
public function authorizeView($data)
|
||||
@ -130,7 +137,7 @@ class BraintreePaymentDriver extends BaseDriver
|
||||
'description' => $response->status,
|
||||
'code' => 0,
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return [
|
||||
'transaction_reference' => null,
|
||||
'transaction_response' => json_encode($e->getMessage()),
|
||||
@ -174,7 +181,7 @@ class BraintreePaymentDriver extends BaseDriver
|
||||
'gateway_type_id' => GatewayType::CREDIT_CARD,
|
||||
];
|
||||
|
||||
$payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED);
|
||||
$payment = $this->createPayment($data, Payment::STATUS_COMPLETED);
|
||||
|
||||
SystemLogger::dispatch(
|
||||
['response' => $result, 'data' => $data],
|
||||
|
@ -72,11 +72,15 @@ class CheckoutComPaymentDriver extends BaseDriver
|
||||
/**
|
||||
* Returns the default gateway type.
|
||||
*/
|
||||
public function gatewayTypes()
|
||||
public function gatewayTypes(): array
|
||||
{
|
||||
return [
|
||||
GatewayType::CREDIT_CARD,
|
||||
];
|
||||
$types = [];
|
||||
|
||||
if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) {
|
||||
$types[] = GatewayType::CREDIT_CARD;
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,7 +236,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
||||
'transaction_reference' => $response->id,
|
||||
];
|
||||
|
||||
$payment = $this->createPayment($data, \App\Models\Payment::STATUS_COMPLETED);
|
||||
$payment = $this->createPayment($data, Payment::STATUS_COMPLETED);
|
||||
|
||||
SystemLogger::dispatch(
|
||||
['response' => $response, 'data' => $data],
|
||||
@ -269,7 +273,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
||||
|
||||
return false;
|
||||
}
|
||||
} catch (\Exception | CheckoutHttpException $e) {
|
||||
} catch (Exception | CheckoutHttpException $e) {
|
||||
$this->unWindGatewayFees($payment_hash);
|
||||
$message = $e instanceof CheckoutHttpException
|
||||
? $e->getBody()
|
||||
|
@ -32,7 +32,9 @@ use App\PaymentDrivers\Stripe\UpdatePaymentMethods;
|
||||
use App\PaymentDrivers\Stripe\Utilities;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Exception;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Laracasts\Presenter\Exceptions\PresenterException;
|
||||
use Stripe\Account;
|
||||
use Stripe\Customer;
|
||||
use Stripe\Exception\ApiErrorException;
|
||||
@ -52,7 +54,7 @@ class StripePaymentDriver extends BaseDriver
|
||||
|
||||
public $can_authorise_credit_card = true;
|
||||
|
||||
/** @var \Stripe\StripeClient */
|
||||
/** @var StripeClient */
|
||||
public $stripe;
|
||||
|
||||
protected $customer_reference = 'customerReferenceParam';
|
||||
@ -112,12 +114,13 @@ class StripePaymentDriver extends BaseDriver
|
||||
public function gatewayTypes(): array
|
||||
{
|
||||
$types = [
|
||||
GatewayType::CREDIT_CARD,
|
||||
GatewayType::CRYPTO,
|
||||
// GatewayType::SEPA, // TODO: Missing implementation
|
||||
// GatewayType::APPLE_PAY, // TODO:: Missing implementation
|
||||
];
|
||||
|
||||
if ($this->company_gateway->fees_and_limits->{GatewayType::CREDIT_CARD}->is_enabled) {
|
||||
$types[] = GatewayType::CREDIT_CARD;
|
||||
}
|
||||
|
||||
if ($this->client
|
||||
&& isset($this->client->country)
|
||||
&& in_array($this->client->country->iso_3166_3, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP'])) {
|
||||
@ -126,7 +129,8 @@ class StripePaymentDriver extends BaseDriver
|
||||
|
||||
if ($this->client
|
||||
&& isset($this->client->country)
|
||||
&& in_array($this->client->country->iso_3166_3, ['USA'])) {
|
||||
&& in_array($this->client->country->iso_3166_3, ['USA'])
|
||||
&& $this->company_gateway->fees_and_limits->{GatewayType::BANK_TRANSFER}->is_enabled) {
|
||||
$types[] = GatewayType::BANK_TRANSFER;
|
||||
}
|
||||
|
||||
@ -213,7 +217,7 @@ class StripePaymentDriver extends BaseDriver
|
||||
* Proxy method to pass the data into payment method authorizeView().
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed
|
||||
* @return RedirectResponse|mixed
|
||||
*/
|
||||
public function authorizeView(array $data)
|
||||
{
|
||||
@ -224,7 +228,7 @@ class StripePaymentDriver extends BaseDriver
|
||||
* Processes the gateway response for credit card authorization.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed
|
||||
* @return RedirectResponse|mixed
|
||||
*/
|
||||
public function authorizeResponse($request)
|
||||
{
|
||||
@ -235,7 +239,7 @@ class StripePaymentDriver extends BaseDriver
|
||||
* Process the payment with gateway.
|
||||
*
|
||||
* @param array $data
|
||||
* @return \Illuminate\Http\RedirectResponse|mixed
|
||||
* @return RedirectResponse|mixed
|
||||
*/
|
||||
public function processPaymentView(array $data)
|
||||
{
|
||||
@ -293,7 +297,7 @@ class StripePaymentDriver extends BaseDriver
|
||||
* Finds or creates a Stripe Customer object.
|
||||
*
|
||||
* @return null|Customer A Stripe customer object
|
||||
* @throws \Laracasts\Presenter\Exceptions\PresenterException
|
||||
* @throws PresenterException
|
||||
* @throws ApiErrorException
|
||||
*/
|
||||
public function findOrCreateCustomer(): ?Customer
|
||||
|
Loading…
x
Reference in New Issue
Block a user