Make "setPaymentMethod" available in all drivers

This commit is contained in:
Benjamin Beganović 2020-06-23 16:47:29 +02:00
parent 2738968170
commit f61ecef4f2
2 changed files with 21 additions and 4 deletions

View File

@ -69,6 +69,10 @@ class PayPalExpressPaymentDriver extends BasePaymentDriver
protected $customer_reference = '';
public function setPaymentMethod($payment_method_id = null)
{
return $this;
}
public function gatewayTypes()
{

View File

@ -21,6 +21,10 @@ use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Stripe\ACH;
use App\PaymentDrivers\Stripe\Alipay;
use App\PaymentDrivers\Stripe\CreditCard;
use App\PaymentDrivers\Stripe\SOFORT;
use App\PaymentDrivers\Stripe\Utilities;
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
@ -43,6 +47,15 @@ class StripePaymentDriver extends BasePaymentDriver
protected $payment_method;
public static $methods = [
GatewayType::CREDIT_CARD => CreditCard::class,
GatewayType::BANK_TRANSFER => ACH::class,
GatewayType::ALIPAY => Alipay::class,
GatewayType::SOFORT => SOFORT::class,
GatewayType::APPLE_PAY => 1,
GatewayType::SEPA => 1,
];
/**
* Methods in this class are divided into
* two separate streams
@ -65,11 +78,11 @@ class StripePaymentDriver extends BasePaymentDriver
Stripe::setApiKey($this->company_gateway->getConfigField('apiKey'));
}
public function setPaymentMethod(string $method)
public function setPaymentMethod($payment_method_id)
{
// Example: setPaymentMethod('App\\PaymentDrivers\\Stripe\\CreditCard');
$this->payment_method = new $method($this);
$class = self::$methods[$payment_method_id];
$this->payment_method = new $class($this);
return $this;
}