Changeset View
Changeset View
Standalone View
Standalone View
src/app/Providers/PaymentProvider.php
Show All 11 Lines | abstract class PaymentProvider | ||||
public const STATUS_PENDING = 'pending'; | public const STATUS_PENDING = 'pending'; | ||||
public const STATUS_AUTHORIZED = 'authorized'; | public const STATUS_AUTHORIZED = 'authorized'; | ||||
public const STATUS_EXPIRED = 'expired'; | public const STATUS_EXPIRED = 'expired'; | ||||
public const STATUS_FAILED = 'failed'; | public const STATUS_FAILED = 'failed'; | ||||
public const STATUS_PAID = 'paid'; | public const STATUS_PAID = 'paid'; | ||||
public const TYPE_ONEOFF = 'oneoff'; | public const TYPE_ONEOFF = 'oneoff'; | ||||
public const TYPE_RECURRING = 'recurring'; | public const TYPE_RECURRING = 'recurring'; | ||||
public const TYPE_MANDATE = 'mandate'; | |||||
/** 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; | ||||
/** | /** | ||||
* Factory method | * Factory method | ||||
* | * | ||||
* @param \App\Wallet|string|null $provider_or_wallet | * @param \App\Wallet|string|null $provider_or_wallet | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | abstract class PaymentProvider | ||||
*/ | */ | ||||
abstract public function webhook(): int; | abstract public function webhook(): int; | ||||
/** | /** | ||||
* Create a payment record in DB | * Create a payment record in DB | ||||
* | * | ||||
* @param array $payment Payment information | * @param array $payment Payment information | ||||
* @param string $wallet_id Wallet ID | * @param string $wallet_id Wallet ID | ||||
* | |||||
* @return \App\Payment Payment object | |||||
*/ | */ | ||||
protected static function storePayment(array $payment, $wallet_id): void | protected function storePayment(array $payment, $wallet_id): Payment | ||||
{ | { | ||||
$db_payment = new Payment(); | $db_payment = new Payment(); | ||||
$db_payment->id = $payment['id']; | $db_payment->id = $payment['id']; | ||||
$db_payment->description = $payment['description']; | $db_payment->description = $payment['description'] ?? ''; | ||||
$db_payment->status = $payment['status']; | $db_payment->status = $payment['status'] ?? self::STATUS_OPEN; | ||||
$db_payment->amount = $payment['amount']; | $db_payment->amount = $payment['amount'] ?? 0; | ||||
$db_payment->type = $payment['type']; | |||||
$db_payment->wallet_id = $wallet_id; | $db_payment->wallet_id = $wallet_id; | ||||
$db_payment->provider = $this->name(); | |||||
$db_payment->save(); | $db_payment->save(); | ||||
return $db_payment; | |||||
} | } | ||||
} | } |