Print_r doesn’t return anything; var_dump shows NULL

I’m new to web dev and I’m experimenting with Braintree webhooks. I’m using their create submerchant example code to create a submerchant and then supposedly a notification is supposed to reach my server that says if it was successful or not.

My method: I refresh the submerchant.php page (I’m using WordPress on a NameCheap server), which then echo‘s “Success!”. Then I go to the webhooks.php page and refresh it. However, the var_dump‘s only return NULL NULL and the print_r‘s don’t return anything. Why does print_r not show anything?

Read More

submerchant.php – this creates the submerchant when I set $one = 1 and set a new id for the submerchant

<?php

require_once(__DIR__ . '/../braintree/lib/Braintree.php');

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('A');
Braintree_Configuration::publicKey('B');
Braintree_Configuration::privateKey('C');

 function fd_create_sm() {

    $one;

    $one = 1;

    if($one=1) {

    $merchantAccountParams = [
      'individual' => [
        'firstName' => 'Janez',
        'lastName' => 'Doe',
        'email' => 'jane@14ladders.com',
        'phone' => '5553334444',
        'dateOfBirth' => '1981-11-19',
        'ssn' => '456-45-4567',
        'address' => [
          'streetAddress' => '111 Main St',
          'locality' => 'Chicago',
          'region' => 'IL',
          'postalCode' => '60622'
        ]
      ],
      'business' => [
        'legalName' => 'Jane's Ladders',
        'dbaName' => 'Jane's Ladders',
        'taxId' => '98-7654321',
        'address' => [
          'streetAddress' => '111 Main St',
          'locality' => 'Chicago',
          'region' => 'IL',
          'postalCode' => '60622'
        ]
      ],
      'funding' => [
        'descriptor' => 'Red Ladders',
        'destination' => Braintree_MerchantAccount::FUNDING_DESTINATION_BANK,
        'email' => 'funding@blueladders.com',
        'mobilePhone' => '5555555555',
        'accountNumber' => '1123581321',
        'routingNumber' => '071101307'
      ],
      'tosAccepted' => true,
      'masterMerchantAccountId' => "na",
      'id' => "green_ladders"
    ];
    $result = Braintree_MerchantAccount::create($merchantAccountParams);

    $result->success;
    if($result->success) {
    echo 'Success!';
    } else {

    print_r($result->errors);

            $errordata;
            echo '***********';
            $BT_Errors = new Braintree_Error_ErrorCollection($errordata);
            echo '***********';
            $BT_Errors->deepAll();
            echo '***********';
            $BT_Errors->onHtmlField("transaction[amount]");

    }

    $result->merchantAccount->status;

    $result->merchantAccount->id;
    // "blue_ladders_store"
    $result->merchantAccount->masterMerchantAccount->id;
    // "14ladders_marketplace"
    $result->merchantAccount->masterMerchantAccount->status;
    // "active"

    } else {
    return;

    }
 }

fd_create_sm();

?>

webhooks.php

<?php

var_dump($_POST['bt_signature']);
var_dump($_POST['bt_payload']);

print_r($_POST['bt_signature']);
print_r($_POST['bt_payload']);

?>

Related posts

2 comments

  1. Most likely, the outputted data is stored within some output buffer. If you’re pretty sure you want to debug your code this way, try adding wp_die(); call right after you output data using print_r. That should help!

    One more thing: sometimes some of the code (not this particular case) is actually never outputted due to more complex data flow. For this cases it might be a good idea to use some 3-rd party debugging tools or, if you’re looking for simpler solution, you can write some of the output to some log file, and check the file afterwards.

    Good Luck!

Comments are closed.