如何使用现有customerId处理Braintree付款

con*_*ool 8 php payment braintree

尝试使用Braintree设置iOS和PHP支付系统.

我可以设置一个clientToken

$clientToken["client_token"] = Braintree_ClientToken::generate());
return ($clientToken);
Run Code Online (Sandbox Code Playgroud)

我可以处理第一笔付款:

$result = Braintree_Transaction::sale(array(
        'amount' => '1',
        'paymentMethodNonce' => $nonce,
        'customer' => array(
            'id' => 'testId',
            'firstName' => 'John',
            'lastName' => 'Doe',
            'email' => 'john@doe.com',
        ),
        'options' => array(
            'submitForSettlement' => true,
            'storeInVaultOnSuccess' => true,
        )
      ));
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试处理第二笔付款时,我收到错误消息:

91609 – Customer ID has already been taken.
Run Code Online (Sandbox Code Playgroud)

如何使用相同的customerId('testId')处理同一客户的第二笔付款 - 当我尝试使用现有客户ID传递付款时,为什么会抛出错误?当然它应该只是将付款附加到同一个客户?这不是它的用途吗?

编辑:所以在环顾四周之后,我发现了另一个字段,我可以在Braintree_Transaction :: sale中包含如下:

'customerId' => 'testId',
Run Code Online (Sandbox Code Playgroud)

因此,这将允许我重新使用存储在Braintree保险库中的customerId.但是,对于第一次交易我得到错误:

91510 – Customer ID is invalid.
Run Code Online (Sandbox Code Playgroud)

所以我最终得到了一个问题 - 我可以使用第一组代码为新客户而不是重复客户,我可以使用第二组代表重复客户但不是新客户.我不能同时使用它们.所以我的解决方案是创建我自己的本地数据库条目,确定用户之前是否通过braintree付款并且代替了代码.有更简化的方法吗?

agf*_*agf 7

我在布伦特里工作.如果您需要更多帮助,可以随时联系我们的支持团队.

你有正确的想法.您需要跟踪您是否存在Braintree的客户ID.

有一个替代方案,但我不推荐它,因为它需要额外的API调用.

您可以先尝试使用Braintree创建客户,如果错误代码为91510以下内容,则忽略错误:

$result = Braintree_Customer::create(array(
        'id' => 'testId',
        'firstName' => 'John',
        'lastName' => 'Doe',
        'email' => 'john@doe.com',
));
Run Code Online (Sandbox Code Playgroud)

然后,您知道客户已经存在,或者您刚刚创建了它,并且您可以使用第二种方法来创建事务.

  • 我觉得文档也很少.它也不直观.到目前为止Stackoverflow支持很好:) (4认同)