Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/PaymentProvider.php
Show All 21 Lines | abstract class PaymentProvider | ||||
public const TYPE_MANDATE = 'mandate'; | public const TYPE_MANDATE = 'mandate'; | ||||
public const TYPE_REFUND = 'refund'; | public const TYPE_REFUND = 'refund'; | ||||
public const TYPE_CHARGEBACK = 'chargeback'; | public const TYPE_CHARGEBACK = 'chargeback'; | ||||
public const METHOD_CREDITCARD = 'creditcard'; | public const METHOD_CREDITCARD = 'creditcard'; | ||||
public const METHOD_PAYPAL = 'paypal'; | public const METHOD_PAYPAL = 'paypal'; | ||||
public const METHOD_BANKTRANSFER = 'banktransfer'; | public const METHOD_BANKTRANSFER = 'banktransfer'; | ||||
public const METHOD_DIRECTDEBIT = 'directdebit'; | public const METHOD_DIRECTDEBIT = 'directdebit'; | ||||
public const METHOD_BITCOIN = 'bitcoin'; | |||||
public const PROVIDER_MOLLIE = 'mollie'; | public const PROVIDER_MOLLIE = 'mollie'; | ||||
public const PROVIDER_STRIPE = 'stripe'; | public const PROVIDER_STRIPE = 'stripe'; | ||||
public const PROVIDER_COINBASE = 'coinbase'; | |||||
/** const int Minimum amount of money in a single payment (in cents) */ | /** const int Minimum amount of money in a single payment (in cents) */ | ||||
public const MIN_AMOUNT = 1000; | public const MIN_AMOUNT = 1000; | ||||
private static $paymentMethodIcons = [ | private static $paymentMethodIcons = [ | ||||
self::METHOD_CREDITCARD => ['prefix' => 'far', 'name' => 'credit-card'], | self::METHOD_CREDITCARD => ['prefix' => 'far', 'name' => 'credit-card'], | ||||
self::METHOD_PAYPAL => ['prefix' => 'fab', 'name' => 'paypal'], | self::METHOD_PAYPAL => ['prefix' => 'fab', 'name' => 'paypal'], | ||||
self::METHOD_BANKTRANSFER => ['prefix' => 'fas', 'name' => 'building-columns'] | self::METHOD_BANKTRANSFER => ['prefix' => 'fas', 'name' => 'building-columns'], | ||||
self::METHOD_BITCOIN => ['prefix' => 'fab', 'name' => 'bitcoin'], | |||||
]; | ]; | ||||
/** | /** | ||||
* Detect the name of the provider | * Detect the name of the provider | ||||
* | * | ||||
* @param \App\Wallet|string|null $provider_or_wallet | * @param \App\Wallet|string|null $provider_or_wallet | ||||
* @return string The name of the provider | * @return string The name of the provider | ||||
*/ | */ | ||||
Show All 18 Lines | private static function providerName($provider_or_wallet = null): string | ||||
return \strtolower($provider); | return \strtolower($provider); | ||||
} | } | ||||
/** | /** | ||||
* Factory method | * Factory method | ||||
* | * | ||||
* @param \App\Wallet|string|null $provider_or_wallet | * @param \App\Wallet|string|null $provider_or_wallet | ||||
*/ | */ | ||||
public static function factory($provider_or_wallet = null) | public static function factory($provider_or_wallet = null, $currency = null) | ||||
{ | { | ||||
if (\strtolower($currency) == 'btc') { | |||||
return new \App\Providers\Payment\Coinbase(); | |||||
} | |||||
switch (self::providerName($provider_or_wallet)) { | switch (self::providerName($provider_or_wallet)) { | ||||
case self::PROVIDER_STRIPE: | case self::PROVIDER_STRIPE: | ||||
return new \App\Providers\Payment\Stripe(); | return new \App\Providers\Payment\Stripe(); | ||||
case self::PROVIDER_MOLLIE: | case self::PROVIDER_MOLLIE: | ||||
return new \App\Providers\Payment\Mollie(); | return new \App\Providers\Payment\Mollie(); | ||||
case self::PROVIDER_COINBASE: | |||||
return new \App\Providers\Payment\Coinbase(); | |||||
default: | default: | ||||
throw new \Exception("Invalid payment provider: {$provider_or_wallet}"); | throw new \Exception("Invalid payment provider: {$provider_or_wallet}"); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Create a new auto-payment mandate for a wallet. | * Create a new auto-payment mandate for a wallet. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 258 Lines • ▼ Show 20 Lines | public static function paymentMethods(Wallet $wallet, $type): array | ||||
if ($methods = Cache::get($cacheKey)) { | if ($methods = Cache::get($cacheKey)) { | ||||
\Log::debug("Using payment method cache" . var_export($methods, true)); | \Log::debug("Using payment method cache" . var_export($methods, true)); | ||||
return $methods; | return $methods; | ||||
} | } | ||||
$provider = PaymentProvider::factory($providerName); | $provider = PaymentProvider::factory($providerName); | ||||
$methods = $provider->providerPaymentMethods($type, $wallet->currency); | $methods = $provider->providerPaymentMethods($type, $wallet->currency); | ||||
if (!empty(\config('services.coinbase.key'))) { | |||||
machniak: It would probably make sense to include coinbase method only if `services.coinbase.key` is set. | |||||
$coinbaseProvider = PaymentProvider::factory(self::PROVIDER_COINBASE); | |||||
$methods = array_merge($methods, $coinbaseProvider->providerPaymentMethods($type, $wallet->currency)); | |||||
} | |||||
$methods = self::applyMethodWhitelist($type, $methods); | $methods = self::applyMethodWhitelist($type, $methods); | ||||
\Log::debug("Loaded payment methods" . var_export($methods, true)); | \Log::debug("Loaded payment methods" . var_export($methods, true)); | ||||
Cache::put($cacheKey, $methods, now()->addHours(1)); | Cache::put($cacheKey, $methods, now()->addHours(1)); | ||||
return $methods; | return $methods; | ||||
} | } | ||||
Show All 19 Lines |
It would probably make sense to include coinbase method only if services.coinbase.key is set. So, we can easily disable it at any time. Or use app.payment.methods_*?