Skip to content

Instantly share code, notes, and snippets.

@ideadude
Last active March 5, 2021 16:37
Show Gist options
  • Save ideadude/bbfc493fbb242ec28b8fb8543c9a4c46 to your computer and use it in GitHub Desktop.
Save ideadude/bbfc493fbb242ec28b8fb8543c9a4c46 to your computer and use it in GitHub Desktop.
Testing the Braintree Webhook with PMPro v2.0+
<?php
/**
* Add this function into a customizations plugin
* and then visit /?test_braintree_webhook from a browser.
*/
function init_test_braintree_webhook() {
if(!empty($_REQUEST['test_braintree_webhook'])) {
define('PMPRO_BRAINTREE_WEBHOOK_DEBUG', true);
$gateway = new PMProGateway_braintree();
$kind = \Braintree\WebhookNotification::SUBSCRIPTION_CHARGED_SUCCESSFULLY;
$subscription_transaction_id = 'arealsubidfromyourorderstotest'; //change this
$sample_notification = \Braintree\WebhookTesting::sampleNotification($kind, $subscription_transaction_id);
$_POST['bt_payload'] = $sample_notification['bt_payload'];
$_POST['bt_signature'] = $sample_notification['bt_signature'];
$_REQUEST['bt_payload'] = $sample_notification['bt_payload'];
$_REQUEST['bt_signature'] = $sample_notification['bt_signature'];
require_once(PMPRO_DIR . "/services/braintree-webhook.php");
exit;
}
}
add_action('init', 'init_test_braintree_webhook');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment