1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/PaymentDrivers/StripePaymentDriver.php

128 lines
3.2 KiB
PHP
Raw Normal View History

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-13 00:33:48 +02:00
use Stripe\PaymentIntent;
2019-09-05 14:42:26 +02:00
use Stripe\Stripe;
2019-09-05 09:00:12 +02:00
class StripePaymentDriver extends BasePaymentDriver
{
protected $refundable = true;
2019-09-05 09:00:12 +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:
2019-09-13 00:33:48 +02:00
return 'gateways.stripe.credit_card';
2019-09-12 13:46:09 +02:00
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-13 00:33:48 +02:00
/**
* Creates a new String Payment Intent
* @param array $data The data array to be passed to Stripe
* @return PaymentIntent The Stripe payment intent object
*/
public function createIntent($data)
{
return PaymentIntent::create($data);
}
2019-09-05 14:42:26 +02:00
/************************************** Omnipay API methods **********************************************************/
2019-09-05 09:00:12 +02:00
}