The simplest way to receive Bitcoin payments. Blockchain forwards all incoming Bitcoin to the address you specify.
Be sure to check out the official documentation for information on callback URLs.
Call ReceiveV2->generate
on a Blockchain
object. Pass a v2 API key, xpub and callback URL. Returns a ReceiveResponse
object.
$blockchain = new \Blockchain\Blockchain($apiKey);
$v2ApiKey = 'myApiKey';
$xpub = 'xpubYourXPub';
$callbackUrl = 'http://example.com/transaction?secret=mySecret';
$gap_limit = 5 // optional - how many unused addresses are allowed before erroring out
$response = $blockchain->ReceiveV2->generate($v2ApiKey, $xPub, $callbackUrl, $gap_limit);
// Show receive address to user:
echo "Send coins to " . $response->getReceiveAddress();
To view the callback logs call ReceiveV2->callbackLogs
on a Blockchain
object. Pass an API key and callback URL. Returns an array of CallbackLogEntry
objects.
$blockchain = new \Blockchain\Blockchain($apiKey);
$v2ApiKey = 'myApiKey';
$callbackUrl = 'http://example.com/transaction?secret=mySecret';
$logs = $blockchain->ReceiveV2->callbackLogs($apiKey, $callbackUrl);
foreach ($logs as $log) {
$log->getCallback();
$log->getCalledAt(); // DateTime instance
$log->getResponseCode();
$log->getResponse();
}
To check the index gap between the last address paid to and the last address generated call ReceiveV2->checkAddressGap
on a Blockchain
object. Returns an int
.
$gap_int = $blockchain->ReceiveV2->checkAddressGap($apiKey, $xpub);
class ReceiveResponse {
private $address; // string
private $index; // int
private $callback; // string
public function getReceiveAddress();
public function getIndex();
public function getCallback();
}
class CallbackLogEntry {
private $callback; // string
private $calledAt; // DateTime
private $rawResponse; // string
private $responseCode; // int
public function getCallback();
public function getCalledAt();
public function getResponse();
public function getResponseCode();
}