function PricerrTheme_gateways_get_purchase_this_lnk_coinbase($pid, $extrs) { $price = get_post_meta($pid, 'price', true); if (empty($price)) { $price = get_option('PricerrTheme_job_fixed_amount'); } $post_au = get_post($pid); $job_title = $post_au->post_title; //--------------------------------------------------- $extr_ttl = 0; $xtra_stuff = ''; $extras = $extrs; $extras = explode("|", $extras); if (count($extras)) { foreach ($extras as $myitem) { if (!empty($myitem)) { $extra_price = get_post_meta($pid, 'extra' . $myitem . '_price', true); $extr_ttl += $extra_price; $xtra_stuff .= '|' . $myitem; } } } $shipping = get_post_meta($pid, 'shipping', true); if (empty($shipping)) { $shipping = 0; } $total = $shipping + $extr_ttl + $price; //---------------------------------------- global $current_user; get_currentuserinfo(); $uid = $current_user->ID; $tm = time(); $cst = $pid . '|' . $uid . '|' . $tm . $xtra_stuff; $custom_id = time() . $pid . $uid; update_option('coinbase_thing_' . $custom_id, $cst); $opt = get_option('PricerrTheme_coinbase_enable'); if ($opt == "yes") { $_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"; $coinbaseOauth = new Coinbase_OAuth($_CLIENT_ID, $_CLIENT_SECRET, $redirectUrl); $args = array('name' => $job_title, 'price_string' => $total, 'price_currency_iso' => get_option('PricerrTheme_currency'), "callback_url" => get_bloginfo('siteurl') . "?my_custom_button_callback_coinbase=1", 'custom' => $custom_id, 'description' => $job_title, 'type' => 'buy_now', 'style' => 'buy_now_large'); $tokens = get_option('coinbase_tokens'); if ($tokens) { try { $coinbase = new Coinbase($coinbaseOauth, $tokens); $button = $coinbase->createButtonWithOptions($args)->embedHtml; } catch (Coinbase_TokensExpiredException $e) { $tokens = $coinbaseOauth->refreshTokens($tokens); update_option('coinbase_tokens', $tokens); $coinbase = new Coinbase($coinbaseOauth, $tokens); $button = $coinbase->createButtonWithOptions($args)->embedHtml; } echo $button; //return $button; } else { //return "The Coinbase plugin has not been properly set up - please visit the Coinbase settings page in your administrator console."; echo 'Please set coinbase up right. From backend.'; } ?> <!-- <a href="<?php bloginfo('siteurl'); ?> /?pay_by_payfast=1&jobid=<?php echo $pid; ?> &extras=<?php echo $extrs; ?> " class="post_bid_btn"><?php _e('Pay by Payfast', 'pr_gateways'); ?> </a> --> <?php } }
<?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>"; }