i am trying to understand how to use braintree but their documents are becomeing hard to understand after all the errors that i am receiving.
what i am trying to do is submit customer billing information + credit card information to then receive a token so that i can store it in a db.
this is what i wrote and i am getting errors.
<?php
include_once("lib/Braintree.php"); //braintree library
include_once("config.php"); //the Braintree_Configurations
$result = Braintree_Customer::create(array(
'firstName' => 'Mike',
'lastName' => 'Jones',
'company' => 'Jones Co.',
'email' => 'mike.jones@example.com',
'phone' => '419.555.1234',
'fax' => '419.555.1235',
'website' => 'http://example.com',
'creditCard' => array(
'number' => '5105105105105100',
'expirationDate' => '05/12',
'cvv' => '123',
'cardholderName' => 'Mike Jones',
'billingAddress' => array(
'firstName' => 'Drew',
'lastName' => 'Smith',
'company' => 'Smith Co.',
'streetAddress' => '1 E Main St',
'extendedAddress' => 'Suite 101',
'locality' => 'Chicago',
'region' => 'IL',
'postalCode' => '60622',
'countryCodeAlpha2' => 'US'
)
)
));
if ($result->success) {
print_r("success!: " . $result->transaction->id);
} else if ($result->transaction) {
print_r("Error processing transaction:");
print_r("\n message: " . $result->message);
print_r("\n code: " . $result->transaction->processorResponseCode);
print_r("\n text: " . $result->transaction->processorResponseText);
} else {
print_r("Message: " . $result->message);
print_r("\nValidation errors: \n");
print_r($result->errors->deepAll());
}
?>
Just remove the line 'countryCodeAlpha2' => 'US' and your code will work. One thing more the result does not have transaction object which you are using like '$result->transaction->id'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.