2019-09-05 09:00:12 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\PaymentDrivers;
|
|
|
|
|
2019-09-08 14:13:55 +02:00
|
|
|
use App\Models\GatewayType;
|
2019-09-05 14:42:26 +02:00
|
|
|
use Stripe\Stripe;
|
|
|
|
|
2019-09-05 09:00:12 +02:00
|
|
|
class StripePaymentDriver extends BasePaymentDriver
|
|
|
|
{
|
2019-09-06 07:22:05 +02:00
|
|
|
protected $refundable = true;
|
2019-09-05 09:00:12 +02:00
|
|
|
|
2019-09-06 07:22:05 +02:00
|
|
|
protected $token_billing = true;
|
|
|
|
|
|
|
|
protected $customer_reference = 'customerReferenceParam';
|
|
|
|
|
2019-09-08 14:13:55 +02:00
|
|
|
|
2019-09-05 14:42:26 +02:00
|
|
|
/**
|
|
|
|
* Methods in this class are divided into
|
|
|
|
* two separate streams
|
|
|
|
*
|
|
|
|
* 1. Omnipay Specific
|
|
|
|
* 2. Stripe Specific
|
|
|
|
*
|
|
|
|
* Our Stripe integration is deeper than
|
|
|
|
* other gateways and therefore
|
|
|
|
* relies on direct calls to the API
|
|
|
|
*/
|
2019-09-08 14:13:55 +02:00
|
|
|
/************************************** Stripe API methods **********************************************************/
|
2019-09-05 14:42:26 +02:00
|
|
|
|
2019-09-08 14:13:55 +02:00
|
|
|
public function init($api_key)
|
|
|
|
{
|
|
|
|
Stripe::setApiKey($api_key);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Returns the gateway types
|
|
|
|
*/
|
|
|
|
public function gatewayTypes() :array
|
|
|
|
{
|
|
|
|
$types = [
|
|
|
|
GatewayType::CREDIT_CARD,
|
|
|
|
GatewayType::TOKEN,
|
|
|
|
];
|
|
|
|
|
|
|
|
if($this->company_gateway->getSofortEnabled() && $this->invitation && $this->client() && isset($this->client()->country) && in_array($this->client()->country, ['AUT', 'BEL', 'DEU', 'ITA', 'NLD', 'ESP']))
|
|
|
|
$types[] = GatewayType::SOFORT;
|
|
|
|
|
|
|
|
if($this->company_gateway->getAchEnabled())
|
|
|
|
$types[] = GatewayType::BANK_TRANSFER;
|
|
|
|
|
|
|
|
if ($this->company_gateway->getSepaEnabled())
|
|
|
|
$types[] = GatewayType::SEPA;
|
|
|
|
|
|
|
|
if ($this->company_gateway->getBitcoinEnabled())
|
|
|
|
$types[] = GatewayType::BITCOIN;
|
|
|
|
|
|
|
|
if ($this->company_gateway->getAlipayEnabled())
|
|
|
|
$types[] = GatewayType::ALIPAY;
|
|
|
|
|
|
|
|
if ($this->company_gateway->getApplePayEnabled())
|
|
|
|
$types[] = GatewayType::APPLE_PAY;
|
|
|
|
|
|
|
|
|
|
|
|
return $types;
|
|
|
|
|
2019-09-12 13:46:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function viewForType($payment_type)
|
|
|
|
{
|
|
|
|
switch ($payment_type) {
|
|
|
|
case GatewayType::CREDIT_CARD:
|
|
|
|
return 'gateways.stripe.credit_card';
|
|
|
|
break;
|
|
|
|
case GatewayType::TOKEN:
|
|
|
|
return 'gateways.stripe.token';
|
|
|
|
break;
|
|
|
|
case GatewayType::SOFORT:
|
|
|
|
return 'gateways.stripe.sofort';
|
|
|
|
break;
|
|
|
|
case GatewayType::BANK_TRANSFER:
|
|
|
|
return 'gateways.stripe.ach';
|
|
|
|
break;
|
|
|
|
case GatewayType::SEPA:
|
|
|
|
return 'gateways.stripe.sepa';
|
|
|
|
break;
|
|
|
|
case GatewayType::BITCOIN:
|
|
|
|
return 'gateways.stripe.other';
|
|
|
|
break;
|
|
|
|
case GatewayType::ALIPAY:
|
|
|
|
return 'gateways.stripe.other';
|
|
|
|
break;
|
|
|
|
case GatewayType::APPLE_PAY:
|
|
|
|
return 'gateways.stripe.other';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
# code...
|
|
|
|
break;
|
|
|
|
}
|
2019-09-08 14:13:55 +02:00
|
|
|
}
|
2019-09-05 14:42:26 +02:00
|
|
|
/************************************** Omnipay API methods **********************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-09-05 09:00:12 +02:00
|
|
|
}
|