alexvargash/laravel-stripe-plaid

一个简单的包,用于从Plaid令牌创建Stripe银行账户令牌。

1.1.0 2020-11-12 14:53 UTC

This package is auto-updated.

Last update: 2024-09-12 23:31:19 UTC


README

Build Status StyleCI

一个简单的包,用于从Plaid Link创建Stripe银行账户令牌。

安装

此包需要Laravel 5.5或更高版本。

使用composer安装包

composer require alexvargash/laravel-stripe-plaid

服务提供程序将自动注册。

您可以使用以下命令发布配置文件:

php artisan vendor:publish --provider="AlexVargash\LaravelStripePlaid\StripePlaidServiceProvider" --tag="config"

发布后,config/stripe-plaid.php配置文件包含

return [

    /*
    |--------------------------------------------------------------------------
    | Environment
    |--------------------------------------------------------------------------
    |
    | The environment on which the API host will be set up, the accepted values
    | are: sandbox, development and production.
    | https://plaid.com/docs/api/#api-host
    |
    */
    'environment' => env('PLAID_ENVIRONMENT', ''),

    /*
    |--------------------------------------------------------------------------
    | Secret
    |--------------------------------------------------------------------------
    |
    | Private API key, here you need to add the respective secret key based on
    | the environment that is set up. This value can be found on your Plaid
    | account under the keys section.
    | https://plaid.com/docs/api/tokens/#token-endpoints
    |
    */
    'secret' => env('PLAID_SECRET', ''),

    /*
    |--------------------------------------------------------------------------
    | Client Id
    |--------------------------------------------------------------------------
    |
    | The client id is an identifier for the Plaid account and can be found
    | on your Plaid account under the keys section. This value is always
    | the same, doesn't change based on environment.
    | https://plaid.com/docs/api/tokens/#token-endpoints
    |
    */
    'client_id' => env('PLAID_CLIENT_ID', ''),

    /*
    |--------------------------------------------------------------------------
    | Client Name
    |--------------------------------------------------------------------------
    |
    | The name of your application, as it should be displayed in Link.
    | https://plaid.com/docs/api/tokens/#token-endpoints
    |
    */
    'client_name' => env('PLAID_CLIENT_NAME', ''),

    /*
    |--------------------------------------------------------------------------
    | Language
    |--------------------------------------------------------------------------
    |
    | The language that Link should be displayed in.
    | When using a Link customization, the language configured here must match the setting
    | in the customization, or the customization will not be applied.
    | Supported languages are: English ('en'), French ('fr'), Spanish ('es'), Dutch ('nl')
    | https://plaid.com/docs/api/tokens/#token-endpoints
    |
    */
    'language' => 'en',

    /*
    |--------------------------------------------------------------------------
    | Country Codes
    |--------------------------------------------------------------------------
    |
    | Specify an array of Plaid-supported country codes using the ISO-3166-1 alpha-2 country code standard.
    | Note that if you initialize with a European country code, your users will see the European consent panel
    | during the Link flow.
    | If Link is launched with multiple country codes, only products that you are enabled for in all countries will be used by Link.
    | Supported country codes are: US, CA, ES, FR, GB, IE, NL. Example value: ['US', 'CA'].
    | https://plaid.com/docs/api/tokens/#token-endpoints
    |
    */
    'country_codes' => ['US'],

    /*
    |--------------------------------------------------------------------------
    | Products
    |--------------------------------------------------------------------------
    |
    | List of Plaid product(s) you wish to use. If launching Link in update mode,
    | should be omitted; required otherwise
    | Supported products are: transactions, auth, identity, assets, investments, liabilities, payment_initiation.
    | Example value: ['auth', 'transactions']
    | https://plaid.com/docs/api/tokens/#token-endpoints
    |
    */
    'products' => ['auth', 'transactions'],

];

使用方法

首先,将Plaid密钥和环境添加到config/stripe-plaid.php文件或您的.env文件中。

PLAID_ENVIRONMENT=sandbox
PLAID_SECRET=your_plaid_secret_key
PLAID_CLIENT_ID=your_plaid_client_id
PLAID_CLIENT_NAME=your_app_name

然后,您需要创建link_token,这是初始化Link时所需的参数。一旦初始化Link,它将返回一个public_token

要创建公共令牌,请使用createLinkToken,此函数需要$clientUserId(您可以在此处找到更多信息),如果未提供这些值,则将使用config/stripe-plaid.php配置文件中的值。

use AlexVargash\LaravelStripePlaid\StripePlaid;

$clientUserId = 'client_user_id';

$stripePlaid = new StripePlaid();
$linkToken   = $stripePlaid->createLinkToken($clientUserId);

现在,您可以使用$linkToken的值在Link Web上获取public_tokenaccount_id值。

use AlexVargash\LaravelStripePlaid\StripePlaid;

$accountId   = 'plaid_link_account_id';
$publicToken = 'plaid_link_public_token';

$stripePlaid = new StripePlaid();
$stripeToken = $stripePlaid->getStripeToken($publicToken, $accountId);

之后,您可以使用$stripeToken处理支付,就像处理Stripe Elements令牌一样。

链接创建和交换也可以使用外观类完成。

use AlexVargash\LaravelStripePlaid\Facades\StripePlaid;

$clientUserId = 'your_end_user_id';

$linkToken    = StripePlaid::createLinkToken($clientUserId);
use AlexVargash\LaravelStripePlaid\Facades\StripePlaid;

$accountId   = 'plaid_link_account_id';
$publicToken = 'plaid_link_public_token';

$stripeToken = StripePlaid::getStripeToken($publicToken, $accountId);

或者,在令牌交换之前可以设置Plaid密钥,这在需要使用多个Plaid账户时非常有用。

use AlexVargash\LaravelStripePlaid\StripePlaid;

$secret      = 'your_plaid_secret_key';
$clientId    = 'your_plaid_client_id';
$environment = 'sandbox';
$accountId   = 'plaid_link_account_id';
$publicToken = 'plaid_link_public_token';

$stripeToken = StripePlaid::make($secret, $clientId, $environment)->getStripeToken($publicToken, $accountId);

异常

当发生错误时,将抛出PlaidException。您可以在Exceptions\Handler.php文件上捕获PlaidException

public function render($request, Exception $exception)
{
    if ($exception instanceof \AlexVargash\LaravelStripePlaid\Exceptions\PlaidException) {
        // Manage exception here ...
    }

    return parent::render($request, $exception);
}

贡献

欢迎提交拉取请求。对于重大更改,请先打开一个问题以讨论您想更改的内容。

请确保根据需要更新测试。

贡献者

Rogelio Bazan

许可

MIT