function after_process() { global $insert_id, $db, $order; $info = $order->info; $name = "Order #" . $insert_id; $custom = $insert_id; $currencyCode = $info['currency']; $total = $info['total']; $callback = zen_href_link('coinbasepp_callback.php', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true, $static = true); $params = array('description' => $name, 'callback_url' => $callback . "?type=" . MODULE_PAYMENT_COINBASE_CALLBACK_SECRET, 'success_url' => $callback . "?type=success", 'cancel_url' => $callback . "?type=cancel", 'info_url' => zen_href_link('index')); require_once dirname(__FILE__) . "/coinbase/Coinbase.php"; $oauth = new Coinbase_Oauth(MODULE_PAYMENT_COINBASE_OAUTH_CLIENTID, MODULE_PAYMENT_COINBASE_OAUTH_CLIENTSECRET, null); $tokens = unserialize(MODULE_PAYMENT_COINBASE_OAUTH); $coinbase = new Coinbase($oauth, $tokens); try { $code = $coinbase->createButton($name, $total, $currencyCode, $custom, $params)->button->code; } catch (Coinbase_TokensExpiredException $e) { try { $tokens = $oauth->refreshTokens($tokens); } catch (Exception $f) { $this->tokenFail($f->getMessage()); } $coinbase = new Coinbase($oauth, $tokens); $db->Execute("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $db->prepare_input(serialize($tokens)) . "' where configuration_key = 'MODULE_PAYMENT_COINBASE_OAUTH'"); $code = $coinbase->createButton($name, $total, $currencyCode, $custom, $params)->button->code; } $_SESSION['cart']->reset(true); $_SESSION['coinbasepp_order_id'] = $insert_id; zen_redirect("https://coinbase.com/checkouts/{$code}"); return false; }
if ($type == "success") { // Customer's browser - checkout was successful unset($_SESSION['coinbasepp_order_id']); zen_redirect(zen_href_link('checkout_success')); } if ($type == "cancel") { // Customer's browser - they clicked Cancel during checkout unset($_SESSION['coinbasepp_order_id']); zen_redirect(zen_href_link('index')); } else { if ($type == "oauth") { // Admin connecting OAuth account $hostPart = "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s://" : "://") . $_SERVER['HTTP_HOST']; $pathParts = explode("?", $_SERVER['REQUEST_URI']); $url = $hostPart . $pathParts[0] . "?type=oauth&after=" . urlencode($_GET['after']); $oauth = new Coinbase_Oauth(MODULE_PAYMENT_COINBASE_OAUTH_CLIENTID, MODULE_PAYMENT_COINBASE_OAUTH_CLIENTSECRET, $url); try { $tokens = $oauth->getTokens($_GET['code']); } catch (Exception $e) { echo 'Could not authenticate. Please try again. ' . $e->getMessage(); return; } global $db; $db->Execute("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $db->prepare_input(serialize($tokens)) . "' where configuration_key = 'MODULE_PAYMENT_COINBASE_OAUTH'"); zen_redirect($hostPart . $_GET['after']); } else { if ($type == MODULE_PAYMENT_COINBASE_CALLBACK_SECRET) { // From Coinbase - callback $postBody = json_decode(file_get_contents('php://input')); $coinbase = new Coinbase(new Coinbase_Oauth(MODULE_PAYMENT_COINBASE_OAUTH_CLIENTID, MODULE_PAYMENT_COINBASE_OAUTH_CLIENTSECRET, null), unserialize(MODULE_PAYMENT_COINBASE_OAUTH)); $orderId = $postBody->order->id;