Bitcoin Coinbase API for PHP - Example
Bitcoin is an innovative payment network and a new kind of money. Bitcoin is the world's most widely used alternative currency with a total market cap of approximately $10 billion. The bitcoin network is made up of thousands of computers run by individuals all over the world.
Note: You need to set these all files url in your coinbase merchant account
Here i am going to present a small example to send money with Coinbase API. You can create a new payment button with Coinbase api. Let see step by step how it will work.
Step 1: Create a payment.php file
<?php require __DIR__ . '/vendor/autoload.php'; use Coinbase\Wallet\Client; use Coinbase\Wallet\Configuration; use Coinbase\Wallet\Value\Money; use Coinbase\Wallet\Resource\Checkout; use Coinbase\Wallet\Resource\Order; $apiKey = 'API KEY'; $apiSecret = 'API SECRET'; $configuration = Configuration::apiKey($apiKey, $apiSecret); $client = Client::create($configuration); $amount = 0.1; $orderId = "YOUR ORDER ID"; $params = array( 'name' => 'Site order ID: '.$orderId, 'amount' => new Money($amount, 'USD'), 'metadata' => array('order_id' => $orderId), 'auto_redirect' => true ); $checkout = new Checkout($params); $client->createCheckout($checkout); $code = $checkout->getEmbedCode(); $redirect_url = "https://www.coinbase.com/checkouts/$code"; ?>
Step 2: Create a notification.php file
<?php require __DIR__ . '/vendor/autoload.php'; use Coinbase\Wallet\Client; use Coinbase\Wallet\Configuration; use Coinbase\Wallet\Value\Money; use Coinbase\Wallet\Resource\Checkout; use Coinbase\Wallet\Resource\Order; $apiKey = 'API KEY'; $apiSecret = 'API SECRET'; $configuration = Configuration::apiKey($apiKey, $apiSecret); $client = Client::create($configuration); $raw_body = file_get_contents('php://input'); $signature = $_SERVER['HTTP_CB_SIGNATURE']; $authenticity = $client->verifyCallback($raw_body, $signature); // boolean if($authenticity){ $order = json_decode($raw_body, true); mail("YOUR EMAIL ID","Coinbase Patment Notifications",print_r($order, true)); } ?>
Step 3: Create a success.php file
<?php $order = $_GET['order']; var_dump($order); ?>
Note: You need to set these all files url in your coinbase merchant account
Please support us, Like us on Facebook.
Subscribe to:
Post Comments (Atom)
Where i found "vendor/autoload.php" ??
ReplyDeleteHello to all, how is everything, I think every one is getting more
ReplyDeletefrom this site, and your views are good in favor of new people.
Greetings! Very helpful advice in this particular post!
ReplyDeleteIt's the little changes that make the largest changes.
Many thanks for sharing!
I love foregathering utile information, this post has got me even more info!
ReplyDeletethanks for the tip, it worked for me, saved lots of money on the fees.
ReplyDelete