コード例 #1
0
ファイル: coinbase.php プロジェクト: juliosd/legacy-master
function pricerrtheme_coinbase_temp_redir()
{
    if (!empty($_GET['my_custom_button_callback_coinbase'])) {
        $data = json_decode(file_get_contents('php://input'), TRUE);
        $arr = print_r($data, true);
        $code_id = $data['order']['custom'];
        $cents = $data['order']['total_native']['cents'] / 100;
        //$code_id2 = $arr['order']['custom'];
        //	mail("*****@*****.**", "asd1", $code_id);
        //	mail("*****@*****.**", "asd2", $code_id2);
        $cst = get_option('coinbase_thing_' . $code_id);
        //***********************************************************************
        $cust = $cst;
        $cust = explode("|", $cust);
        $pid = $cust[0];
        $uid = $cust[1];
        $datemade = $cust[2];
        $xtra1 = $cust[3];
        $xtra2 = $cust[4];
        $xtra3 = $cust[5];
        $xtra4 = $cust[6];
        $xtra5 = $cust[7];
        $xtra6 = $cust[8];
        $xtra7 = $cust[9];
        $xtra8 = $cust[10];
        $xtra9 = $cust[11];
        $xtra10 = $cust[12];
        //---------------------------------------------------
        $my_arr = array();
        $my_arr['extra1'] = 0;
        $my_arr['extra2'] = 0;
        $my_arr['extra3'] = 0;
        $my_arr['extra4'] = 0;
        $my_arr['extra5'] = 0;
        $my_arr['extra6'] = 0;
        $my_arr['extra7'] = 0;
        $my_arr['extra8'] = 0;
        $my_arr['extra9'] = 0;
        $my_arr['extra10'] = 0;
        if (!empty($xtra1)) {
            $my_arr['extra' . $xtra1] = 1;
        }
        if (!empty($xtra2)) {
            $my_arr['extra' . $xtra2] = 1;
        }
        if (!empty($xtra3)) {
            $my_arr['extra' . $xtra3] = 1;
        }
        if (!empty($xtra4)) {
            $my_arr['extra' . $xtra4] = 1;
        }
        if (!empty($xtra5)) {
            $my_arr['extra' . $xtra5] = 1;
        }
        if (!empty($xtra6)) {
            $my_arr['extra' . $xtra6] = 1;
        }
        if (!empty($xtra7)) {
            $my_arr['extra' . $xtra7] = 1;
        }
        if (!empty($xtra8)) {
            $my_arr['extra' . $xtra8] = 1;
        }
        if (!empty($xtra9)) {
            $my_arr['extra' . $xtra9] = 1;
        }
        if (!empty($xtra10)) {
            $my_arr['extra' . $xtra10] = 1;
        }
        $xtra1 = $my_arr['extra1'];
        $xtra2 = $my_arr['extra2'];
        $xtra3 = $my_arr['extra3'];
        $xtra4 = $my_arr['extra4'];
        $xtra5 = $my_arr['extra5'];
        $xtra6 = $my_arr['extra6'];
        $xtra7 = $my_arr['extra7'];
        $xtra8 = $my_arr['extra8'];
        $xtra9 = $my_arr['extra9'];
        $xtra10 = $my_arr['extra10'];
        //---------------------------------------------------
        $payment_status = $_POST['payment_status'];
        if (1) {
            //$payment_status == "Completed"):
            $price = get_post_meta($pid, 'price', true);
            if (empty($price)) {
                $price = get_option('pricerrTheme_price');
            }
            $mc_gross = $cents;
            //$_POST['mc_gross'] - $_POST['mc_fee'];
            //-----------------------------------------------------
            global $wpdb;
            $pref = $wpdb->prefix;
            $s1 = "select * from " . $pref . "job_orders where pid='{$pid}' AND uid='{$uid}' AND date_made='{$datemade}'";
            $r1 = $wpdb->get_results($s1);
            if (count($r1) == 0) {
                $nts = addslashes($nts);
                $s1 = "insert into " . $pref . "job_orders (pid,uid,date_made, mc_gross, notes_to_seller, extra1, extra2, extra3, extra4, extra5, extra6, extra7, extra8, extra9, extra10) \r\n\t\t\tvalues('{$pid}','{$uid}','{$datemade}','{$mc_gross}', '{$nts}','{$xtra1}','{$xtra2}','{$xtra3}','{$xtra4}','{$xtra5}','{$xtra6}','{$xtra7}','{$xtra8}','{$xtra9}','{$xtra10}')";
                $wpdb->query($s1);
                //--------------
                $s1 = "select * from " . $pref . "job_orders where pid='{$pid}' AND uid='{$uid}' AND date_made='{$datemade}'";
                $r1 = $wpdb->get_results($s1);
                $orderid = $r1[0]->id;
                //------------------------
                $g1 = "insert into " . $pref . "job_chatbox (datemade, uid, oid, content) values('{$datemade}','0','{$orderid}','{$ccc}')";
                $wpdb->query($g1);
                //--------------
                $s1 = "insert into " . $pref . "job_ratings (orderid) values('{$orderid}')";
                $wpdb->query($s1);
                $sales = get_post_meta($pid, 'sales', true);
                if (empty($sales)) {
                    $sales = 1;
                } else {
                    $sales = $sales + 1;
                }
                update_post_meta($pid, 'sales', $sales);
                //---------------
                // email to the owner of the job
                $post = get_post($pid);
                PricerrTheme_send_email_when_job_purchased_4_buyer($orderid, $pid, $uid, $post->post_author);
                PricerrTheme_send_email_when_job_purchased_4_seller($orderid, $pid, $post->post_author, $uid);
                //---------------
                $instant = get_post_meta($pid, 'instant', true);
                if ($instant == "1") {
                    $tm = current_time('timestamp', 0);
                    $s = "update " . $wpdb->prefix . "job_orders set done_seller='1', date_finished='{$tm}' where id='{$orderid}' ";
                    $wpdb->query($s);
                    $ccc = __('Delivered', 'PricerrTheme');
                    $g1 = "insert into " . $wpdb->prefix . "job_chatbox (datemade, uid, oid, content) values('{$tm}','-1','{$orderid}','{$ccc}')";
                    $wpdb->query($g1);
                    PricerrTheme_send_email_when_job_delivered($orderid, $pid, $uid);
                }
                //---------------
                $admin_email = get_bloginfo('admin_email');
                $message = sprintf(__('A new job has been purchased on your site: <a href="%s">%s</a>', 'PricerrTheme'), get_permalink($pid), $post->post_title);
                PricerrTheme_send_email($admin_email, sprintf(__('New Job Purchased on your site - %s', 'PricerrTheme'), $post->post_title), $message);
            }
        }
        //**********************************************************************
        //mail("*****@*****.**", "asd", $arr);
        die;
    }
    if (!empty($_GET['coinbase_code'])) {
        $code = $_GET['coinbase_code'];
        $_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);
        //----------------------
        $tokens = $coinbaseOauth->getTokens($code);
        update_option('coinbase_tokens', $tokens);
        wp_redirect(get_bloginfo('siteurl') . "/wp-admin");
        die;
    }
}
コード例 #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>";
}