如何添加银行帐户并将其附加到"已连接的帐户"在条纹?

时间:2017-11-29 09:32:58

标签: php stripe-payments

Stripe API解释了如何创建帐户并对其进行更新: https://stripe.com/docs/api#external_accounts

Stripe Api还解释了如何创建银行帐户: https://stripe.com/docs/api#account_create_bank_account

我正在尝试为已关联的帐户创建一个银行帐户,但遗憾的是我一直屏蔽此错误消息:

  

缺少必需的参数:external_account。

以下是我开始创建关联帐户的方法:

public function test_stripe_create_connected_account(Request $request)
{

    \Stripe\Stripe::setApiKey("sk_test_...");

    $acct = \Stripe\Account::create(array(
        "country" => "CH",
        "type" => "custom",
        "email" => "test@test.ch"
    ));

}

然后我通过这种方式更新帐户来完成帐户:

public function test_stripe_update_account(Request $request)
{

    try {

        \Stripe\Stripe::setApiKey("sk_test_...");

        $account = \Stripe\Account::retrieve("acct_1BTRCOB5XLEUUY47");
        $account->support_email = "victor@krown.ch";
        $account->support_phone = "0041764604220";

        $account->legal_entity->type = "company";
        $account->legal_entity->business_name = "Barbosa Duvanel SARL";
        $account->legal_entity->additional_owners = NULL;

        //NAME
        $account->legal_entity->first_name = "Victor";
        $account->legal_entity->last_name = "Duvanel";

        //BIRTH DATE
        $account->legal_entity->dob->day = 25;
        $account->legal_entity->dob->month = 3;
        $account->legal_entity->dob->year = 1988;

        //ADDRESS
        $account->legal_entity->address->city = "Genève";
        $account->legal_entity->address->country = "CH";
        $account->legal_entity->address->line1 = "Av de la Roseraie 76A";
        $account->legal_entity->address->line2 = "Genève";
        $account->legal_entity->address->postal_code = "1207";
        $account->legal_entity->address->state = "Genève";

        //PERSONAL ADDRESS
        $account->legal_entity->personal_address->city = "Genève";
        $account->legal_entity->personal_address->country = "CH";
        $account->legal_entity->personal_address->line1 = "Av de la Roseraie 76A";
        $account->legal_entity->personal_address->line2 = "Genève";
        $account->legal_entity->personal_address->postal_code = "1207";
        $account->legal_entity->personal_address->state = "Genève";

        //GENERAL CONDITIONS ACCEPTATION
        $account->tos_acceptance->date = time();
        $account->tos_acceptance->ip = $_SERVER['REMOTE_ADDR'];

        $account->save();

        $message = 'OK';
        $status = true;

    } catch (\Exception $error) {
        $message = $error->getMessage();
        $status = false;
    }

    $results = (object)array(
        'message' => $message,
        'status' => $status,
    );

    $response = response()->json($results, 200);
    return $response;

}

最后,我正在尝试为我的用户添加一个新的银行帐户:

public function test_stripe_create_bank_account(Request $request)
{

    try {

        \Stripe\Stripe::setApiKey("sk_test_...");

        $account = \Stripe\Account::retrieve("acct_1BSoOaGS1D3TfSN5");

        $account->external_accounts->create(
            array(
                "object" => "bank_account",
                "account_number" => "CH820024024090647501F",
                "country" => "CH",
                "currency" => "CHF",
            )
        );

        $message = 'OK';
        $status = true;

    } catch (\Exception $error) {
        $message = $error->getMessage();
        $status = false;
    }

    $results = (object)array(
        'message' => $message,
        'status' => $status,
    );

    $response = response()->json($results, 200);
    return $response;

}

我做错了什么?

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:3)

您需要更改external account creation request以将数组包装在external_account参数名称下,如下所示:

$account->external_accounts->create(array(
    "external_account" => array(
        "object" => "bank_account",
        "account_number" => "CH820024024090647501F",
        "country" => "CH",
        "currency" => "CHF",
    )
));

答案 1 :(得分:0)

我在现有项目中使用以下代码。您可以不使用此代码 任何恐惧

public function Stripe(){
    Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
    try {
        // first create bank token
        $bankToken = \Stripe\Token::create([
            'bank_account' => [
                'country' => 'GB',
                'currency' => 'GBP',
                'account_holder_name' => 'Soura Sankar',
                'account_holder_type' => 'individual',
                'routing_number' => '108800',
                'account_number' => '00012345'
            ]
        ]); 
        // second create stripe account
        $stripeAccount = \Stripe\Account::create([
            "type" => "custom",
            "country" => "GB",
            "email" => "<Mail-Id>",   
            "business_type" => "individual",
            "individual" => [
                'address' => [
                    'city' => 'London',
                    'line1' => '16a, Little London, Milton Keynes, MK19 6HT ',
                    'postal_code' => 'MK19 6HT',            
                ],
                'dob'=>[
                    "day" => '25',
                    "month" => '02',
                    "year" => '1994'
                ],
                "email" => '<Mail-Id>',
                "first_name" => 'Soura',
                "last_name" => 'Ghosh',
                "gender" => 'male',
                "phone"=> "<Phone-No>"
            ]     
        ]);
        // third link the bank account with the stripe account
        $bankAccount = \Stripe\Account::createExternalAccount(
          $stripeAccount->id,['external_account' => $bankToken->id]
        );
        // Fourth stripe account update for tos acceptance
        \Stripe\Account::update(
            $stripeAccount->id,[
            'tos_acceptance' => [
                  'date' => time(),
                  'ip' => $_SERVER['REMOTE_ADDR'] // Assumes you're not using a proxy
                ],
            ]
        );
        $response = ["bankToken"=>$bankToken->id,"stripeAccount"=>$stripeAccount->id,"bankAccount"=>$bankAccount->id];
        dd($response);
    } catch (\Exception $e) {
       dd($e->jsonBody['error']['message']);
    }