1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-17 00:22:51 +01:00
invoiceninja/app/PaymentDrivers/Stripe/Connect/Account.php

211 lines
5.1 KiB
PHP
Raw Normal View History

2021-04-12 12:11:08 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\PaymentDrivers\Stripe\Connect;
class Account
{
2021-04-20 16:08:33 +02:00
/**
* @throws \Stripe\Exception\ApiErrorException
*/
public static function create(array $payload): \Stripe\Account
{
$stripe = new \Stripe\StripeClient(
2021-04-21 00:38:50 +02:00
config('ninja.ninja_stripe_key')
2021-04-20 16:08:33 +02:00
);
return $stripe->accounts->create([
'type' => 'standard',
'country' => $payload['country'],
'email' => $payload['email'],
]);
}
/**
* @throws \Stripe\Exception\ApiErrorException
*/
2021-04-21 16:36:08 +02:00
public static function link(string $account_id, string $token): \Stripe\AccountLink
2021-04-20 16:08:33 +02:00
{
$stripe = new \Stripe\StripeClient(
2021-04-21 00:38:50 +02:00
config('ninja.ninja_stripe_key')
2021-04-20 16:08:33 +02:00
);
return $stripe->accountLinks->create([
'account' => $account_id,
2021-04-21 16:36:08 +02:00
'refresh_url' => route('stripe_connect.initialization', $token),
'return_url' => route('stripe_connect.return'),
2021-04-20 16:08:33 +02:00
'type' => 'account_onboarding',
]);
}
2021-04-12 12:11:08 +02:00
2021-04-20 00:41:14 +02:00
/*** If this is a new account (ie there is no account_id in company_gateways.config, the we need to create an account as below.
2021-04-12 12:11:08 +02:00
///
// $stripe = new \Stripe\StripeClient(
// 'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
// );
// $stripe->accounts->create([
2021-04-20 00:41:14 +02:00
// 'type' => 'standard',
// 'country' => 'US', //if we have it - inject
// 'email' => 'jenny.rosen@example.com', //if we have it - inject
2021-04-12 12:11:08 +02:00
// ]);
///
//response
2021-04-20 00:41:14 +02:00
//******************* We should store the 'id' as a property in the config with the key `account_id`
2021-04-12 12:11:08 +02:00
/**
* {
"id": "acct_1032D82eZvKYlo2C",
"object": "account",
"business_profile": {
"mcc": null,
"name": "Stripe.com",
"product_description": null,
"support_address": null,
"support_email": null,
"support_phone": null,
"support_url": null,
"url": null
},
"capabilities": {
"card_payments": "active",
"transfers": "active"
},
"charges_enabled": false,
"country": "US",
"default_currency": "usd",
"details_submitted": false,
"email": "site@stripe.com",
"metadata": {},
"payouts_enabled": false,
"requirements": {
"current_deadline": null,
"currently_due": [
"business_profile.product_description",
"business_profile.support_phone",
"business_profile.url",
"external_account",
"tos_acceptance.date",
"tos_acceptance.ip"
],
"disabled_reason": "requirements.past_due",
"errors": [],
"eventually_due": [
"business_profile.product_description",
"business_profile.support_phone",
"business_profile.url",
"external_account",
"tos_acceptance.date",
"tos_acceptance.ip"
],
"past_due": [],
"pending_verification": []
},
"settings": {
"bacs_debit_payments": {},
"branding": {
"icon": null,
"logo": null,
"primary_color": null,
"secondary_color": null
},
"card_issuing": {
"tos_acceptance": {
"date": null,
"ip": null
}
},
"card_payments": {
"decline_on": {
"avs_failure": true,
"cvc_failure": false
},
"statement_descriptor_prefix": null
},
"dashboard": {
"display_name": "Stripe.com",
"timezone": "US/Pacific"
},
"payments": {
"statement_descriptor": null,
"statement_descriptor_kana": null,
"statement_descriptor_kanji": null
},
"payouts": {
"debit_negative_balances": true,
"schedule": {
"delay_days": 7,
"interval": "daily"
},
"statement_descriptor": null
},
"sepa_debit_payments": {}
},
"type": "standard"
}
*/
2021-04-20 00:41:14 +02:00
//At this stage we have an account, so we need to generate the account link
2021-04-12 12:11:08 +02:00
//then create the account link
2021-04-20 00:41:14 +02:00
// now we start the stripe onboarding flow
// https://stripe.com/docs/api/account_links/object
2021-04-20 16:08:33 +02:00
//
2021-04-20 00:41:14 +02:00
/**
* $stripe = new \Stripe\StripeClient(
'sk_test_4eC39HqLyjWDarjtT1zdp7dc'
);
$stripe->accountLinks->create([
'account' => 'acct_1032D82eZvKYlo2C',
'refresh_url' => 'https://example.com/reauth',
'return_url' => 'https://example.com/return',
'type' => 'account_onboarding',
]);
*/
/**
2021-04-20 16:08:33 +02:00
* Response =
2021-04-20 00:41:14 +02:00
* {
"object": "account_link",
"created": 1618869558,
"expires_at": 1618869858,
"url": "https://connect.stripe.com/setup/s/9BhFaPdfseRF"
}
*/
//The users account may not be active yet, we need to pull the account back and check for the property `charges_enabled`
//
//
// What next?
2021-04-20 16:08:33 +02:00
//
2021-04-20 00:41:14 +02:00
// Now we need to create a superclass of the StripePaymentDriver, i believe the only thing we need to change is the way we initialize the gateway..
/**
2021-04-20 16:08:33 +02:00
*
2021-04-20 00:41:14 +02:00
\Stripe\Stripe::setApiKey("{{PLATFORM_SECRET_KEY}}"); <--- platform secret key = Invoice Ninja secret key
\Stripe\Customer::create(
["email" => "person@example.edu"],
["stripe_account" => "{{CONNECTED_STRIPE_ACCOUNT_ID}}"] <------ company_gateway.config.account_id
);
*/
2021-04-20 16:08:33 +02:00
}