1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Models/Gateway.php

223 lines
13 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-11 05:32:07 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-11 05:32:07 +02:00
*/
namespace App\Models;
2023-03-08 08:33:42 +01:00
/**
* App\Models\Gateway
*
* @property int $id
* @property string $name
* @property string $key
* @property string $provider
* @property bool $visible
* @property int $sort_order
* @property string|null $site_url
* @property bool $is_offsite
* @property bool $is_secure
* @property object|null $fields
* @property string $default_gateway_type_id
* @property int|null $created_at
* @property int|null $updated_at
* @property-read mixed $options
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel company()
* @method static \Illuminate\Database\Eloquent\Builder|StaticModel exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Gateway newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Gateway query()
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereDefaultGatewayTypeId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereFields($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereIsOffsite($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereIsSecure($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereKey($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereProvider($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereSiteUrl($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereSortOrder($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Gateway whereVisible($value)
* @mixin \Eloquent
*/
class Gateway extends StaticModel
{
2019-09-17 12:27:48 +02:00
protected $casts = [
'is_offsite' => 'boolean',
'is_secure' => 'boolean',
2019-10-15 12:36:51 +02:00
'recommended' => 'boolean',
2020-10-12 01:21:24 +02:00
'visible' => 'boolean',
'sort_order' => 'int',
'updated_at' => 'timestamp',
'created_at' => 'timestamp',
'default_gateway_type_id' => 'string',
// 'fields' => 'json',
'fields' => 'object',
2020-10-06 05:01:28 +02:00
'options' => 'array',
];
protected $appends = [
'options',
2019-09-17 12:27:48 +02:00
];
2020-07-05 10:59:28 +02:00
protected $dateFormat = 'Y-m-d H:i:s.u';
2020-10-06 05:01:28 +02:00
public function getOptionsAttribute()
{
return $this->getMethods();
}
2019-09-05 14:42:26 +02:00
/**
* Test if gateway is custom.
* @return bool TRUE|FALSE
2019-09-05 14:42:26 +02:00
*/
2024-01-14 05:05:00 +01:00
public function isCustom(): bool
2019-09-05 14:42:26 +02:00
{
return in_array($this->id, [62, 67, 68]); //static table ids of the custom gateways
}
2020-09-28 04:56:11 +02:00
public function getHelp()
{
$link = '';
if ($this->id == 1) {
$link = 'http://reseller.authorize.net/application/?id=5560364';
2023-11-26 08:41:42 +01:00
} elseif (in_array($this->id, [15,60,61])) {
2020-09-28 04:56:11 +02:00
$link = 'https://www.paypal.com/us/cgi-bin/webscr?cmd=_login-api-run';
} elseif ($this->id == 24) {
$link = 'https://www.2checkout.com/referral?r=2c37ac2298';
} elseif ($this->id == 35) {
$link = 'https://bitpay.com/dashboard/signup';
} elseif ($this->id == 18) {
$link = 'https://applications.sagepay.com/apply/2C02C252-0F8A-1B84-E10D-CF933EFCAA99';
} elseif ($this->id == 20 || $this->id == 56) {
2020-09-28 04:56:11 +02:00
$link = 'https://dashboard.stripe.com/account/apikeys';
2022-04-18 04:47:08 +02:00
} elseif ($this->id == 59) {
$link = 'https://www.forte.net/';
2020-11-25 15:19:52 +01:00
}
2020-09-28 04:56:11 +02:00
2020-09-29 06:32:29 +02:00
return $link;
2020-09-28 04:56:11 +02:00
}
2020-10-06 05:01:28 +02:00
/**
* Returns an array of methods and the gatewaytypes possible
2020-11-25 15:19:52 +01:00
*
* @return array
2021-03-16 14:40:58 +01:00
*/
2020-10-06 05:01:28 +02:00
public function getMethods()
{
switch ($this->id) {
case 1:
2021-08-18 13:46:04 +02:00
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Authorize.net
2021-07-22 03:30:16 +02:00
case 3:
return [GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true]]; //eWay
2021-08-18 13:21:05 +02:00
case 11:
return [GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true]]; //Payfast
2021-08-14 11:32:16 +02:00
case 7:
return [
GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']], // Mollie
GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => [' ']],
GatewayType::KBC => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']],
GatewayType::BANCONTACT => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']],
GatewayType::IDEAL => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']],
2021-08-14 11:32:16 +02:00
];
2020-10-06 05:01:28 +02:00
case 15:
return [
GatewayType::PAYPAL => ['refund' => false, 'token_billing' => false],
]; //Paypal
2020-10-06 05:01:28 +02:00
case 20:
2023-03-18 08:24:56 +01:00
case 56:
return [
2023-03-17 03:55:46 +01:00
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'customer.source.updated','payment_intent.processing', 'payment_intent.payment_failed']],
GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => false, 'webhooks' => ['payment_intent.processing','payment_intent.succeeded','payment_intent.partially_funded', 'payment_intent.payment_failed']],
2021-09-21 11:55:15 +02:00
GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false],
GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false],
2023-03-17 03:55:46 +01:00
GatewayType::BACS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.processing', 'payment_intent.succeeded', 'mandate.updated', 'payment_intent.payment_failed']],
GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::KLARNA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::SEPA => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::PRZELEWY24 => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::GIROPAY => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::EPS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::BANCONTACT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::BECS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::IDEAL => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
GatewayType::ACSS => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded', 'payment_intent.payment_failed']],
2023-01-06 08:43:28 +01:00
GatewayType::FPX => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']],
];
2020-10-06 05:01:28 +02:00
case 39:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']]]; //Checkout
2021-07-21 12:35:22 +02:00
case 46:
return [GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true]]; //Paytrace
2021-06-11 09:39:51 +02:00
case 49:
return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']],
]; //WePay
2021-05-04 14:56:30 +02:00
case 50:
return [
2021-08-11 08:43:20 +02:00
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], //Braintree
2021-08-26 15:37:17 +02:00
GatewayType::PAYPAL => ['refund' => true, 'token_billing' => true],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']],
2021-05-04 14:56:30 +02:00
];
2021-08-14 11:32:16 +02:00
case 57:
2021-08-04 14:31:47 +02:00
return [
2023-08-19 03:13:52 +02:00
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], //Square
2021-08-04 14:31:47 +02:00
];
2021-09-28 18:24:35 +02:00
case 52:
return [
2023-09-17 10:44:05 +02:00
GatewayType::BANK_TRANSFER => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']], // GoCardless
GatewayType::DIRECT_DEBIT => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
GatewayType::SEPA => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
GatewayType::INSTANT_BANK_PAY => ['refund' => false, 'token_billing' => true, 'webhooks' => ['confirmed','paid_out','failed','fulfilled']],
2021-09-28 18:24:35 +02:00
];
2021-10-07 16:24:40 +02:00
case 58:
return [
GatewayType::HOSTED_PAGE => ['refund' => false, 'token_billing' => false, 'webhooks' => [' ']], // Razorpay
2021-10-07 16:24:40 +02:00
];
2022-04-18 04:47:08 +02:00
case 59:
return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true], // Forte
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => [' ']],
];
2023-06-20 15:10:25 +02:00
case 60:
return [
GatewayType::PAYPAL => ['refund' => false, 'token_billing' => false],
2023-06-21 14:19:13 +02:00
GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => false],
GatewayType::VENMO => ['refund' => false, 'token_billing' => false],
2023-07-23 01:32:05 +02:00
// GatewayType::SEPA => ['refund' => false, 'token_billing' => false],
// GatewayType::BANCONTACT => ['refund' => false, 'token_billing' => false],
// GatewayType::EPS => ['refund' => false, 'token_billing' => false],
// GatewayType::MYBANK => ['refund' => false, 'token_billing' => false],
// GatewayType::PAYLATER => ['refund' => false, 'token_billing' => false],
// GatewayType::PRZELEWY24 => ['refund' => false, 'token_billing' => false],
// GatewayType::SOFORT => ['refund' => false, 'token_billing' => false],
2023-06-20 15:10:25 +02:00
]; //Paypal
2023-10-16 03:05:19 +02:00
case 61:
return [
GatewayType::PAYPAL => ['refund' => false, 'token_billing' => false],
GatewayType::CREDIT_CARD => ['refund' => false, 'token_billing' => false],
GatewayType::VENMO => ['refund' => false, 'token_billing' => false],
// GatewayType::SEPA => ['refund' => false, 'token_billing' => false],
// GatewayType::BANCONTACT => ['refund' => false, 'token_billing' => false],
// GatewayType::EPS => ['refund' => false, 'token_billing' => false],
// GatewayType::MYBANK => ['refund' => false, 'token_billing' => false],
2023-12-07 09:32:08 +01:00
GatewayType::PAYLATER => ['refund' => false, 'token_billing' => false],
2023-10-16 03:05:19 +02:00
// GatewayType::PRZELEWY24 => ['refund' => false, 'token_billing' => false],
// GatewayType::SOFORT => ['refund' => false, 'token_billing' => false],
]; //Paypal PPCP
2020-10-06 05:01:28 +02:00
default:
2020-10-11 11:17:33 +02:00
return [];
2020-10-06 05:01:28 +02:00
}
}
}