$def_language = "en"; // default Payment Box Language $public_key = "-your public key for coin box-"; // from gourl.io $private_key = "-your private key for coin box-"; // from gourl.io // IMPORTANT: Please read description of options here - https://gourl.io/cryptocoin_payment_api.html#options /********************************/ /** PAYMENT BOX **/ $options = array("public_key" => $public_key, "private_key" => $private_key, "webdev_key" => "", "orderID" => $orderID, "userID" => $userID, "userFormat" => $userFormat, "amount" => 0, "amountUSD" => $amountUSD, "period" => $period, "language" => $def_language); // Initialise Payment Class $box = new Cryptobox($options); // coin name $coinName = $box->coin_name(); // Optional - Language selection list for payment box (html code) $languages_list = display_language_box($def_language); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><head> <title><?php echo $coinName; ?> Pay-Per-View / Page Access Cryptocoin Payment Example</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv='cache-control' content='no-cache'> <meta http-equiv='Expires' content='-1'> <meta name='robots' content='all'> <script src='../cryptobox.min.js' type='text/javascript'></script> </head>
public function cryptopayments($pluginName, $amount, $amountCurrency = "USD", $orderID, $period, $default_language = "en", $default_coin = "bitcoin", $affiliate_key = "", $userID = "auto", $icon_width = 60) { // Security Test // --------------------- if (!$pluginName) { return array("error" => __("Error. Please place in variable \$YourPluginName - your plugin name", GOURL)); } if (preg_replace('/[^a-z0-9\\_\\-]/', '', $pluginName) != $pluginName || strlen($pluginName) < 5 || strlen($pluginName) > 17) { return array("error" => sprintf(__("Error. Invalid plugin name - %s. Size: 5-17 symbols. Allowed symbols: a..Z0..9_-", GOURL), $pluginName)); } if (stripos($pluginName, "product") === 0 || stripos($pluginName, "file") === 0 || stripos($pluginName, "pay") === 0 || stripos($pluginName, "membership") === 0 || stripos($pluginName, "user") === 0) { return array("error" => __("Error. Please change plugin name. Plugin name can not begin with: 'file..', 'product..', 'pay..', 'membership..', 'user..'", GOURL)); } if (stripos($pluginName, "gourl") !== false && $pluginName != "gourlwoocommerce" && $affiliate_key != "gourl") { return array("error" => __("Error. Please change plugin name. Plugin name can not use in name '..gourl..'", GOURL)); } $pluginName = strtolower(substr($pluginName, 0, 17)); $amountCurrency = trim(strtoupper($amountCurrency)); if ($amountCurrency == "USD" && (!is_numeric($amount) || $amount < 0.01 || $amount > 1000000)) { return array("error" => sprintf(__("Error. Invalid amount value - %s. Min value for USD: 0.01", GOURL), $amount)); } if ($amountCurrency != "USD" && (!is_numeric($amount) || $amount < 0.0001 || $amount > 50000000)) { return array("error" => sprintf(__("Error. Invalid amount value - %s. Min value: 0.0001", GOURL), $amount)); } if ($amountCurrency != "USD" && !isset($this->coin_names[$amountCurrency])) { return array("error" => sprintf(__("Error. Invalid amountCurrency - %s. Allowed: USD, %s", GOURL), $amountCurrency, implode(", ", array_keys($this->coin_names)))); } if (!$orderID || preg_replace('/[^A-Za-z0-9\\_\\-]/', '', $orderID) != $orderID || strlen($orderID) > 32) { return array("error" => sprintf(__("Error. Invalid Order ID - %s. Max size: 32 symbols. Allowed symbols: a..Z0..9_-", GOURL), $orderID)); } $period = trim(strtoupper(str_replace(" ", "", $period))); if (substr($period, -1) == "S") { $period = substr($period, 0, -1); } for ($i = 1; $i <= 90; $i++) { $arr[] = $i . "MINUTE"; $arr[] = $i . "HOUR"; $arr[] = $i . "DAY"; $arr[] = $i . "WEEK"; $arr[] = $i . "MONTH"; } if ($period != "NOEXPIRY" && !in_array($period, $arr)) { return array("error" => sprintf(__("Error. Invalid period value - %s. Allowed: NOEXPIRY, 1..90 HOUR, 1..90 DAY, 1..90 WEEK, 1..90 MONTH; example: 2 DAYS", GOURL), $period)); } $period = str_replace(array("MINUTE", "HOUR", "DAY", "WEEK", "MONTH"), array(" MINUTE", " HOUR", " DAY", " WEEK", " MONTH", GOURL), $period); if (!$default_language) { $default_language = "en"; } if (!in_array($default_language, array_keys($this->languages))) { return array("error" => sprintf(__("Error. Invalid language - %s. Allowed: %s"), GOURL), $default_language, implode(", ", array_keys($this->languages))); } if (!$default_coin) { $default_coin = "bitcoin"; } if (!in_array($default_coin, $this->coin_names)) { return array("error" => sprintf(__("Error. Invalid Coin - %s. Allowed: %s", GOURL), $default_coin, implode(",", $this->coin_names))); } if ($affiliate_key == "gourl") { $affiliate_key = ""; } if ($affiliate_key && (strpos($affiliate_key, "DEV") !== 0 || preg_replace('/[^A-Za-z0-9]/', '', $affiliate_key) != $affiliate_key)) { return array("error" => __("Error. Invalid affiliate_key, you can leave it empty", GOURL)); } if (!$userID || $userID == "auto") { $userID = get_current_user_id(); } if ($userID && $userID != "guest" && (!is_numeric($userID) || preg_replace('/[^0-9]/', '', $userID) != $userID)) { return array("error" => sprintf(__("Error. Invalid User ID - %s. Allowed numeric values or 'guest' value", GOURL), $userID)); } if (!$userID) { return array("error" => __("Error.", GOURL) . __("You need first to login or register on the website to make Bitcoin/Altcoin Payments", GOURL)); } if (!$this->payments) { return array("error" => __("Error. Please try a different payment method. GoUrl Bitcoin Plugin not configured - need setup payment box keys on GoUrl Bitcoin Gateway Options page", GOURL)); } $icon_width = str_replace("px", "", $icon_width); if (!is_numeric($icon_width) || $icon_width < 30 || $icon_width > 250) { $icon_width = 60; } if ($amountCurrency == "USD") { $amountUSD = $amount; $amountCoin = 0; $default_show = false; } else { $amountUSD = 0; $amountCoin = $amount; $default_coin = $this->coin_names[$amountCurrency]; $default_show = true; } // GoUrl Payments // -------------------------- $all_keys = array(); // Your payment boxes public / private keys from GoUrl.io $available_coins = array(); // List of coins that you accept for payments $cryptobox_private_keys = array(); // List Of your private keys $box_width = $this->options["box_width"]; $box_height = $this->options["box_height"]; $box_style = $this->payment_box_style(); $message_style = $this->payment_message_style(); foreach ($this->coin_names as $k => $v) { $public_key = $this->options[$v . 'public_key']; $private_key = $this->options[$v . 'private_key']; if ($public_key && !strpos($public_key, "PUB")) { return array("error" => sprintf(__('Invalid %s Public Key - %s', GOURL), $v, $public_key)); } if ($private_key && !strpos($private_key, "PRV")) { return array("error" => sprintf(__('Invalid %s Private Key', GOURL), $v)); } if ($private_key) { $cryptobox_private_keys[] = $private_key; } if ($private_key && $public_key && (!$default_show || $v == $default_coin)) { $all_keys[$v] = array("public_key" => $public_key, "private_key" => $private_key); $available_coins[] = $v; } } if (!defined("CRYPTOBOX_PRIVATE_KEYS")) { define("CRYPTOBOX_PRIVATE_KEYS", implode("^", $cryptobox_private_keys)); } if (!$available_coins) { return array("error" => sprintf(__("Error. Please enter Payment Private/Public Keys on GoUrl Options page for %s", GOURL), $default_coin)); } if (!in_array($default_coin, $available_coins)) { $vals = array_values($available_coins); $default_coin = array_shift($vals); } /// GoUrl Payment Class // -------------------------- include_once plugin_dir_path(__FILE__) . "includes/cryptobox.class.php"; // Current selected coin by user $coinName = cryptobox_selcoin($available_coins, $default_coin); // Current Coin public/private keys $public_key = $all_keys[$coinName]["public_key"]; $private_key = $all_keys[$coinName]["private_key"]; // PAYMENT BOX CONFIG $options = array("public_key" => $public_key, "private_key" => $private_key, "webdev_key" => $affiliate_key, "orderID" => $pluginName . "." . $orderID, "userID" => $userID == "guest" ? $pluginName . "." . $userID : "user" . $userID, "userFormat" => "MANUAL", "amount" => $amountCoin, "amountUSD" => $amountUSD, "period" => $period, "language" => $default_language); // Initialise Payment Class $box = new Cryptobox($options); // Coin name $coinName = $box->coin_name(); // Paid or not $is_paid = $box->is_paid(); // page anchor $anchor = "go" . $this->icrc32($pluginName . "." . $orderID); // Coins selection list (html code) $coins_list = count($available_coins) > 1 ? display_currency_box($available_coins, $default_coin, $default_language, $icon_width, "margin:10px 0 30px 0;text-align:center;font-weight:normal;", plugins_url('/images', __FILE__), $anchor) : ""; // Language selection list for payment box (html code) $languages_list = display_language_box($default_language, $anchor); // Payment Box $box_html = $box->display_cryptobox(true, $box_width, $box_height, $box_style, $message_style, $anchor); $html = ""; if (!$is_paid) { $html .= "<a id='" . $anchor . "' name='" . $anchor . "'></a>"; } if ($is_paid) { $html .= "<br>"; } else { $html .= $coins_list; } // Cryptocoin Payment Box if ($languages_list) { $html .= "<table cellspacing='0' cellpadding='0' border='0' width='100%' style='border:0;box-shadow:none;margin:0;padding:0;background-color:transparent'>"; $html .= "<tr style='background-color:transparent'><td style='border:0;margin:0;padding:0;background-color:transparent'><div style='margin:" . ($coins_list ? 25 : 50) . "px 0 5px " . ($this->options['box_width'] / 2 - 115) . "px;min-width:100%;text-align:center;font-size:13px;color:#666;font-weight:normal;white-space:nowrap;'>" . __('Language', GOURL) . ": " . $this->space(1) . $languages_list . "</div></td></tr>"; $html .= "<tr style='background-color:transparent'><td style='border:0;margin:0;padding:0;background-color:transparent'>" . $box_html . "</td></tr>"; $html .= "</table>"; } else { $html .= $box_html; } // Result $obj = $is_paid ? $box->payment_info() : ""; $arr = array("status" => $is_paid ? "payment_received" : "payment_not_received", "error" => "", "is_paid" => $is_paid, "paymentID" => $is_paid ? $obj->paymentID : 0, "paymentDate" => $is_paid ? $obj->txDate : "", "paymentLink" => $is_paid ? GOURL_ADMIN . GOURL . "payments&s=payment_" . $obj->paymentID : "", "addr" => $is_paid ? $obj->addr : "", "tx" => $is_paid ? $obj->txID : "", "is_confirmed" => $is_paid ? $obj->txConfirmed : "", "amount" => $is_paid ? $obj->amount : "", "amountusd" => $amountUSD, "coinlabel" => $is_paid ? $obj->coinLabel : "", "coinname" => $is_paid ? strtolower($coinName) : "", "boxID" => $is_paid ? $obj->boxID : 0, "boxtype" => $is_paid ? $obj->boxType : "", "boxLink" => $is_paid ? "https://gourl.io/view/coin_boxes/" . $obj->boxID . "/statistics.html" : "", "orderID" => $orderID, "userID" => $userID, "usercountry" => $is_paid ? $obj->countryID : "", "userLink" => $userID == "guest" ? "" : admin_url("user-edit.php?user_id=" . $userID), "is_processed" => $is_paid ? $obj->processed : "", "processedDate" => $is_paid && $obj->processed ? $obj->processedDate : "", "callback_function" => $orderID . "_gourlcallback", "available_payments" => $this->payments, "html_payment_box" => $html); if ($is_paid && !$obj->processed) { $box->set_status_processed(); } return $arr; }