Example #1
0
function PricerrTheme_add_new_coinbase_cnt()
{
    $arr = array("yes" => __("Yes", 'PricerrTheme'), "no" => __("No", 'PricerrTheme'));
    $clientId = get_option('PricerrTheme_coinbase_id');
    ?>

<div id="tabs_coinbase"  >	
          
          <form method="post" action="<?php 
    bloginfo('siteurl');
    ?>
/wp-admin/admin.php?page=payment-methods&active_tab=tabs_coinbase">
          
          
            <?php 
    if (!empty($clientId)) {
        $_CLIENT_ID = get_option('PricerrTheme_coinbase_id');
        $_CLIENT_SECRET = get_option('PricerrTheme_client_secret_key');
        include dirname(__FILE__) . '/coinbase_php/lib/coinbase.php';
        //-------------------------------------------------------------------------------------
        $redirectUrl = str_replace("http://", "https://", plugins_url('PricerrTheme_gateways/coinbase/coinbase_redirect.php'));
        //get_bloginfo('siteurl') . "/?bitcoins=1";
        echo 'Callback URL: ';
        echo $redirectUrl;
        echo '<br/> ';
        $coinbaseOauth = new Coinbase_OAuth($_CLIENT_ID, $_CLIENT_SECRET, $redirectUrl);
        ?>
      
      <?php 
        $authorizeUrl = $coinbaseOauth->createAuthorizeUrl("buttons");
        ?>
      <p>Please authorize this website with coinbase: <a href="<?php 
        echo $authorizeUrl;
        ?>
" class="button"><?php 
        _e('Authorize Wordpress Plugin');
        ?>
</a></p>
                        <?php 
    }
    ?>
          
          
          First, create an OAuth2 application for this plugin at <a href="https://coinbase.com/oauth/applications">https://coinbase.com/oauth/applications</a>
          <br/><br/>
            <table width="100%" class="sitemile-table">
    				
                    <tr>
                    <td valign=top width="22"><?php 
    PricerrTheme_theme_bullet();
    ?>
</td>
                    <td width="200"><?php 
    _e('Enable:', 'PricerrTheme');
    ?>
</td>
                    <td><?php 
    echo PricerrTheme_get_option_drop_down($arr, 'PricerrTheme_coinbase_enable');
    ?>
</td>
                    </tr>

                    
                    <tr>
                    <td valign=top width="22"><?php 
    PricerrTheme_theme_bullet();
    ?>
</td>
                    <td ><?php 
    _e('Client ID:', 'PricerrTheme');
    ?>
</td>
                    <td><input type="text" size="45" name="PricerrTheme_coinbase_id" value="<?php 
    echo get_option('PricerrTheme_coinbase_id');
    ?>
"/> find this on: https://coinbase.com/oauth/applications</td>
                    </tr>
                    
                    <tr>
                    <td valign=top width="22"><?php 
    PricerrTheme_theme_bullet();
    ?>
</td>
                    <td ><?php 
    _e('Client Secret:', 'PricerrTheme');
    ?>
</td>
                    <td><input type="text" size="45" name="PricerrTheme_client_secret_key" value="<?php 
    echo get_option('PricerrTheme_client_secret_key');
    ?>
"/> find this on: https://coinbase.com/oauth/applications</td>
                    </tr>
                    
                    
                   
        
                    <tr>
                    <td ></td>
                    <td ></td>
                    <td><input type="submit" name="PricerrTheme_save_coinbase" value="<?php 
    _e('Save Options', 'PricerrTheme');
    ?>
"/></td>
                    </tr>
            
            </table>      
          	</form>
          
          </div>

<?php 
}
Example #2
0
<?php

require_once dirname(__FILE__) . '/../lib/Coinbase.php';
// Create an application at https://coinbase.com/oauth/applications and set these values accordingly
$_CLIENT_ID = "83a481f96bf28ea4bed1ee8bdc49ba4265609efa40d40477c2a57e913c479065";
$_CLIENT_SECRET = "a8dda20b94d09e84e8fefa5e7560133d9c5af9da93ec1d3e79ad0843d2920bbb";
// Note: your redirect URL should use HTTPS.
$_REDIRECT_URL = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$coinbaseOauth = new Coinbase_OAuth($_CLIENT_ID, $_CLIENT_SECRET, $_REDIRECT_URL);
if (isset($_GET['code'])) {
    // Request tokens
    $tokens = $coinbaseOauth->getTokens($_GET['code']);
    // The user is now authenticated! Access and refresh tokens are in $tokens
    // Store these tokens safely, and use them to make Coinbase API requests in the future.
    // For example:
    $coinbase = new Coinbase($coinbaseOauth, $tokens);
    try {
        echo 'Balance: ' . $coinbase->getBalance() . '<br>';
        echo $coinbase->createButton("Alpaca socks", "10.00", "CAD")->embedHtml;
    } catch (Coinbase_TokensExpiredException $e) {
        $newTokens = $coinbaseOauth->refreshTokens($tokens);
        // Store $newTokens and retry request
    }
} else {
    // Redirect to Coinbase authorization page
    // The provided parameters specify the access your application will have to the
    // user's account; for a full list, see https://coinbase.com/docs/api/overview
    // You can pass as many scopes as you would like
    echo "<a href=\"" . $coinbaseOauth->createAuthorizeUrl("balance", "buttons") . "\">Connect with Coinbase</a>";
}