Reputation: 147
I verify a credit card as follows:
$result = Braintree_PaymentMethod::create([
'paymentMethodNonce' => nonceFromTheClient,
'options' => [
'verifyCard' => true
]
]);
Once the verification is successful, I get back a huge object that consists of:
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=Friday, 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=Unknown, imageUrl=https://assets.braintreegateway.com/payment_method_logo/visa.png?environment=sandbox, issuingBank=Unknown, payroll=Unknown, prepaid=Unknown, subscriptions=, token=384zbr, uniqueNumberIdentifier=123xyz, updatedAt=Friday, 11-Sep-15 22:05:53 UTC, venmoSdk=, verifications=0=status=verified, cvvResponseCode=M, avsErrorResponseCode=, avsPostalCodeResponseCode=I, avsStreetAddressResponseCode=I, gatewayRejectionReason=, merchantAccountId=SignNow, processorResponseCode=1000, processorResponseText=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, issuingBank=Unknown, countryOfIssuance=Unknown, productId=Unknown, createdAt=Friday, 11-Sep-15 22:05:52 UTC, updatedAt=Friday, 11-Sep-15 22:05:53 UTC, riskData=id=xyz, decision=Approve, billingAddress=, expirationDate=03/2017, maskedNumber=411111******1111, ......]]]]] [] []
I want to read the credit card token value as seen in the above response: "token=384zbr"
I tried accessing it in the following ways, which did not work
$result->creditCard->token
$result->creditCards[0]->token
I get an exception that says "Undefined property on Braintree_Result_Successful: creditCard [] []."
Upvotes: 2
Views: 1444
Reputation: 1
I tried with the parameter in the documentation but it doesn't exist, so reading the Braintree Customer Class I found that paymentMethods is a method wich returns an array of paymentMethods. Maybe if you have the same problem try this:
$result->customer->paymentMethods()[0]->token;
Upvotes: 0
Reputation: 147
Braintree support helped me correct it. The correct way to access the token is
$result->customer->paymentMethods[0]->token;
Upvotes: 0
Reputation: 743
If you use print_r
instead of print
, the structure of the object will be much easier to read!
$result->paymentMethod->token
is how you access the token from the result object.
Upvotes: 1
Reputation: 3481
Can you this:
$ token = result->Braintree_Result_Successful[0]-> Braintree_Customer[0]->token
Upvotes: 0