Here is the code I use to create Sub-merchant accounts in my Braintree account for testing purpose on my local machine using postman. The sub_merchant creation call will come from either from Android or iOS device using a custom form. In local this code is working fine with postman, can anyone suggest me how to capture the error messages if there any associated with any fields we are passing to Braintree from the $result object returned and display back to the client side screen in a neat way ?
<?php
include("../connection.php");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'braintree_environment_settings.php';
$dataReceived = json_decode(file_get_contents('php://input'), true);
//var_dump($dataReceived);
if((json_last_error() == JSON_ERROR_NONE))
{
// code to handle iOS call
$firstName = $dataReceived['firstName'];
$lastName = $dataReceived['lastName'];
$email = $dataReceived['email'];
$dateOfBirth = $dataReceived['dateOfBirth'];
$streetAddress = $dataReceived['streetAddress'];
$locality = $dataReceived['locality'];
$region = $dataReceived['region'];
$postalCode = $dataReceived['postalCode'];
$accountNumber = $dataReceived['accountNumber'];
$routingNumber = $dataReceived['routingNumber'];
}
else {
// code to handle Android call
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$dateOfBirth = $_POST['dateOfBirth'];
$streetAddress = $_POST['streetAddress'];
$locality = $_POST['locality'];
$region = $_POST['region'];
$postalCode = $_POST['postalCode'];
$accountNumber = $_POST['accountNumber'];
$routingNumber = $_POST['routingNumber'];
}
$merchantAccountParams = [
'individual' => [
'firstName' => $firstName,
'lastName' => $lastName,
'email' => $email,
'dateOfBirth' => $dateOfBirth,
'address' => [
'streetAddress' => $streetAddress,
'locality' => $locality,
'region' => $region,
'postalCode' => $postalCode
]
],
'funding' => [
'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,
'accountNumber' => $accountNumber,
'routingNumber' => $routingNumber
],
'tosAccepted' => true,
'masterMerchantAccountId' => 'zeefasys'
// 'id' => "Praveens_caffe_store"
];
$result = Braintree_MerchantAccount::create($merchantAccountParams);
$responseData = array('Merchant_ID' => $result->merchantAccount->id, "message" => "Success");
header('Content-type: application/json');
echo json_encode($responseData);
?>