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

标签 php payment braintree

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

我可以设置一个 clientToken

$clientToken["client_token"] = Braintree_ClientToken::generate());
return ($clientToken);

我可以通过以下方式处理第一笔付款:

$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,
        )
      ));

但是,当我尝试处理第二笔付款时,出现错误:

91609 – Customer ID has already been taken.

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

编辑: 因此,在仔细查看之后,我发现了另一个可以包含在 Braintree_Transaction::sale 中的字段,如下所示:

'customerId' => 'testId',

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

91510 – Customer ID is invalid.

所以我最终陷入了陷阱 22 - 我可以将第一组代码用于新客户但不能用于回头客,我可以将第二组代码用于回头客但不能用于新客户。我不能同时使用两者。所以我的解决方案是创建我自己的本地数据库条目,确定用户之前是否通过 braintree 付款并相应地替换代码。是否有更简化的方法?

最佳答案

我在布伦特里工作。如果您需要更多帮助,可以随时reach out to our support team .

你的想法是正确的。您需要在您这边跟踪 Braintree 是否存在客户 ID。

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

可以先尝试create the customer with Braintree ,如果错误代码为 91510,则忽略错误:

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

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

关于php - 如何使用现有的 customerId 处理 Braintree 付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29418104/

相关文章:

php - MySQL:选择 2 个最早记录的时间(AM)

php - 在 woocommerce_before_calculate_totals Hook 中获取购物车小计

css - 如何修改 CSS 以使付款表格具有黑色背景?

process - Paypal ipn 处理和下拉选项/价格按钮逻辑

paypal - 当我尝试设置欧元支付时,PayPal 使用 Braintree SDK 时出现问题。无法调试问题

php - 请帮助我理解这个 php 调试错误(Braintree-WooCommerce 扩展)

php - 解码 php mysql 中的编码值

php - 如何不只匹配一个正则表达式

payment-gateway - 支付宝一键购买

android - 通过应用内结算获取谷歌分析税