如何解析braintree创建客户响应?

时间:2015-09-13 18:18:55

标签: php braintree

我验证信用卡如下:

$result = Braintree_PaymentMethod::create([
    'paymentMethodNonce' => nonceFromTheClient,
    'options' => [
        'verifyCard' => true
    ]
]);

验证成功后,我会找回一个包含以下内容的巨大对象:

  

Braintree_Result_Successful [Braintree_Customer [id = 123456,merchantId = xyz,firstName =,lastName =,company =,email =,phone =,fax =,website =,createdAt = Friday,11-Sep-15 22:05:53 UTC,updatedAt =星期五,11-Sep-15 22:05:53 UTC,customFields =,creditCards = 0 = Braintree_CreditCard [bin = 411111,expirationMonth = 03,expirationYear = 2017,last4 = 1111,cardType = Visa,cardholderName = sc ,commercial = Unknown,countryOfIssuance = Unknown,createdAt = Friday,11-Sep-15 22:05:53 UTC,customerId = 64065056,customerLocation = US,debit = Unknown,default = 1,durbinRegulated = Unknown,expired =,healthcare =未知,imageUrl = https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox,issuingBank =未知,工资单=未知,预付=未知,订阅=,令牌= 384zbr,uniqueNumberIdentifier = 123xyz,updatedAt =星期五,11-Sep-15 22:05:53 UTC,venmoSdk =,verifications = 0 = status = verified,cvvResponseCode = M,avsErrorResponseCode =,avsPostalCodeResponseCode = I,avsStreetAddressResponseCode = I,gatewayRejectionReason =,merchantAccountId = SignNow,processorResponseCode = 1000,processorRe sponseText = Approved,id = d2jqnd,billing = firstName =,lastName =,company =,streetAddress =,extendedAddress =,locality =,region =,postalCode =,countryName =,creditCard = token = 384zbr,bin = 411111,last4 = 1111 ,cardType = Visa,expirationMonth = 03,expirationYear = 2017,customerLocation = US,cardholderName = sc,uniqueNumberIdentifier = xyz123,prepaid = Unknown,healthcare = Unknown,debit = Unknown,durbinRegulated = Unknown,commercial = Unknown,payroll = Unknown,issuedBank =未知,countryOfIssuance =未知,productId =未知,createdAt =星期五,11-Sep-15 22:05:52 UTC,updatedAt =星期五,11-Sep-15 22:05:53 UTC,riskData = id = xyz,decision = Approve,billingAddress =,expirationDate = 03/2017,maskedNumber = 411111 ****** 1111,......]]]]] [] []

我想阅读信用卡令牌值,如上面的回复所示:"令牌= 384zbr"

我尝试通过以下方式访问它,但无效

$result->creditCard->token
$result->creditCards[0]->token

我得到一个异常,说明" Braintree_Result_Successful上的未定义属性:creditCard [] []。"

4 个答案:

答案 0 :(得分:1)

如果您使用print_r而不是print,则对象的结构将更容易阅读! $result->paymentMethod->token是您从结果对象访问令牌的方式。

答案 1 :(得分:0)

Can you this:

$ token = result->Braintree_Result_Successful[0]-> Braintree_Customer[0]->token

答案 2 :(得分:0)

Braintree的支持帮助我纠正了它。访问令牌的正确方法是

$result->customer->paymentMethods[0]->token;

答案 3 :(得分:0)

我尝试使用文档中的参数但它不存在,因此阅读Braintree客户类我发现paymentMethods是一种返回paymentMethods数组的方法。也许如果你遇到同样的问题,试试这个:

$result->customer->paymentMethods()[0]->token;