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

177 lines
4.2 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-03-25 20:56:31 +01:00
use Eloquent;
2015-03-26 07:24:02 +01:00
use Omnipay;
2015-12-02 14:26:06 +01:00
use Utils;
2015-03-25 20:56:31 +01:00
/**
* Class Gateway
*/
2015-03-16 22:45:25 +01:00
class Gateway extends Eloquent
{
/**
* @var bool
*/
2015-03-16 22:45:25 +01:00
public $timestamps = true;
/**
* @var array
*/
2016-06-20 16:14:43 +02:00
public static $gatewayTypes = [
GATEWAY_TYPE_CREDIT_CARD,
GATEWAY_TYPE_BANK_TRANSFER,
GATEWAY_TYPE_PAYPAL,
GATEWAY_TYPE_BITCOIN,
GATEWAY_TYPE_DWOLLA,
GATEWAY_TYPE_TOKEN,
];
2016-06-09 09:56:22 +02:00
// these will appear in the primary gateway select
// the rest are shown when selecting 'more options'
/**
* @var array
*/
2016-06-09 09:56:22 +02:00
public static $preferred = [
GATEWAY_PAYPAL_EXPRESS,
GATEWAY_BITPAY,
GATEWAY_DWOLLA,
GATEWAY_STRIPE,
GATEWAY_BRAINTREE,
2016-06-22 20:42:09 +02:00
GATEWAY_AUTHORIZE_NET,
GATEWAY_MOLLIE,
2016-06-09 09:56:22 +02:00
];
// allow adding these gateway if another gateway
// is already configured
/**
* @var array
*/
2016-06-09 09:56:22 +02:00
public static $alternate = [
GATEWAY_PAYPAL_EXPRESS,
GATEWAY_BITPAY,
GATEWAY_DWOLLA,
];
/**
* @var array
*/
2015-05-31 14:37:29 +02:00
public static $hiddenFields = [
// PayPal
'headerImageUrl',
'solutionType',
'landingPage',
'brandName',
'logoImageUrl',
'borderColor',
// Dwolla
2015-06-07 10:05:30 +02:00
'returnUrl',
2015-05-31 14:37:29 +02:00
];
/**
* @var array
*/
2015-05-31 14:37:29 +02:00
public static $optionalFields = [
// PayPal
'testMode',
'developerMode',
2015-06-03 19:55:48 +02:00
// Dwolla
'sandbox',
2015-05-31 14:37:29 +02:00
];
/**
* @return string
*/
2015-03-16 22:45:25 +01:00
public function getLogoUrl()
{
return '/images/gateways/logo_'.$this->provider.'.png';
}
/**
* @param $gatewayId
* @return bool
*/
2015-11-09 20:24:22 +01:00
public function isGateway($gatewayId)
{
return $this->id == $gatewayId;
}
/**
* @param $type
* @return string
*/
2015-12-02 14:26:06 +01:00
public static function getPaymentTypeName($type)
{
return Utils::toCamelCase(strtolower(str_replace('PAYMENT_TYPE_', '', $type)));
}
/**
* @param $gatewayIds
* @return int
*/
2016-06-09 09:56:22 +02:00
public static function hasStandardGateway($gatewayIds)
{
$diff = array_diff($gatewayIds, static::$alternate);
return count($diff);
}
/**
* @param $query
* @param $accountGatewaysIds
*/
2016-06-09 09:56:22 +02:00
public function scopePrimary($query, $accountGatewaysIds)
{
$query->where('payment_library_id', '=', 1)
->where('id', '!=', GATEWAY_WEPAY)
2016-06-22 20:42:09 +02:00
->whereIn('id', static::$preferred)
->whereIn('id', $accountGatewaysIds);
2016-06-09 09:56:22 +02:00
}
/**
* @param $query
* @param $accountGatewaysIds
*/
2016-06-09 09:56:22 +02:00
public function scopeSecondary($query, $accountGatewaysIds)
{
2016-06-22 20:42:09 +02:00
$query->where('payment_library_id', '=', 1)
->where('id', '!=', GATEWAY_WEPAY)
->whereNotIn('id', static::$preferred)
->whereIn('id', $accountGatewaysIds);
2016-06-09 09:56:22 +02:00
}
/**
* @return string|\Symfony\Component\Translation\TranslatorInterface
*/
2015-03-16 22:45:25 +01:00
public function getHelp()
{
$link = '';
2016-06-20 16:14:43 +02:00
if ($this->id == GATEWAY_AUTHORIZE_NET) {
2015-03-16 22:45:25 +01:00
$link = 'http://reseller.authorize.net/application/?id=5560364';
} elseif ($this->id == GATEWAY_PAYPAL_EXPRESS) {
$link = 'https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run';
} elseif ($this->id == GATEWAY_TWO_CHECKOUT) {
$link = 'https://www.2checkout.com/referral?r=2c37ac2298';
2015-04-17 13:57:17 +02:00
} elseif ($this->id == GATEWAY_BITPAY) {
$link = 'https://bitpay.com/dashboard/signup';
2015-05-31 14:37:29 +02:00
} elseif ($this->id == GATEWAY_DWOLLA) {
$link = 'https://www.dwolla.com/register';
2016-03-17 14:28:28 +01:00
} elseif ($this->id == GATEWAY_SAGE_PAY_DIRECT || $this->id == GATEWAY_SAGE_PAY_SERVER) {
$link = 'https://applications.sagepay.com/apply/2C02C252-0F8A-1B84-E10D-CF933EFCAA99';
2015-03-16 22:45:25 +01:00
}
$key = 'texts.gateway_help_'.$this->id;
$str = trans($key, ['link' => "<a href='$link' target='_blank'>Click here</a>"]);
return $key != $str ? $str : '';
}
/**
* @return mixed
*/
2015-03-16 22:45:25 +01:00
public function getFields()
{
2015-04-15 18:35:41 +02:00
return Omnipay::create($this->provider)->getDefaultParameters();
}
2015-03-16 22:45:25 +01:00
}