hasOne(User::class, 'id', 'user_id');
}
public function displayName(){
if($this->paypal_order_id) return 'PayPal';
if($this->card_type){
return "{$this->card_type} ****-****-{$this->card_last_four}Expires: {$this->expiration_month} / {$this->expiration_year}";
}
$parsed = json_decode($this->stripe_detail_json ?? $this->braintree_detail_json);
if(@$parsed->tenant){
return "{$parsed->tenant} - {$parsed->email}";
}
if(@$parsed->card) {
return "{$parsed->card->brand} ****-****-{$parsed->card->last4}Expires: {$parsed->card->exp_month} / {$parsed->card->exp_year}";
}
return 'Non-card Payment Method';
}
public function displayNameShort(){
if ($this->card_type) {
return "****-****-{$this->card_last_four}";
}
$parsed = json_decode($this->stripe_detail_json);
if(!@$parsed->card) return 'Non-card Payment Method';
return "****-****-{$parsed->card->last4}";
}
public function brand(){
if($this->card_type) return $this->card_type;
$parsed = json_decode($this->stripe_detail_json);
if(!@$parsed->card) return;
return $parsed->card->brand;
}
public function cardLast4(){
if($this->card_last_four) return $this->card_last_four;
$parsed = json_decode($this->stripe_detail_json);
if(!@$parsed->card) return '---';
return $parsed->card->last4;
}
public function stripeDetails() {
return json_decode($this->stripe_detail_json);
}
public function getWalletType(){
$data = $this->stripeDetails();
if(!@$data->card) return;
if(!@$data->card->wallet) return;
return toHumanReadable($data->card->wallet->type);
}
public function brandToCssClassName(){
$brand = $this->brand();
if(!$brand) return '';
$brand = strtolower($brand);
return preg_replace('/\s+/', '_', $brand);
}
public function financialTransactions(){
return $this->hasMany(FinancialTransaction::class, 'payment_method_id', 'id');
}
public function isExpired() {
$stripeDetailJson = json_decode($this->stripe_detail_json);
$expirationMonth = @$stripeDetailJson->card ? @$stripeDetailJson->card->exp_month : null;
$expirationYear = @$stripeDetailJson->card ? @$stripeDetailJson->card->exp_year : null;
if((int) $expirationYear >= (int) date('Y')){
if((int) $expirationMonth >= (int) date('m')){
return false;
}
}
return true;
}
}