Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/PaymentProvider.php
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 Lines | protected function storeRefund(Wallet $wallet, array $refund): void | ||||
// FIXME: Refunds/chargebacks are out of the reseller comissioning for now | // FIXME: Refunds/chargebacks are out of the reseller comissioning for now | ||||
$this->storePayment($refund, $wallet->id); | $this->storePayment($refund, $wallet->id); | ||||
} | } | ||||
/** | /** | ||||
* List supported payment methods from this provider | * List supported payment methods from this provider | ||||
* | * | ||||
* @param string $type The payment type for which we require a method (oneoff/recurring). | * @param string $type The payment type for which we require a method (oneoff/recurring). | ||||
* @param string $currency Currency code | |||||
* | * | ||||
* @return array Array of array with available payment methods: | * @return array Array of array with available payment methods: | ||||
* - id: id of the method | * - id: id of the method | ||||
* - name: User readable name of the payment method | * - name: User readable name of the payment method | ||||
* - minimumAmount: Minimum amount to be charged in cents | * - minimumAmount: Minimum amount to be charged in cents | ||||
* - currency: Currency used for the method | * - currency: Currency used for the method | ||||
* - exchangeRate: The projected exchange rate (actual rate is determined during payment) | * - exchangeRate: The projected exchange rate (actual rate is determined during payment) | ||||
* - icon: An icon (icon name) representing the method | * - icon: An icon (icon name) representing the method | ||||
*/ | */ | ||||
abstract public function providerPaymentMethods($type): array; | abstract public function providerPaymentMethods(string $type, string $currency): array; | ||||
/** | /** | ||||
* Get a payment. | * Get a payment. | ||||
* | * | ||||
* @param string $paymentId Payment identifier | * @param string $paymentId Payment identifier | ||||
* | * | ||||
* @return array Payment information: | * @return array Payment information: | ||||
* - id: Payment identifier | * - id: Payment identifier | ||||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | abstract class PaymentProvider | ||||
* - currency: Currency used for the method | * - currency: Currency used for the method | ||||
* - exchangeRate: The projected exchange rate (actual rate is determined during payment) | * - exchangeRate: The projected exchange rate (actual rate is determined during payment) | ||||
* - icon: An icon (icon name) representing the method | * - icon: An icon (icon name) representing the method | ||||
*/ | */ | ||||
public static function paymentMethods(Wallet $wallet, $type): array | public static function paymentMethods(Wallet $wallet, $type): array | ||||
{ | { | ||||
$providerName = self::providerName($wallet); | $providerName = self::providerName($wallet); | ||||
$cacheKey = "methods-" . $providerName . '-' . $type; | $cacheKey = "methods-{$providerName}-{$type}-{$wallet->currency}"; | ||||
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 = self::applyMethodWhitelist($type, $provider->providerPaymentMethods($type)); | $methods = $provider->providerPaymentMethods($type, $wallet->currency); | ||||
$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 18 Lines |