mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 06:04:33 -04:00
Refactor view for authorization
This commit is contained in:
parent
90e4534fef
commit
0f4d7f6aed
@ -48,7 +48,10 @@ class PaymentMethodController extends Controller
|
|||||||
'token' => false,
|
'token' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $gateway->driver(auth()->user()->client)->authorizeCreditCardView($data);
|
return $gateway
|
||||||
|
->driver(auth()->user()->client)
|
||||||
|
->setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard')
|
||||||
|
->authorizeView($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
40
app/PaymentDrivers/Stripe/CreditCard.php
Normal file
40
app/PaymentDrivers/Stripe/CreditCard.php
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\PaymentDrivers\Stripe;
|
||||||
|
|
||||||
|
use App\PaymentDrivers\StripePaymentDriver;
|
||||||
|
|
||||||
|
class CreditCard
|
||||||
|
{
|
||||||
|
/** @var StripePaymentDriver */
|
||||||
|
public $stripe;
|
||||||
|
|
||||||
|
public function __construct(StripePaymentDriver $stripe)
|
||||||
|
{
|
||||||
|
$this->stripe = $stripe;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Authorises a credit card for future use.
|
||||||
|
*
|
||||||
|
* @param array $data Array of variables needed for the view.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
|
*/
|
||||||
|
public function authorizeView(array $data)
|
||||||
|
{
|
||||||
|
$intent['intent'] = $this->stripe->getSetupIntent();
|
||||||
|
|
||||||
|
return render('gateways.stripe.add_credit_card', array_merge($data, $intent));
|
||||||
|
}
|
||||||
|
}
|
@ -40,6 +40,8 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
|
|
||||||
protected $customer_reference = 'customerReferenceParam';
|
protected $customer_reference = 'customerReferenceParam';
|
||||||
|
|
||||||
|
protected $payment_method;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Methods in this class are divided into
|
* Methods in this class are divided into
|
||||||
* two separate streams
|
* two separate streams
|
||||||
@ -62,6 +64,21 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
|
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return payment method type.
|
||||||
|
*
|
||||||
|
* @param string $method
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setPaymentMethod(string $method)
|
||||||
|
{
|
||||||
|
// Example: setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard');
|
||||||
|
|
||||||
|
$this->payment_method = new $method($this);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the gateway types
|
* Returns the gateway types
|
||||||
*/
|
*/
|
||||||
@ -128,16 +145,15 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authorises a credit card for future use.
|
* Proxy method to pass the data into payment method authorizeView().
|
||||||
*
|
*
|
||||||
* @param array $data Array of variables needed for the view
|
* @param array $data
|
||||||
|
*
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
*/
|
*/
|
||||||
public function authorizeCreditCardView(array $data)
|
public function authorizeView(array $data)
|
||||||
{
|
{
|
||||||
$intent['intent'] = $this->getSetupIntent();
|
return $this->payment_method->authorizeView($data);
|
||||||
|
|
||||||
return render('gateways.stripe.add_credit_card', array_merge($data, $intent));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -400,12 +416,12 @@ class StripePaymentDriver extends BasePaymentDriver
|
|||||||
return $payment;
|
return $payment;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function convertFromStripeAmount($amount, $precision)
|
public function convertFromStripeAmount($amount, $precision)
|
||||||
{
|
{
|
||||||
return $amount / pow(10, $precision);
|
return $amount / pow(10, $precision);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function convertToStripeAmount($amount, $precision)
|
public function convertToStripeAmount($amount, $precision)
|
||||||
{
|
{
|
||||||
return $amount * pow(10, $precision);
|
return $amount * pow(10, $precision);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user