public function GetIframeUrl() { // are they using bitpay? if (!($quote = Mage::getSingleton('checkout/session')->getQuote()) or !($payment = $quote->getPayment()) or !($instance = $payment->getMethodInstance()) or $instance->getCode() != 'Bitcoins') { return 'notbitpay'; } // fullscreen disabled? if (Mage::getStoreConfig('payment/Bitcoins/fullscreen')) { return 'disabled'; } include Mage::getBaseDir('lib') . '/bitpay/bp_lib.php'; $apiKey = Mage::getStoreConfig('payment/Bitcoins/api_key'); $speed = Mage::getStoreConfig('payment/Bitcoins/speed'); $quote = $this->getQuote(); $quoteId = $quote->getId(); if (Mage::getModel('Bitcoins/ipn')->GetQuotePaid($quoteId)) { return 'paid'; } // quote's already paid, so don't show the iframe $options = array('currency' => $quote->getQuoteCurrencyCode(), 'fullNotifications' => 'true', 'notificationURL' => Mage::getUrl('bitpay_callback'), 'redirectURL' => Mage::getUrl('customer/account'), 'transactionSpeed' => $speed, 'apiKey' => $apiKey); // customer data $method = Mage::getModel('Bitcoins/paymentMethod'); $options += $method->ExtractAddress($quote->getShippingAddress()); // Mage doesn't round the total until saving and it can have more precision at this point which would be bad for later comparing records w/ bitpay. So round here to match what the price will be saved as: $price = round($quote->getGrandTotal(), 4); //serialize info about the quote to detect changes $hash = $method->getQuoteHash($quoteId); Mage::log('invoicing for ' . $price . ' ' . $quote->getQuoteCurrencyCode(), NULL, 'bitpay.log'); $invoice = bpCreateInvoice($quoteId, $price, array('quoteId' => $quoteId, 'quoteHash' => $hash), $options); Mage::log($invoice, NULL, 'bitpay.log'); if (array_key_exists('error', $invoice)) { Mage::log('Error creating bitpay invoice', null, 'bitpay.log'); Mage::log($invoice['error'], null, 'bitpay.log'); Mage::throwException("Error creating bit-pay invoice. Please try again or use another payment option."); return false; } return $invoice['url'] . '&view=iframe'; }
function after_process() { global $insert_id, $order, $db; require_once 'bitpay/bp_lib.php'; // change order status to value selected by merchant $db->Execute("update " . TABLE_ORDERS . " set orders_status = " . intval(MODULE_PAYMENT_BITPAY_UNPAID_STATUS_ID) . " where orders_id = " . intval($insert_id)); $options = array('physical' => $order->content_type == 'physical' ? 'true' : 'false', 'currency' => $order->info['currency'], 'buyerName' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 'fullNotifications' => 'true', 'notificationURL' => zen_href_link('bitpay_callback.php', $parameters = '', $connection = 'NONSSL', $add_session_id = true, $search_engine_safe = true, $static = true), 'redirectURL' => zen_href_link('account'), 'transactionSpeed' => MODULE_PAYMENT_BITPAY_TRANSACTION_SPEED, 'apiKey' => MODULE_PAYMENT_BITPAY_APIKEY); $invoice = bpCreateInvoice($insert_id, $order->info['total'], $insert_id, $options); if (!is_array($invoice) or array_key_exists('error', $invoice)) { $this->log('createInvoice error ' . var_export($invoice['error'], true)); zen_remove_order($insert_id, $restock = true); // unfortunately, there's not a good way of telling the customer that it's hosed. Their cart is still full so they can try again w/ a different payment option. } else { $_SESSION['cart']->reset(true); zen_redirect($invoice['url']); } return false; }
function after_process() { global $insert_id, $order; require_once DIR_FS_CATALOG . 'callback/bitpay/library/bp_lib.php'; $lut = array("High-0 Confirmations" => 'high', "Medium-1 Confirmations" => 'medium', "Low-6 Confirmations" => 'low'); $network = array("Live" => 'Live', "Test" => 'Test'); // change order status to value selected by merchant xtc_db_query("update " . TABLE_ORDERS . " set orders_status = " . intval(MODULE_PAYMENT_BITPAY_UNPAID_STATUS_ID) . " where orders_id = " . intval($insert_id)); $options = array('physical' => $order->content_type == 'physical' ? 'true' : 'false', 'currency' => $order->info['currency'], 'buyerName' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 'fullNotifications' => 'true', 'notificationURL' => xtc_href_link('callback/bitpay/bitpay_callback.php', '', 'SSL', true, true), 'redirectURL' => xtc_href_link('account'), 'transactionSpeed' => $lut[MODULE_PAYMENT_BITPAY_TRANSACTION_SPEED], 'apiKey' => MODULE_PAYMENT_BITPAY_APIKEY, 'network' => $network[MODULE_PAYMENT_BITPAY_NETWORK]); $decimal_place = xtc_db_fetch_array(xtc_db_query("SELECT decimal_point FROM " . TABLE_CURRENCIES . " WHERE code = '" . $order->info['currency'] . "'")); $thousands_place = xtc_db_fetch_array(xtc_db_query("SELECT thousands_point FROM " . TABLE_CURRENCIES . " WHERE code = '" . $order->info['currency'] . "'")); $decimal_place = $decimal_place['decimal_point']; $thousands_place = $thousands_place['thousands_point']; $priceString = preg_replace('/[^0-9' . $decimal_place . ']/', '', $order->info['total']); if ($decimal_place != '.') { $priceString = preg_replace('/[' . $decimal_place . ']/', '.', $priceString); } $price = floatval($priceString); $invoice = bpCreateInvoice($insert_id, $price, $insert_id, $options); if (is_array($invoice) && array_key_exists('error', $invoice)) { // error bpLog('Error creating invoice: ' . var_export($invoice, true)); xtc_remove_order($insert_id, $restock = true); xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode($invoice['error']['message']), 'SSL')); } else { if (!is_array($invoice)) { // error bpLog('Error creating invoice: ' . var_export($this->invoice, true)); xtc_remove_order($insert_id, $restock = true); xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode('There was a problem processing your payment: invalid response returned from gateway.'), 'SSL')); } else { if (is_array($invoice) && array_key_exists('url', $invoice)) { // success $_SESSION['cart']->reset(true); xtc_redirect($invoice['url']); } else { // unknown problem bpLog('Error creating invoice: ' . var_export($invoice, true)); xtc_remove_order($insert_id, $restock = true); xtc_redirect(xtc_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode('There was a problem processing your payment: unknown error or response.'), 'SSL')); } } } return false; }
function CreateInvoiceAndRedirect($payment, $amount) { include Mage::getBaseDir('lib') . '/bitpay/bp_lib.php'; $apiKey = Mage::getStoreConfig('payment/Bitcoins/api_key'); $speed = Mage::getStoreConfig('payment/Bitcoins/speed'); $order = $payment->getOrder(); $orderId = $order->getIncrementId(); $options = array('currency' => $order->getBaseCurrencyCode(), 'buyerName' => $order->getCustomerFirstname() . ' ' . $order->getCustomerLastname(), 'fullNotifications' => 'true', 'notificationURL' => Mage::getUrl('bitpay_callback'), 'redirectURL' => Mage::getUrl('customer/account'), 'transactionSpeed' => $speed, 'apiKey' => $apiKey); $options += $this->ExtractAddress($order->getShippingAddress()); $invoice = bpCreateInvoice($orderId, $amount, array('orderId' => $orderId), $options); $payment->setIsTransactionPending(true); // status will be PAYMENT_REVIEW instead of PROCESSING if (array_key_exists('error', $invoice)) { Mage::log('Error creating bitpay invoice', null, 'bitpay.log'); Mage::log($invoice['error'], null, 'bitpay.log'); Mage::throwException("Error creating bit-pay invoice. Please try again or use another payment option."); } else { $invoiceId = Mage::getModel('sales/order_invoice_api')->create($orderId, array()); Mage::getSingleton('customer/session')->setRedirectUrl($invoice['url']); } return $this; }
<?php require 'bp_lib.php'; require 'config.php'; require 'functions.php'; if ($_POST['x_login'] != $login) { debuglog('ecwid login does not match that found in config.php'); print 'invalid ecwid login'; die; } // create invoice $posData = array($_POST['x_amount'], $_POST['x_invoice_num']); $options = array('apiKey' => $apiKey, 'notificationURL' => $bitpayURL . 'callback.php', 'transactionSpeed' => $speed, 'fullNotifications' => true, 'itemDesc' => $_POST['x_description'], 'currency' => $_POST['x_currency_code'], 'redirectURL' => $bitpayURL . 'redirect2ecwid.php?ecwidInvoiceId=' . $_POST['x_invoice_num'], 'buyerEmail' => $_POST['x_email'], 'buyerName' => $_POST['x_first_name'] . ' ' . $_POST['x_last_name'], 'buyerAddress1' => $_POST['x_address'], 'buyerCity' => $_POST['x_city'], 'buyerState' => $_POST['x_state'], 'buyerZip' => $_POST['x_zip'], 'buyerCountry' => $_POST['x_country']); $invoice = bpCreateInvoice(NULL, $_POST['x_amount'], $posData, $options); if (isset($invoice['error'])) { debuglog('Error creating invoice'); print 'Error creating invoice'; die; } // save bitpay invoice id in a file named after the ecwid invoice id file_put_contents($_POST['x_invoice_num'] . '.inv', $invoice['id']); // redirect to bitpay header('Location: ' . $invoice['url']);
$currentCurrency = mysql_fetch_assoc($result); if (!$currentCurrency) { bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid invoice currency of ' . $currency); die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid invoice currency of ' . $currency); } $result = mysql_query("SELECT code, rate FROM tblcurrencies where `id` = {$convertTo}"); $convertToCurrency = mysql_fetch_assoc($result); if (!$convertToCurrency) { bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid convertTo currency of ' . $convertTo); die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invalid convertTo currency of ' . $convertTo); } $currency = $convertToCurrency['code']; $price = $price / $currentCurrency['rate'] * $convertToCurrency['rate']; } // create invoice $options = $_POST; unset($options['invoiceId']); unset($options['systemURL']); $options['notificationURL'] = $_POST['systemURL'] . '/modules/gateways/callback/bitpay.php'; $options['redirectURL'] = $_POST['systemURL']; $options['apiKey'] = $GATEWAY['apiKey']; $options['transactionSpeed'] = $GATEWAY['transactionSpeed']; $options['currency'] = $currency; $options['network'] = $GATEWAY['network']; $invoice = bpCreateInvoice($invoiceId, $price, $invoiceId, $options); if (isset($invoice['error'])) { bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invoice error: ' . var_export($invoice['error'], true)); die('[ERROR] In modules/gateways/bitpay/createinvoice.php: Invoice error: ' . var_export($invoice['error']['message'], true)); } else { header('Location: ' . $invoice['url']); }
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. * * Written by Rich Morgan (rich@bitpay.com) */ require_once 'bp_lib.php'; global $bpOptions; if (isset($_POST['rcla'])) { $post = array(); $bpOptions['apiKey'] = base64_decode(trim($_POST['rcla'])); $opts = array('orderID', 'itemDesc', 'itemCode', 'notificationEmail', 'notificationURL', 'redirectURL', 'currency', 'physical', 'fullNotifications', 'transactionSpeed', 'buyerName', 'buyerAddress1', 'buyerAddress2', 'buyerCity', 'buyerState', 'buyerZip', 'buyerEmail', 'buyerPhone'); $opts = array_flip($opts); foreach ($_POST as $key => $value) { if (array_key_exists($key, $opts)) { $post[$key] = $_POST[$key]; } } $invresp = bpCreateInvoice($_POST['orderId'], $_POST['price'], substr($_POST['posData'], 0, 99), $post, $_POST['network']); if (isset($invresp['url'])) { header('Location: ' . $invresp['url']); } else { bplog($invresp['error']['message']); } echo 'BitPay Transaction Error:<br />"' . $invresp['error']['message'] . '"<br />Please contact the site administrator'; die; } else { die; }
function onAfterOrderConfirm(&$order, &$methods, $method_id) { require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bitpay/bp_lib.php'; $method =& $methods[$method_id]; $tax_total = ''; $discount_total = ''; $currencyClass = hikashop_get('class.currency'); $currencies = null; $currencies = $currencyClass->getCurrencies($order->order_currency_id, $currencies); $currency = $currencies[$order->order_currency_id]; if ($currency->currency_locale['int_frac_digits'] > 2) { $currency->currency_locale['int_frac_digits'] = 2; } hikashop_loadUser(true, true); //reset user data in case the emails were changed in the email code $user = hikashop_loadUser(true); $lang = JFactory::getLanguage(); $locale = strtolower(substr($lang->get('tag'), 0, 2)); if (!isset($method->payment_params->no_shipping)) { $method->payment_params->no_shipping = 1; } if (!empty($method->payment_params->rm)) { $method->payment_params->rm = 2; } //"currency_code" => $currency->currency_code, $vars = array(); $sessionid = $order->order_id; $lang = JFactory::getLanguage(); $locale = strtolower(substr($lang->get('tag'), 0, 2)); global $Itemid; $url_itemid = ''; if (!empty($Itemid)) { $url_itemid = '&Itemid=' . $Itemid; } $notify_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&bitpay_callback=true&task=notify¬if_payment=hikabitcoin&tmpl=component&lang=' . $locale . $url_itemid; //currency $options['currency'] = $currency->currency_code; $options['notificationURL'] = $notify_url; $options['notificationEmail'] = $method->payment_params->notificationEmail; //pass sessionid along so that it can be used to populate the transaction results page $return_url = HIKASHOP_LIVE . 'index.php?option=com_hikashop&ctrl=checkout&task=after_end&order_id=' . $order->order_id . $url_itemid; $options['redirectURL'] = $return_url . "&sessionid=" . $sessionid; $options['transactionSpeed'] = $method->payment_params->transactionSpeed; $options['apiKey'] = $method->payment_params->apiKey; $options['posData'] = $order->order_id; $options['fullNotifications'] = true; $options['orderID'] = $order->order_id; if (!empty($method->payment_params->address_type)) { $address_type = $method->payment_params->address_type . '_address'; $app = JFactory::getApplication(); $address = $app->getUserState(HIKASHOP_COMPONENT . '.' . $address_type); if (!empty($address)) { if (!isset($method->payment_params->address_override)) { $method->payment_params->address_override = '1'; } $vars["address_override"] = $method->payment_params->address_override; $cart = hikashop_get('class.cart'); $cart->loadAddress($order->cart, $address, 'object', $method->payment_params->address_type); $vars["bill_first_name"] = @$order->cart->{$address_type}->address_firstname; $vars["bill_last_name"] = @$order->cart->{$address_type}->address_lastname; $address1 = ''; $address2 = ''; if (!empty($order->cart->{$address_type}->address_street2)) { $address2 = substr($order->cart->{$address_type}->address_street2, 0, 99); } if (!empty($order->cart->{$address_type}->address_street)) { if (strlen($order->cart->{$address_type}->address_street) > 100) { $address1 = substr($order->cart->{$address_type}->address_street, 0, 99); if (empty($address2)) { $address2 = substr($order->cart->{$address_type}->address_street, 99, 199); } } else { $address1 = $order->cart->{$address_type}->address_street; } } if (isset($vars["bill_first_name"])) { $options['buyerName'] = $vars["bill_first_name"]; if (isset($vars["bill_last_name"])) { $options['buyerName'] .= ' ' . $vars["bill_last_name"]; } } $options["buyerAddress1"] = $address1; $options["buyerAddress2"] = $address2; $options["buyerZip"] = @$order->cart->{$address_type}->address_post_code; $options["buyerCity"] = @$order->cart->{$address_type}->address_city; $options["buyerState"] = @$order->cart->{$address_type}->address_state->zone_code_3; $options["buyerCountry"] = @$order->cart->{$address_type}->address_country->zone_code_2; $options["buyerEmail"] = $user->user_email; $options["buyerPhone"] = @$order->cart->{$address_type}->address_telephone; } elseif (!empty($order->cart->billing_address->address_country->zone_code_2)) { $options["buyerCountry"] = $order->cart->billing_address->address_country->zone_code_2; } } elseif (!empty($order->cart->billing_address->address_country->zone_code_2)) { $options["buyerCountry"] = $order->cart->billing_address->address_country->zone_code_2; } /*if(empty($method->payment_params->details)){ $vars["price1"]=sprintf('%.2f',$order->cart->full_total->prices[0]->price_value_with_tax,(int)$currency->currency_locale['int_frac_digits']); $vars["description1"]=JText::_('CART_PRODUCT_TOTAL_PRICE'); }else{ $i = 1; $tax = 0; foreach($order->cart->products as $product){ $vars["description".$i]=substr(strip_tags($product->order_product_name),0,127); $vars["id".$i]=$product->order_product_code; $vars["price".$i]=sprintf('%.2f',$product->order_product_price,(int)$currency->currency_locale['int_frac_digits']); $vars["quantity".$i]=$product->order_product_quantity; $tax+=sprintf('%.2f',$product->order_product_tax,(int)$currency->currency_locale['int_frac_digits'])*$product->order_product_quantity; $i++; } if(!empty($order->order_shipping_price) && bccomp($order->order_shipping_price,0,5)){ $vars["description".$i]=JText::_('HIKASHOP_SHIPPING'); $vars["price".$i]=sprintf('%.2f',$order->order_shipping_price-@$order->order_shipping_tax,(int)$currency->currency_locale['int_frac_digits']); $tax+=sprintf('%.2f',$order->order_shipping_tax,(int)$currency->currency_locale['int_frac_digits']); $vars["quantity".$i]=1; $i++; } if(!empty($order->order_payment_price) && bccomp($order->order_payment_price,0,5)){ $vars["description".$i]=JText::_('HIKASHOP_PAYMENT'); $vars["price".$i]=sprintf('%.2f',$order->order_payment_price,(int)$currency->currency_locale['int_frac_digits']); $vars["quantity".$i]=1; $i++; } if(bccomp($tax,0,5)){ $vars['price_taxes']=$tax; } if(!empty($order->cart->coupon)){ $vars["discount_amount_cart"]=sprintf('%.2f',$order->order_discount_price,(int)$currency->currency_locale['int_frac_digits']); } }*/ // itemDesc if (count($order->cart->products) == 1) { $item = $order->cart->products[0]; $options['itemDesc'] = $item->order_product_name; if ($item->order_product_quantity > 1) { $options['itemDesc'] = $item->order_product_quantity . 'x ' . $options['itemDesc']; } if (strlen($options['itemDesc']) >= 100) { $options['itemDesc'] = substr($options['itemDesc'], 0, 95) . ' ...'; } } else { foreach ($order->cart->products as $item) { $quantity += $item->order_product_quantity; } $options['itemDesc'] = $quantity . ' items'; } // truncate if longer than 100 chars foreach (array("buyerName", "buyerAddress1", "buyerAddress2", "buyerCity", "buyerState", "buyerZip", "buyerCountry", "buyerEmail", "buyerPhone") as $k) { if (isset($options[$k])) { $options[$k] = substr($options[$k], 0, 100); } } $price = sprintf('%.2f', $order->cart->full_total->prices[0]->price_value_with_tax, (int) $currency->currency_locale['int_frac_digits']); $invoice = bpCreateInvoice($sessionid, $price, $sessionid, $options); if (isset($invoice['error'])) { bpLog($invoice); if (isset($invoice['error']['message'])) { $invoice['error'] = $invoice['error']['message']; } JFactory::getApplication()->enqueueMessage('Sorry your transaction did not go through successfully, please try again.<br/>Error:' . $invoice['error'], 'error'); return false; } else { /*echo '<pre>price'.$price;print_r($options);print_r($order->cart);print_r($invoice);exit; $app = JFactory::getApplication(); $app->setRedirect($url); $wpsc_cart->empty_cart(); unset($_SESSION['WpscGatewayErrorMessage']);*/ header("Location: " . $invoice['url']); exit; //return true; } }
function gateway_bitpay($seperator, $sessionid) { require 'wp-content/plugins/wp-e-commerce/wpsc-merchants/bitpay/bp_lib.php'; //$wpdb is the database handle, //$wpsc_cart is the shopping cart object global $wpdb, $wpsc_cart; //This grabs the purchase log id from the database //that refers to the $sessionid $purchase_log = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1", ARRAY_A); //This grabs the users info using the $purchase_log // from the previous SQL query $usersql = "SELECT `" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.value,\r\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`name`,\r\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.`unique_name` FROM\r\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "` LEFT JOIN\r\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ON\r\n\t\t`" . WPSC_TABLE_CHECKOUT_FORMS . "`.id =\r\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`form_id` WHERE\r\n\t\t`" . WPSC_TABLE_SUBMITED_FORM_DATA . "`.`log_id`=" . $purchase_log['id']; $userinfo = $wpdb->get_results($usersql, ARRAY_A); // convert from awkward format foreach ((array) $userinfo as $value) { if (strlen($value['value'])) { $ui[$value['unique_name']] = $value['value']; } } $userinfo = $ui; // name if (isset($userinfo['billingfirstname'])) { $options['buyerName'] = $userinfo['billingfirstname']; if (isset($userinfo['billinglastname'])) { $options['buyerName'] .= ' ' . $userinfo['billinglastname']; } } //address -- remove newlines if (isset($userinfo['billingaddress'])) { $newline = strpos($userinfo['billingaddress'], "\n"); if ($newline !== FALSE) { $options['buyerAddress1'] = substr($userinfo['billingaddress'], 0, $newline); $options['buyerAddress2'] = substr($userinfo['billingaddress'], $newline + 1); $options['buyerAddress2'] = preg_replace('/\\r\\n/', ' ', $options['buyerAddress2'], -1, $count); } else { $options['buyerAddress1'] = $userinfo['billingaddress']; } } // state if (isset($userinfo['billingstate'])) { $options['buyerState'] = wpsc_get_state_by_id($userinfo['billingstate'], 'code'); } // more user info foreach (array('billingphone' => 'buyerPhone', 'billingemail' => 'buyerEmail', 'billingcity' => 'buyerCity', 'billingcountry' => 'buyerCountry', 'billingpostcode' => 'buyerZip') as $f => $t) { if ($userinfo[$f]) { $options[$t] = $userinfo[$f]; } } // itemDesc if (count($wpsc_cart->cart_items) == 1) { $item = $wpsc_cart->cart_items[0]; $options['itemDesc'] = $item->product_name; if ($item->quantity > 1) { $options['itemDesc'] = $item->quantity . 'x ' . $options['itemDesc']; } } else { foreach ($wpsc_cart->cart_items as $item) { $quantity += $item->quantity; } $options['itemDesc'] = $quantity . ' items'; } if (get_option('permalink_structure') != '') { $separator = "?"; } else { $separator = "&"; } //currency $currencyId = get_option('currency_type'); $options['currency'] = $wpdb->get_var($wpdb->prepare("SELECT `code` FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id` = %d LIMIT 1", $currencyId)); $options['notificationURL'] = get_option('siteurl') . '/?bitpay_callback=true'; // Test or Live mode URL switch $options['testMode'] = get_option('test_mode'); //pass sessionid along so that it can be used to populate the transaction results page $options['redirectURL'] = get_option('bitpay_redirect') . $separator . 'sessionid=' . $sessionid; $options['transactionSpeed'] = get_option('bitpay_transaction_speed'); $options['apiKey'] = get_option('bitpay_apikey'); $options['posData'] = $sessionid; $options['fullNotifications'] = true; // truncate if longer than 100 chars foreach (array("buyerName", "buyerAddress1", "buyerAddress2", "buyerCity", "buyerState", "buyerZip", "buyerCountry", "buyerEmail", "buyerPhone") as $k) { $options[$k] = substr($options[$k], 0, 100); } $price = number_format($wpsc_cart->total_price, 2); $invoice = bpCreateInvoice($sessionid, $price, $sessionid, $options); if (isset($invoice['error'])) { debuglog($invoice); // close order $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed`= '5' WHERE `sessionid`=" . $sessionid; $wpdb->query($sql); //redirect back to checkout page with errors $_SESSION['WpscGatewayErrorMessage'] = __('Sorry your transaction did not go through successfully, please try again.'); header('Location: ' . get_option('checkout_url')); } else { $wpsc_cart->empty_cart(); unset($_SESSION['WpscGatewayErrorMessage']); header('Location: ' . $invoice['url']); exit; } }
/** * @return false */ function after_process() { global $insert_id, $order; require_once 'bitpay/bp_lib.php'; $lut = array("High-0 Confirmations" => 'high', "Medium-1 Confirmations" => 'medium', "Low-6 Confirmations" => 'low'); // change order status to value selected by merchant tep_db_query("update " . TABLE_ORDERS . " set orders_status = " . intval(MODULE_PAYMENT_BITPAY_UNPAID_STATUS_ID) . " where orders_id = " . intval($insert_id)); $options = array('physical' => $order->content_type == 'physical' ? 'true' : 'false', 'currency' => $order->info['currency'], 'buyerName' => $order->customer['firstname'] . ' ' . $order->customer['lastname'], 'fullNotifications' => 'true', 'notificationURL' => tep_href_link('bitpay_callback.php', '', 'SSL', true, true), 'redirectURL' => tep_href_link(FILENAME_ACCOUNT), 'transactionSpeed' => $lut[MODULE_PAYMENT_BITPAY_TRANSACTION_SPEED], 'apiKey' => MODULE_PAYMENT_BITPAY_APIKEY); $invoice = bpCreateInvoice($insert_id, $order->info['total'], $insert_id, $options); if (is_array($invoice) && array_key_exists('error', $invoice)) { // error bpLog('Error creating invoice: ' . var_export($invoice, true)); tep_remove_order($insert_id, $restock = true); tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode($invoice['error']['message']), 'SSL')); } else { if (!is_array($invoice)) { // error bpLog('Error creating invoice: ' . var_export($invoice, true)); tep_remove_order($insert_id, $restock = true); tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode('There was a problem processing your payment: invalid response returned from gateway.'), 'SSL')); } else { if (is_array($invoice) && array_key_exists('url', $invoice)) { // success $_SESSION['cart']->reset(true); tep_redirect($invoice['url']); } else { // unknown problem bpLog('Error creating invoice: ' . var_export($invoice, true)); tep_remove_order($insert_id, $restock = true); tep_redirect(tep_href_link(FILENAME_SHOPPING_CART, 'error_message=' . urlencode('There was a problem processing your payment: unknown error or response.'), 'SSL')); } } } return false; }