$methods HitPay's names for the methods the merchant ticked * @property list|null $refused_methods Ticked methods HitPay refused (switched off in the merchant's HitPay account) * @property CarbonInterface|null $refused_at When HitPay last refused them * @property CarbonInterface|null $created_at * @property CarbonInterface|null $updated_at * @property-read Store $store */ #[Fillable(['api_key', 'methods', 'refused_methods', 'refused_at'])] class HitPayAccount extends Model { protected $table = 'hitpay_accounts'; protected $hidden = ['api_key']; /** * The HitPay methods we offer, by HitPay's own name. Cards, FPX and GrabPay stay with Stripe. */ public const array METHODS = ['duitnow', 'touch_n_go', 'shopee_pay']; /** * How long a refused method is left out of checkout before we try it again. The merchant may have * switched it on in HitPay meanwhile; saving the methods in Settings tries again at once. */ public const int RETRY_REFUSED_AFTER_MINUTES = 60; /** * The ticked methods to show shoppers: refused ones are left out for a while, so shoppers are not * offered something that fails. * * @return list */ public function offeredMethods(): array { $ticked = array_values(array_intersect(self::METHODS, $this->methods ?? [])); if ($this->refused_at === null || $this->refused_at->lt(now()->subMinutes(self::RETRY_REFUSED_AFTER_MINUTES))) { return $ticked; } return array_values(array_diff($ticked, $this->refused_methods ?? [])); } /** * Remember that HitPay refused these methods. * * @param list $methods */ public function refused(array $methods): void { $this->refused_methods = array_values(array_intersect(self::METHODS, $methods)); $this->refused_at = now(); $this->save(); } /** The merchant changed their methods or key: try every ticked method again. */ public function clearRefused(): void { $this->refused_methods = null; $this->refused_at = null; } /** * @return BelongsTo */ public function store(): BelongsTo { return $this->belongsTo(Store::class); } /** * @return array */ protected function casts(): array { return [ 'api_key' => 'encrypted', 'methods' => 'array', 'refused_methods' => 'array', 'refused_at' => 'datetime', ]; } }