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 } }
function testCreateButtonWithOptions() { $requestor = new MockCoinbase_Requestor(); $requestor->returns('doCurlRequest', array("statusCode" => 200, "body" => ' { "success": true, "button": { "code": "93865b9cae83706ae59220c013bc0afd", "type": "buy_now", "style": "custom_large", "text": "Pay With Bitcoin", "name": "test", "description": "Sample description", "custom": "Order123", "price": { "cents": 123, "currency_iso": "USD" } } }')); $coinbase = new Coinbase(""); $coinbase->setRequestor($requestor); $response = $coinbase->createButtonWithOptions("test", "1.23", "USD", "Order123", array("name" => "test", "price_string" => "1.23", "price_currency_iso" => "USD", "custom" => "Order123", "style" => "custom_large", "description" => "Sample description")); $this->assertEqual($response->button->code, '93865b9cae83706ae59220c013bc0afd'); $this->assertEqual($response->embedHtml, "<div class=\"coinbase-button\" data-code=\"93865b9cae83706ae59220c013bc0afd\"></div><script src=\"https://coinbase.com/assets/button.js\" type=\"text/javascript\"></script>"); }