6

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?

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' => '[email protected]',
        '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' => '[email protected]',
        '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']);

?>
5
  • print_r() behaves like echo, and so the null value prints nothing, whereas var_dump() fully inspects it to show its value (if it has one) and type - and they're null. Now as to why they are null instead of populated? That depends on when you are refreshing it. The $_POST values would only be present at the moment the request is received. I don't know Braintree, so I can't speculate on what it expects, but your use of the term "refresh" on the webhooks script makes me suspicious that you are loading it manually somehow, whereby the POST values wouldn't be present. Dec 26, 2015 at 23:11
  • @MichaelBerkowski I think I see what you're saying about the manual refresh. It's almost as if by the time I hit refresh the variable gets blanked out. Got any tips on how I can test this webhook and accurately tell what gets returned? Dec 27, 2015 at 4:45
  • Is this what you are working from? You won't be able to visit the webhooks.php script and get mraningful output from in because braintree is what calls to it. You'll never see BT's post data there because HTTP requests are stateless. If you create a form with bt_payload, bt_signature inputs and post it to webhooks.php, then you would see the values you sent. Merely visitung that script will not give you a helpful response. Dec 28, 2015 at 1:07
  • Use exit after print_r may helps you Dec 28, 2015 at 7:49
  • is this scrip transferring directly to the user's bank account? Jul 21, 2016 at 16:25

2 Answers 2

0

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!

0

add die; after last line of print_r()

2
  • Comparing this to the existing answer, what benefit does die offer over wp_die? Jul 3, 2020 at 21:05
  • die returns clean page , wp_die returns WP error-styled page Jul 3, 2020 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.