2015-03-18 00:39:03 +01:00
|
|
|
<?php namespace App\Models;
|
2015-03-16 22:45:25 +01:00
|
|
|
|
2015-11-01 19:21:11 +01:00
|
|
|
use Crypt;
|
2015-04-15 18:35:41 +02:00
|
|
|
use App\Models\Gateway;
|
2015-03-31 11:38:24 +02:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
class AccountGateway extends EntityModel
|
|
|
|
{
|
2015-03-31 11:38:24 +02:00
|
|
|
use SoftDeletes;
|
|
|
|
protected $dates = ['deleted_at'];
|
|
|
|
|
2015-11-05 23:37:04 +01:00
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return ENTITY_ACCOUNT_GATEWAY;
|
|
|
|
}
|
|
|
|
|
2015-03-16 22:45:25 +01:00
|
|
|
public function gateway()
|
|
|
|
{
|
2015-03-31 11:38:24 +02:00
|
|
|
return $this->belongsTo('App\Models\Gateway');
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getCreditcardTypes()
|
|
|
|
{
|
|
|
|
$flags = unserialize(CREDIT_CARDS);
|
|
|
|
$arrayOfImages = [];
|
|
|
|
|
|
|
|
foreach ($flags as $card => $name) {
|
|
|
|
if (($this->accepted_credit_cards & $card) == $card) {
|
|
|
|
$arrayOfImages[] = ['source' => asset($name['card']), 'alt' => $name['text']];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $arrayOfImages;
|
|
|
|
}
|
|
|
|
|
2015-11-01 19:21:11 +01:00
|
|
|
public function getPaymentType()
|
|
|
|
{
|
2015-04-15 18:35:41 +02:00
|
|
|
return Gateway::getPaymentType($this->gateway_id);
|
|
|
|
}
|
|
|
|
|
2015-11-01 19:21:11 +01:00
|
|
|
public function isPaymentType($type)
|
|
|
|
{
|
2015-04-15 18:35:41 +02:00
|
|
|
return $this->getPaymentType() == $type;
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
2015-07-01 21:01:12 +02:00
|
|
|
|
2015-11-01 19:21:11 +01:00
|
|
|
public function isGateway($gatewayId)
|
|
|
|
{
|
2015-07-01 21:01:12 +02:00
|
|
|
return $this->gateway_id == $gatewayId;
|
|
|
|
}
|
2015-11-01 19:21:11 +01:00
|
|
|
|
|
|
|
public function setConfig($config)
|
|
|
|
{
|
|
|
|
$this->config = Crypt::encrypt(json_encode($config));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getConfig()
|
|
|
|
{
|
|
|
|
return json_decode(Crypt::decrypt($this->config));
|
|
|
|
}
|
2015-11-29 21:13:50 +01:00
|
|
|
|
|
|
|
public function getConfigField($field)
|
|
|
|
{
|
2016-04-20 13:37:57 +02:00
|
|
|
return object_get($this->getConfig(), $field, false);
|
2015-11-29 21:13:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPublishableStripeKey()
|
|
|
|
{
|
|
|
|
if ( ! $this->isGateway(GATEWAY_STRIPE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getConfigField('publishableKey');
|
|
|
|
}
|
2016-04-28 22:38:01 +02:00
|
|
|
|
|
|
|
public function getAchEnabled()
|
|
|
|
{
|
|
|
|
return !empty($this->getConfigField('enableAch'));
|
|
|
|
}
|
|
|
|
|
2016-05-12 17:09:07 +02:00
|
|
|
public function getPayPalEnabled()
|
2016-05-07 04:33:03 +02:00
|
|
|
{
|
|
|
|
return !empty($this->getConfigField('enablePayPal'));
|
|
|
|
}
|
|
|
|
|
2016-04-28 22:38:01 +02:00
|
|
|
public function getPlaidSecret()
|
|
|
|
{
|
|
|
|
if ( ! $this->isGateway(GATEWAY_STRIPE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getConfigField('plaidSecret');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPlaidClientId()
|
|
|
|
{
|
|
|
|
if ( ! $this->isGateway(GATEWAY_STRIPE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getConfigField('plaidClientId');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPlaidPublicKey()
|
|
|
|
{
|
|
|
|
if ( ! $this->isGateway(GATEWAY_STRIPE)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->getConfigField('plaidPublicKey');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPlaidEnabled()
|
|
|
|
{
|
|
|
|
return !empty($this->getPlaidClientId()) && $this->getAchEnabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPlaidEnvironment()
|
|
|
|
{
|
|
|
|
if (!$this->getPlaidClientId()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$stripe_key = $this->getPublishableStripeKey();
|
|
|
|
|
2016-05-01 04:45:51 +02:00
|
|
|
return substr(trim($stripe_key), 0, 8) == 'pk_test_' ? 'tartan' : 'production';
|
2016-04-28 22:38:01 +02:00
|
|
|
}
|
2016-05-18 15:51:20 +02:00
|
|
|
|
|
|
|
public function getWebhookUrl()
|
|
|
|
{
|
|
|
|
$account = $this->account ? $this->account : Account::find($this->account_id);
|
|
|
|
return \URL::to(env('WEBHOOK_PREFIX','').'paymenthook/'.$account->account_key.'/'.$this->gateway_id.env('WEBHOOK_SUFFIX',''));
|
|
|
|
}
|
2015-03-16 22:45:25 +01:00
|
|
|
}
|
|
|
|
|