} echo '</ul>' . "\n"; } //example search criteria array $criteria = array('merchant_id' => MERCHANT_ID, 'start_time' => '2014-03-14T00:00:00.000Z', 'per_page' => 10); echo '<hr/>' . "\n"; echo '<h3 style="color:blue">Recent Invoices</h3>'; //search invoices with criteria $invoices = GoCoin::searchInvoices($token, $criteria); if (!empty($invoices) && property_exists($invoices, 'invoices')) { foreach ($invoices->invoices as $invoice) { showObject($invoice); echo '<hr/>' . "\n"; } } echo '<h3 style="color:blue">Specific Invoices</h3>'; //get a specific invoice $specific = GoCoin::getInvoice($token, INVOICE_ID); showObject($invoice); $NEW_INVOICE = FALSE; if ($NEW_INVOICE) { echo '<hr/>' . "\n"; echo '<h3 style="color:blue">New Invoice</h3>'; //create a new invoice $new_invoice = array('price_currency' => 'BTC', 'base_price' => '456.00', 'base_price_currency' => 'USD', 'notification_level' => 'all', 'confirmations_required' => 5); $new_invoice = GoCoin::createInvoice($token, MERCHANT_ID, $new_invoice); //var_dump($new_invoice); showObject($new_invoice); } //close our HTML block echo '</body></html>' . "\n";
function after_process() { include_once DIR_WS_INCLUDES . 'gocoinlib/src/GoCoin.php'; global $messageStack; global $insert_id, $db, $order, $sendto, $currency; if (version_compare(PHP_VERSION, '5.3.0') >= 0) { $php_version_allowed = true; } else { $php_version_allowed = false; } $customer_id = $_SESSION['customer_id']; $customer = $order->billing['firstname'] . ' ' . $order->billing['lastname']; $callback_url = $this->baseUrl . "ext/modules/payment/gocoinpay/callback_url.php"; $return_url = $this->baseUrl . "checkout_success.php"; $merchant_id = MODULE_PAYMENT_GOCOIN_MERCHANT_ID; $access_token = MODULE_PAYMENT_GOCOIN_ACCESS_KEY; $stage = "GoCoin Payment In CheckOut :"; if (empty($access_token)) { $msg = 'Improper Gateway set up. API Key not found.'; $this->osLog($stage, $msg); $json['error'] = $msg; } elseif (empty($merchant_id)) { $msg = 'Improper Gateway set up. Merchant ID not found.'; $json['error'] = $msg; $this->osLog($stage, $msg); } elseif ($php_version_allowed == false) { $msg = 'The minimum PHP version required for GoCoin plugin is 5.3.0.'; $json['error'] = $msg; $this->osLog($stage, $msg); } else { $options = array("type" => 'bill', 'price_currency' => $coin_currency, 'base_price' => $order->info['total'], 'base_price_currency' => $order->info['currency'], 'callback_url' => $callback_url, 'redirect_url' => $return_url, 'order_id' => $insert_id, 'customer_name' => $customer, 'customer_address_1' => $order->billing['street_address'], 'customer_address_2' => '', 'customer_city' => $order->delivery['city'], 'customer_region' => $order->delivery['state'], 'customer_postal_code' => $order->customer['postcode'], 'customer_country' => $order->billing['country']['title'], 'customer_phone' => $order->customer['telephone'], 'customer_email' => $order->customer['email_address']); $signature = $this->sign($options, $access_token); $options['user_defined_8'] = $signature; try { $invoice = GoCoin::createInvoice($access_token, $merchant_id, $options); $url = $invoice->gateway_url; $json['success'] = $url; } catch (Exception $e) { $msg = $e->getMessage(); $json['error'] = $msg; $this->osLog($stage, $msg); } } if (isset($json['error']) && $json['error'] != '') { $messageStack->add_session('checkout_payment', $json['error'] . '<!-- [' . $this->code . '] -->', 'error'); tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error=' . $this->code . '&error=' . base64_encode($json['error']), 'SSL')); } elseif (isset($json['success']) && $json['success'] != '') { $_SESSION['cart']->reset(true); tep_redirect($url); } return false; }
/** * Process payment for woocommerce checkout * * @param mixed $order_id */ function process_payment($order_id) { global $woocommerce, $wpdb; $access_token = $this->settings['accessToken']; $merchant_id = $this->settings['merchantId']; $logger = new WC_Logger(); // Check to make sure we have an access token (API Key) if (empty($access_token)) { $msg = 'Improper Gateway set up. Access token not found.'; $logger->add('gocoin', $msg); $woocommerce->add_error(__($msg)); } elseif (empty($merchant_id)) { $msg = 'Improper Gateway set up. Merchant ID not found.'; $logger->add('gocoin', $msg); $woocommerce->add_error(__($msg)); } else { // Build the WooCommerce order, is has status "Pending" $order = new WC_Order($order_id); // Handle breaking route changes for after-purchase pages if (version_compare(WOOCOMMERCE_VERSION, '2.1.0', '>=')) { $redirect_url = $this->get_return_url($this->order); } else { $redirect_url = add_query_arg('key', $order->order_key, add_query_arg('order', $order_id, get_permalink(get_option('woocommerce_thanks_page_id')))); } $callback_url = plugin_dir_url(__FILE__) . 'gocoin-callback.php'; $currency = get_woocommerce_currency(); $options = array("type" => 'bill', "base_price" => $order->order_total, "base_price_currency" => $currency, "callback_url" => $callback_url, "redirect_url" => $redirect_url, "order_id" => $order_id, "customer_name" => $order->shipping_first_name . ' ' . $order->shipping_last_name, "customer_address_1" => $order->shipping_address_1, "customer_address_2" => $order->shipping_address_2, "customer_city" => $order->shipping_city, "customer_region" => $order->shipping_state, "customer_postal_code" => $order->shipping_postcode, "customer_country" => $order->shipping_country, "customer_phone" => $order->shipping_phone, "customer_email" => $order->shipping_email); // Sign invoice with access token, if this fails we should still allow user to check out. if ($signature = Util::sign($options, $access_token)) { $options['user_defined_8'] = $signature; } try { $invoice = GoCoin::createInvoice($access_token, $merchant_id, $options); $url = $invoice->gateway_url; $woocommerce->cart->empty_cart(); return array('result' => 'success', 'redirect' => $url); } catch (Exception $e) { $msg = $e->getMessage(); $order->add_order_note(var_export($msg)); $logger->add('gocoin', $msg); $woocommerce->add_error(__($msg)); } } }