【问题标题】:PHP: Stripe connect API would not accept card details?PHP:Stripe connect API 不接受卡详细信息?
【发布时间】:2019-03-14 16:38:10
【问题描述】:

我知道在这里问这个问题可能会在黑暗中扔石头,因为我发现了其他 2 个类似的问题,但没有一个有任何答案。

无论如何,我希望有人已经找到了解决方案并可以阐明它。

让我先解释一下这个场景,因为它可能有助于找到解决方案:

我正在像这样创建条纹custom connect accounts

$acct = \Stripe\Account::create(array(
    "country" => "US",
    "type" => "custom",
    "email" => "email@mail.com"
));

然后我像这样向他们添加Bank Accounts

$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "bank_account",
            "country" => "US",
            "currency" => "usd",
            "account_holder_name" => 'Jane Austen',
            "account_holder_type" => 'individual',
            "routing_number" => "111000025",
            "account_number" => "000123456789"
        )
));

到目前为止一切正常......

现在,我需要做的是能够将资金/付款从关联的自定义账户转移到他们的银行账户

为此,我需要向connetced account 添加一张信用卡,以便使用信用卡详细信息向银行账户付款。

所以我继续尝试:

$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "card",
            "exp_month" => 8,
            "exp_year" => 2018,
            "number" => "4012888888881881",
            "currency" => "usd",
            "cvc" => "123"
        )
));

这不起作用并给了我这个错误:

Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.

所以我改变了策略并尝试了这个:

$result = \Stripe\Token::create(
                    array(
                        "card" => array(
                        "name" => "Some Name",
                        "exp_month" => 8,
                        "exp_year" => 2018,
                        "number" => "4012888888881881",
                        "currency" => "usd",
                        "cvc" => "123"
                        )
                    ));



$token = $result['id'];


$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "card",
            "source" => "".$token.""
        )
));

但是,这给了我同样的错误信息!!!

这非常令人沮丧,因为如果您查看他们自己的 API 文档,您会清楚地看到他们说:

source required

Either a token, like the ones returned by Stripe.js, or a dictionary containing a user's credit card details (with the options shown below). Stripe will automatically validate the card. 

可以在这里看到:

https://stripe.com/docs/api#create_card

有人可以就这个问题提出建议吗?

我不能在我的项目中使用 stripe.js,所以我需要使用 API。

任何帮助将不胜感激。

提前致谢。

第一次编辑:

这是一个奇怪的..我从这里生成了一个条纹卡令牌:

https://codepen.io/fmartingr/pen/pGfhy

请注意,上面的 codepen 使用 stripe.js 来生成令牌....

并尝试在我的 PHP 代码中使用该令牌,如下所示:

$account->external_accounts->create(
array(
        'external_account' => array(
            "object" => "card",
            "source" => "tok_1AqPXeDQzcw33c71uncYBFdm"
        )
));

但这给了我完全相同的错误:

Requests made on behalf of a connected account must use card tokens from Stripe.js, but card details were directly provided.

【问题讨论】:

  • 您如何在第二次尝试中创建作为源发送的令牌?令牌是否成功从条带返回?
  • @Birdy,我的第一次尝试是使用$result = \Stripe\Token::create(...)。我已经在我的问题中包含了代码。此外,我用另一种尝试方式(使用 stripe.js)生成了令牌并直接在源代码中使用了该令牌,但这给了我相同的错误消息。
  • @Birdy,是的,我成功拿到了令牌。
  • 我可以在我的页面上简单地echo $token;,然后我会在我的页面上看到令牌。

标签: php stripe-connect


【解决方案1】:

请使用它,它将添加您的外部帐户

$result = \Stripe\Token::create(
                array(
                    "card" => array(
                    "name" => "Some Name",
                    "exp_month" => 8,
                    "exp_year" => 2018,
                    "number" => "4012888888881881",
                    "currency" => "usd",
                    "cvc" => "123"
                    )
                ));



$token = $result['id'];

$account->external_accounts->create(
   array(
      'external_account' => "".$token.""
));

【讨论】:

    猜你喜欢
    • 2019-04-29
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-09-28
    • 2016-08-08
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多