예제 #1
0
<?php

// # Get WebHook
// This sample code demonstrate how you can get a webhook, as documented here at:
// <a href="http://dev.blockcypher.com/#webhooks">Using webhooks</a>
//
// API used: GET /v1/btc/main/hooks/WebHook-Id
// ## Create Sample WebHook
// In samples we are using CreateWebHook.php sample to get the created instance of webhook.
// However, in real case scenario, we could use just the ID.
/** @var \BlockCypher\Api\WebHook $webHook */
$webHook = (require 'CreateWebHook.php');
$webHookId = $webHook->getId();
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContexts['BTC.main']);
// ## Get WebHook by Id
try {
    /// Get WebHook by Id
    $output = $webHookClient->get($webHookId);
} catch (Exception $ex) {
    ResultPrinter::printError("Get a WebHook", "WebHook", null, $webHookId, $ex);
    exit(1);
}
ResultPrinter::printResult("Get a WebHook", "WebHook", $output->getId(), null, $output);
return $output;
예제 #2
0
<?php

// # Get Multiple WebHooks
// This sample code demonstrate how you can get multiple webhooks at once, as documented here at:
// <a href="http://dev.blockcypher.com/#webhooks">Using webhooks</a>
//
// API used: GET /v1/btc/main/hooks/WebHook-Id;WebHook-Id
// ## Create Sample WebHook
// In samples we are using CreateWebHook.php sample to get the created instance of webhook.
// However, in real case scenario, we could use just the ID.
/** @var \BlockCypher\Api\WebHook $webHook */
$webHook = (require 'CreateWebHook.php');
$webHookId = $webHook->getId();
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContexts['BTC.main']);
// ## Get Multiple WebHooks
try {
    $webHookList = array($webHookId);
    $output = $webHookClient->getMultiple($webHookList);
} catch (Exception $ex) {
    ResultPrinter::printError("Get Multiple WebHooks", "WebHook[]", null, implode(';', $webHookList), $ex);
    exit(1);
}
ResultPrinter::printResult("Get Multiple WebHooks", "WebHook[]", implode(';', $webHookList), null, $output);
return $output;
예제 #3
0
<?php

// # Get All WebHooks Sample
//
// Use this call to list all the webhooks, as documented here at:
// http://dev.blockcypher.com/#webhooks
// API used: GET /v1/btc/main/hooks?token=<Your-Token>
require __DIR__ . '/../bootstrap.php';
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContexts['BTC.main']);
// ### Get List of All WebHooks
try {
    $output = $webHookClient->getAll();
} catch (Exception $ex) {
    ResultPrinter::printError("List all WebHooks", "Array of WebHook", null, null, $ex);
    exit(1);
}
ResultPrinter::printResult("List all WebHooks", "Array of WebHook", null, null, $output);
return $output;
예제 #4
0
<?php

// # Create WebHook
// This sample code demonstrate how you can create a webhook, as documented here at:
// <a href="http://dev.blockcypher.com/#using-webhooks">Using Webhooks</a>
//
// API used: POST /v1/btc/main/hooks
require __DIR__ . '/../bootstrap.php';
$webHook = new \BlockCypher\Api\WebHook();
$webHook->setUrl("http://requestb.in/rwp6jirw?uniqid=" . uniqid());
$webHook->setEvent('unconfirmed-tx');
$webHook->setHash('2b17f5589528f97436b5d563635b4b27ca8980aa20c300abdc538f2a8bfa871b');
/// For Sample Purposes Only.
$request = clone $webHook;
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContexts['BTC.main']);
/// Create WebHook
try {
    $output = $webHookClient->create($webHook);
} catch (Exception $ex) {
    ResultPrinter::printError("Created WebHook", "WebHook", null, $request, $ex);
    exit(1);
}
ResultPrinter::printResult("Created WebHook", "WebHook", $output->getId(), $request, $output);
return $output;
// # WebHook request
//     {
//         "url":"https://requestb.in/slmm49sl",
//         "event":"unconfirmed-tx",
//         "hash":"2b17f5589528f97436b5d...8980aa20c300abdc538f2a8bfa871b",
//     }
// Fill up the basic information that is required for the webhook
<?php

// # Delete All WebHooks Sample
// This is a sample helper method, to delete all existing webhooks.
// To properly use the sample, change the token from bootstrap.php file with your own app token.
// ## Get WebHook Instance
$webHookList = (require 'CreateAndListWebHooks.php');
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContexts['BTC.main']);
// ### Delete All WebHooks
try {
    $webHookIdList = array();
    /** @var \BlockCypher\Api\WebHook $webHook */
    foreach ($webHookList as $webHook) {
        $webHookIdList[] = $webHook->getId();
        $webHookClient->delete($webHook->getId());
    }
} catch (Exception $ex) {
    ResultPrinter::printError("Deleted All WebHooks", "", implode(';', $webHookIdList), null, $ex);
    exit(1);
}
ResultPrinter::printResult("Delete All WebHook", "", implode(';', $webHookIdList), null, null);
예제 #6
0
<?php

// Run on console:
// php -f .\sample\hook-api\DeleteWebHookEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('main', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContext);
$webHookClient->delete('d5ca3bd3-5dfb-477d-9fb4-ac3510af258d');
ResultPrinter::printResult("Delete WebHook Endpoint", "WebHook", 'd5ca3bd3-5dfb-477d-9fb4-ac3510af258d', null, $webHook);
예제 #7
0
<?php

// Run on console:
// php -f .\sample\hook-api\WebHookIdEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('main', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContext);
$webHook = $webHookClient->get('d5ca3bd3-5dfb-477d-9fb4-ac3510af258d');
ResultPrinter::printResult("WebHook ID Endpoint", "WebHook", $webHook->getId(), null, $webHook);
예제 #8
0
<?php

// Run on console:
// php -f .\sample\hook-api\ListWebHooksEndpoint.php
require __DIR__ . '/../bootstrap.php';
use BlockCypher\Auth\SimpleTokenCredential;
use BlockCypher\Rest\ApiContext;
$apiContext = ApiContext::create('main', 'btc', 'v1', new SimpleTokenCredential('c0afcccdde5081d6429de37d16166ead'), array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => 'BlockCypher.log', 'log.LogLevel' => 'DEBUG'));
$webHookClient = new \BlockCypher\Client\WebHookClient($apiContext);
$webHooks = $webHookClient->getAll();
ResultPrinter::printResult("List WebHooks Endpoint", "WebHook[]", null, null, $webHooks);