1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00
invoiceninja/app/Models/Gateway.php

114 lines
3.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-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
2015-03-16 22:45:25 +01:00
class Gateway extends Eloquent
{
public $timestamps = true;
2015-05-31 14:37:29 +02:00
public static $paymentTypes = [
PAYMENT_TYPE_STRIPE,
2015-05-31 14:37:29 +02:00
PAYMENT_TYPE_CREDIT_CARD,
PAYMENT_TYPE_PAYPAL,
PAYMENT_TYPE_BITCOIN,
2016-01-18 10:13:39 +01:00
PAYMENT_TYPE_DIRECT_DEBIT,
PAYMENT_TYPE_DWOLLA,
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
];
public static $optionalFields = [
// PayPal
'testMode',
'developerMode',
2015-06-03 19:55:48 +02:00
// Dwolla
'sandbox',
2015-05-31 14:37:29 +02:00
];
2015-03-16 22:45:25 +01:00
public function getLogoUrl()
{
return '/images/gateways/logo_'.$this->provider.'.png';
}
2015-11-09 20:24:22 +01:00
public function isGateway($gatewayId)
{
return $this->id == $gatewayId;
}
2015-12-02 14:26:06 +01:00
public static function getPaymentTypeName($type)
{
return Utils::toCamelCase(strtolower(str_replace('PAYMENT_TYPE_', '', $type)));
}
/*
2015-06-10 22:55:23 +02:00
public static function getPaymentTypeLinks() {
$data = [];
foreach (self::$paymentTypes as $type) {
2015-12-02 14:26:06 +01:00
$data[] = Utils::toCamelCase(strtolower(str_replace('PAYMENT_TYPE_', '', $type)));
2015-06-10 22:55:23 +02:00
}
return $data;
}
2015-12-02 14:26:06 +01:00
*/
2015-06-10 22:55:23 +02:00
2015-03-16 22:45:25 +01:00
public function getHelp()
{
$link = '';
if ($this->id == GATEWAY_AUTHORIZE_NET || $this->id == GATEWAY_AUTHORIZE_NET_SIM) {
$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 : '';
}
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
2015-04-15 18:35:41 +02:00
public static function getPaymentType($gatewayId) {
if ($gatewayId == GATEWAY_PAYPAL_EXPRESS) {
return PAYMENT_TYPE_PAYPAL;
} else if ($gatewayId == GATEWAY_BITPAY) {
return PAYMENT_TYPE_BITCOIN;
2015-05-31 14:37:29 +02:00
} else if ($gatewayId == GATEWAY_DWOLLA) {
return PAYMENT_TYPE_DWOLLA;
} else if ($gatewayId == GATEWAY_GOCARDLESS) {
2016-01-18 10:13:39 +01:00
return PAYMENT_TYPE_DIRECT_DEBIT;
} else if ($gatewayId == GATEWAY_STRIPE) {
return PAYMENT_TYPE_STRIPE;
2015-03-16 22:45:25 +01:00
} else {
2015-04-15 18:35:41 +02:00
return PAYMENT_TYPE_CREDIT_CARD;
2015-03-16 22:45:25 +01:00
}
2015-04-15 18:35:41 +02:00
}
2015-03-16 22:45:25 +01:00
2015-04-15 18:35:41 +02:00
public static function getPrettyPaymentType($gatewayId) {
return trans('texts.' . strtolower(Gateway::getPaymentType($gatewayId)));
2015-03-16 22:45:25 +01:00
}
}