public function beforeFilter()
 {
     parent::beforeFilter();
     $this->Auth->allow(array('processSubscription'));
     //webhook validation
     $btChallenge = '';
     if (isset($this->request->query['bt_challenge'])) {
         $btChallenge = $this->request->query['bt_challenge'];
     } elseif (isset($_GET["bt_challenge"])) {
         $btChallenge = $_GET["bt_challenge"];
     }
     if (!empty($btChallenge)) {
         echo Braintree_WebhookNotification::verify($btChallenge);
         exit;
     }
 }
Example #2
0
 public function webhooks()
 {
     require_once 'application/libraries/braintree_ci/lib/braintree.php';
     Braintree_Configuration::environment("sandbox");
     Braintree_Configuration::merchantId("yv7v3d5f833vjkp2");
     Braintree_Configuration::publicKey("chg92p6xsjrx4nhj");
     Braintree_Configuration::privateKey("da8986a0ea0ffa58ef149c5f101faee5");
     if ($_GET["bt_challenge"]) {
         echo Braintree_WebhookNotification::verify($_GET["bt_challenge"]);
     }
     if ($this->input->post('bt_signature') and $this->input->post('bt_payload')) {
         if (!($webhookNotification = $this->braintree_ci->webhooks_for_braintree($this->input->post('bt_signature'), $this->input->post('bt_payload')))) {
             $braintree_response_data = array('recurring_transaction' => 1, 'recurring_customer_id' => $webhookNotification->subscription->transactions[0]->customer[id], 'recurring_subscription_id' => $webhookNotification->subscription->id, 'recurring_subscription_status' => $webhookNotification->subscription->status, 'recurring_next_billing_amount' => $webhookNotification->subscription->nextBillAmount, 'recurring_next_billing_date' => $webhookNotification->subscription->nextBillingDate->format('Y-m-d'), 'recurring_current_billing_cycle' => $webhookNotification->subscription->currentBillingCycle, 'recurring_payment_method_token' => $webhookNotification->subscription->paymentMethodToken, 'recurring_currency_code' => $webhookNotification->subscription->transactions[0]->currencyIsoCode, 'recurring_transaction_failure' => 0, 'transaction_id' => $webhookNotification->subscription->transactions[0]->id, 'transaction_status' => $webhookNotification->subscription->transactions[0]->status, 'customer_billing_country_code_alpha_2' => $webhookNotification->subscription->transactions[0]->billing[countryCodeAlpha2], 'customer_billing_country_code_alpha_3' => $webhookNotification->subscription->transactions[0]->billing[countryCodeAlpha3], 'amount' => $webhookNotification->subscription->transactions[0]->amount, 'credit_card_type' => '');
             $this->load->model('payment_model');
             if (!$this->payment_model->update_order_info($braintree_response_data, $webhookNotification->subscription->transactions[0]->orderId, true)) {
                 $log_message = date('Y-m-d H:i:s') . ' A transaction has made with Customer ID' . $webhookNotification->subscription->transactions[0]->customer[id] . '. Transaction status is ' . $webhookNotification->subscription->transactions[0]->status . '. Paid amount is ' . $webhookNotification->subscription->transactions[0]->amount . ', but could not update database.';
                 log_message('error', $log_message);
             }
         }
     }
 }
Example #3
0
 public function __construct()
 {
     $config = array('environment' => 'sandbox', 'merchantId' => 'yv7v3d5f833vjkp2', 'publicKey' => 'chg92p6xsjrx4nhj', 'privateKey' => 'da8986a0ea0ffa58ef149c5f101faee5');
     require_once 'application/libraries/braintree_ci/lib/braintree.php';
     Braintree_Configuration::environment("sandbox");
     Braintree_Configuration::merchantId("yv7v3d5f833vjkp2");
     Braintree_Configuration::publicKey("chg92p6xsjrx4nhj");
     Braintree_Configuration::privateKey("da8986a0ea0ffa58ef149c5f101faee5");
     if ($_GET["bt_challenge"]) {
         echo Braintree_WebhookNotification::verify($_GET["bt_challenge"]);
         mail('*****@*****.**', 'Web Hook Notification', 'Message From get notification');
     }
     if (isset($_POST["bt_signature"]) and isset($_POST["bt_payload"])) {
         $webHookNotification = Braintree_WebhookNotification::parse($_POST["bt_signature"], $_POST["bt_payload"]);
         mail('*****@*****.**', 'Web Hook Notification', print_r($webHookNotification, true));
         /*$this->load->model( 'payment' );
         
                     $braintree_response_data = array(
                         'recurring_transaction'                     => 1,
                         'recurring_customer_id'                     => $webHookNotification->subscription->transactions[0]->customer[id],
                         'recurring_subscription_id'                 => $webHookNotification->subscription->id,
                         'recurring_subscription_status'             => $webHookNotification->subscription->status,
                         'recurring_next_billing_amount'             => $webHookNotification->subscription->nextBillAmount,
                         'recurring_next_billing_date'               => $webHookNotification->subscription->nextBillingDate->format( 'Y-m-d' ),
                         'recurring_current_billing_cycle'           => $webHookNotification->subscription->currentBillingCycle,
                         'recurring_payment_method_token'            => $webHookNotification->subscription->paymentMethodToken,
                         'recurring_currency_code'                   => $webHookNotification->subscription->transactions[0]->currencyIsoCode,
                         'recurring_transaction_failure'             => 0,
         
                         'transaction_id'                            => $webHookNotification->subscription->transactions[0]->id,
                         'transaction_status'                        => $webHookNotification->subscription->transactions[0]->status,
         
                         'customer_billing_country_code_alpha_2'     => $webHookNotification->subscription->transactions[0]->billing[countryCodeAlpha2],
                         'customer_billing_country_code_alpha_3'     => $webHookNotification->subscription->transactions[0]->billing[countryCodeAlpha3],
                         'amount'                                    => $webHookNotification->subscription->transactions[0]->amount,
                         'credit_card_type'                          => '',
                     );*/
     }
 }
<?php

require 'credentials.php';
if (isset($_GET["bt_challenge"])) {
    die(Braintree_WebhookNotification::verify($_GET["bt_challenge"]));
}
*/
//when loading directly, make sure 200 status is given
global $isapage;
$isapage = true;
//in case the file is loaded directly
if (!defined("WP_USE_THEMES")) {
    define('WP_USE_THEMES', false);
    require_once dirname(__FILE__) . '/../../../../wp-load.php';
}
//globals
global $wpdb;
//load Braintree library, gateway class constructor does config
require_once dirname(__FILE__) . "/../classes/gateways/class.pmprogateway_braintree.php";
$gateway = new PMProGateway_braintree();
//verify
echo Braintree_WebhookNotification::verify($_REQUEST['bt_challenge']);
//only verifying?
if (empty($_REQUEST['bt_payload'])) {
    exit;
}
//get notification
$webhookNotification = Braintree_WebhookNotification::parse($_REQUEST['bt_signature'], $_REQUEST['bt_payload']);
//subscription charged sucessfully
if ($webhookNotification->kind == "subscription_charged_successfully") {
    //need a subscription id
    if (empty($webhookNotification->subscription->id)) {
        die("No subscription ID.");
    }
    //figure out which order to attach to
    $old_order = new MemberOrder();
    $old_order->getLastMemberOrderBySubscriptionTransactionID($webhookNotification->subscription->id);
 function testVerify()
 {
     $verificationString = Braintree_WebhookNotification::verify('verification_token');
     $this->assertEquals('integration_public_key|c9f15b74b0d98635cd182c51e2703cffa83388c3', $verificationString);
 }
Example #7
0
 public function verifyWebHookNotification()
 {
     if (isset($_GET["bt_challenge"])) {
         echo Braintree_WebhookNotification::verify($_GET["bt_challenge"]);
     } else {
         return false;
     }
 }
 /**
  * @expectedException Braintree_Exception_Configuration
  * @expectedExceptionMessage Braintree_Configuration::merchantId needs to be set (or accessToken needs to be passed to Braintree_Gateway).
  */
 function testVerifyRaisesErrorWhenEnvironmentNotSet()
 {
     Braintree_Configuration::reset();
     Braintree_WebhookNotification::verify('20f9f8ed05f77439fe955c977e4c8a53');
 }
 public function webHookVerify($bt_challenge)
 {
     echo Braintree_WebhookNotification::verify($bt_challenge);
 }