1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
invoiceninja/app/Models/AccountGatewayToken.php

99 lines
2.3 KiB
PHP
Raw Normal View History

2015-03-18 00:39:03 +01:00
<?php namespace App\Models;
2015-03-16 22:45:25 +01:00
2015-04-13 21:43:51 +02:00
use Eloquent;
2015-03-31 11:38:24 +02:00
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class AccountGatewayToken
*/
2015-03-16 22:45:25 +01:00
class AccountGatewayToken extends Eloquent
{
2015-03-31 11:38:24 +02:00
use SoftDeletes;
/**
* @var array
*/
2015-03-31 11:38:24 +02:00
protected $dates = ['deleted_at'];
/**
* @var bool
*/
2015-03-16 22:45:25 +01:00
public $timestamps = true;
2016-05-11 00:46:32 +02:00
/**
* @var array
*/
2016-06-20 16:14:43 +02:00
protected $casts = [];
2016-05-11 00:46:32 +02:00
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
2016-05-11 00:46:32 +02:00
public function payment_methods()
{
return $this->hasMany('App\Models\PaymentMethod');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
2016-06-20 16:14:43 +02:00
public function account_gateway()
{
return $this->belongsTo('App\Models\AccountGateway');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
2016-05-11 00:46:32 +02:00
public function default_payment_method()
{
return $this->hasOne('App\Models\PaymentMethod', 'id', 'default_payment_method_id');
}
2016-06-20 16:14:43 +02:00
/**
* @return mixed
*/
2016-06-20 16:14:43 +02:00
public function autoBillLater()
{
return $this->default_payment_method->requiresDelayedAutoBill();
}
/**
* @param $query
* @param $clientId
* @param $accountGatewayId
* @return mixed
*/
2016-06-20 16:14:43 +02:00
public function scopeClientAndGateway($query, $clientId, $accountGatewayId)
{
$query->where('client_id', '=', $clientId)
->where('account_gateway_id', '=', $accountGatewayId);
return $query;
}
/**
* @return mixed
*/
2016-06-20 16:14:43 +02:00
public function gatewayName()
{
return $this->account_gateway->gateway->name;
}
/**
* @return bool|string
*/
2016-06-20 16:14:43 +02:00
public function gatewayLink()
{
$accountGateway = $this->account_gateway;
if ($accountGateway->gateway_id == GATEWAY_STRIPE) {
return "https://dashboard.stripe.com/customers/{$this->token}";
} elseif ($accountGateway->gateway_id == GATEWAY_BRAINTREE) {
$merchantId = $accountGateway->getConfig()->merchantId;
$testMode = $accountGateway->getConfig()->testMode;
return $testMode ? "https://sandbox.braintreegateway.com/merchants/{$merchantId}/customers/{$this->token}" : "https://www.braintreegateway.com/merchants/{$merchantId}/customers/{$this->token}";
} else {
return false;
}
}
}