public function processSubscription()
 {
     if (!$this->request->is('post') || !isset($this->request->data['bt_signature']) || !isset($this->request->data['bt_payload'])) {
         $this->response->statusCode(404);
         return $this->response;
     }
     $webhookNotification = Braintree_WebhookNotification::parse($this->request->data['bt_signature'], $this->request->data['bt_payload']);
     if (!isset($webhookNotification->subscription)) {
         $this->response->statusCode(404);
         return $this->response;
     }
     CakeLog::write('debug', __d('billing', '%s Braintree webhook for subscription %s: %s', $webhookNotification->timestamp, $webhookNotification->subscription->id, $webhookNotification->kind));
     $braintreeSubscription = $webhookNotification->subscription;
     CakeLog::write('debug', json_encode($webhookNotification->subscription));
     $subscription = $this->BillingSubscription->findByRemoteSubscriptionId($braintreeSubscription->id);
     if (empty($subscription)) {
         $this->response->statusCode(404);
         return $this->response;
     }
     switch ($braintreeSubscription->status) {
         case 'Canceled':
             $result = $this->BillingSubscription->cancel($subscription['BillingSubscription']['id']);
             break;
         default:
             $result = true;
     }
     if ($result) {
         $this->response->statusCode(200);
     } else {
         $this->response->statusCode(500);
     }
     return $this->response;
 }
 public function actionSuccess()
 {
     if (isset($this->_data["bt_signature"]) && isset($this->_data["bt_payload"])) {
         $webhookNotification = \Braintree_WebhookNotification::parse($this->_data["bt_signature"], $this->_data["bt_payload"]);
         if (isset($webhookNotification->subscription->transactions[0]->customer['id'])) {
             $this->_updateUserStatus($webhookNotification->subscription->transactions[0]->customer['id'], User::STATUS_PAID);
         }
         $message = "[Webhook Received " . $webhookNotification->timestamp->format('Y-m-d H:i:s') . "] " . "Kind: " . $webhookNotification->kind . " | " . "Subscription: " . $webhookNotification->subscription->id . "\n";
         file_put_contents("webhook.log", $message, FILE_APPEND);
     }
 }
示例#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'                          => '',
                     );*/
     }
 }
    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);
    //no order?
    if (empty($old_order)) {
        die("Couldn't find the original subscription with ID=" . $webhookNotification->subscription->id . ".");
    }
    //create new order
    $user_id = $old_order->user_id;
<?php

require_once "PATH_TO_BRAINTREE/lib/Braintree.php";
Braintree_Configuration::environment("sandbox");
Braintree_Configuration::merchantId("your_merchant_id");
Braintree_Configuration::publicKey("your_public_key");
Braintree_Configuration::privateKey("your_private_key");
if (isset($_GET["bt_challenge"])) {
    echo Braintree_WebhookNotification::verify($_GET["bt_challenge"]);
}
if (isset($_POST["bt_signature"]) && isset($_POST["bt_payload"])) {
    $webhookNotification = Braintree_WebhookNotification::parse($_POST["bt_signature"], $_POST["bt_payload"]);
    $message = "[Webhook Received " . $webhookNotification->timestamp->format('Y-m-d H:i:s') . "] " . "Kind: " . $webhookNotification->kind . " | " . "Subscription: " . $webhookNotification->subscription->id . "\n";
    file_put_contents("/tmp/webhook.log", $message, FILE_APPEND);
}
 function testParsingInvalidSignatureRaisesError()
 {
     $sampleNotification = Braintree_WebhookTesting::sampleNotification(Braintree_WebhookNotification::SUBSCRIPTION_WENT_PAST_DUE, 'my_id');
     $this->setExpectedException('Braintree_Exception_InvalidSignature');
     $webhookNotification = Braintree_WebhookNotification::parse("bad_signature", $sampleNotification['payload']);
 }
 function testBuildsASampleNotificationForAPartnerMerchantDeclinedWebhook()
 {
     $sampleNotification = Braintree_WebhookTesting::sampleNotification(Braintree_WebhookNotification::PARTNER_MERCHANT_DECLINED, "my_id");
     $webhookNotification = Braintree_WebhookNotification::parse($sampleNotification['bt_signature'], $sampleNotification['bt_payload']);
     $this->assertEquals(Braintree_WebhookNotification::PARTNER_MERCHANT_DECLINED, $webhookNotification->kind);
     $this->assertEquals("abc123", $webhookNotification->partnerMerchant->partnerMerchantId);
 }
示例#8
0
 public function parseWebHookNotification()
 {
     if (isset($_POST["bt_signature"]) && isset($_POST["bt_payload"])) {
         $webhookNotification = Braintree_WebhookNotification::parse($_POST["bt_signature"], $_POST["bt_payload"]);
         return $webhookNotification;
         /*  
           $message =
         		"[Webhook Received " . $webhookNotification->timestamp->format('Y-m-d H:i:s') . "] "
         		. "Kind: " . $webhookNotification->kind . " | "
         		. "Subscription: " . $webhookNotification->subscription->id . "\n";
         
           file_put_contents("/tmp/webhook.log", $message, FILE_APPEND);
         */
     } else {
         return false;
     }
 }
 /**
  * Get notification for recurring billing
  * @param $bt_signature
  * @param $bt_payload
  * @return Braintree_WebhookNotification
  */
 public function webHookNotification($bt_signature, $bt_payload)
 {
     return Braintree_WebhookNotification::parse($bt_signature, $bt_payload);
 }