public function execPayment($cart) { // Create invoice $currency = Currency::getCurrencyInstance((int) $cart->id_currency); $options = $_POST; $options['transactionSpeed'] = Configuration::get('bitpay_TXSPEED'); $options['currency'] = $currency->iso_code; $total = $cart->getOrderTotal(true); $options['notificationURL'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/ipn.php'; if (_PS_VERSION_ <= '1.5') { $options['redirectURL'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . $cart->id . '&id_module=' . $this->id . '&id_order=' . $this->currentOrder; } else { $options['redirectURL'] = Context::getContext()->link->getModuleLink('bitpay', 'validation'); } $options['posData'] = '{"cart_id": "' . $cart->id . '"'; $options['posData'] .= ', "hash": "' . crypt($cart->id, Configuration::get('bitpay_APIKEY')) . '"'; $this->key = $this->context->customer->secure_key; $options['posData'] .= ', "key": "' . $this->key . '"}'; $options['orderID'] = $cart->id; $options['price'] = $total; $options['fullNotifications'] = true; $postOptions = array('orderID', 'itemDesc', 'itemCode', 'notificationEmail', 'notificationURL', 'redirectURL', 'posData', 'price', 'currency', 'physical', 'fullNotifications', 'transactionSpeed', 'buyerName', 'buyerAddress1', 'buyerAddress2', 'buyerCity', 'buyerState', 'buyerZip', 'buyerEmail', 'buyerPhone'); foreach ($postOptions as $o) { if (array_key_exists($o, $options)) { $post[$o] = $options[$o]; } } if (function_exists('json_encode')) { $post = json_encode($post); } else { $post = rmJSONencode($post); } // Call BitPay $curl = curl_init($this->apiurl . '/api/invoice/'); $length = 0; if ($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); $length = strlen($post); } $uname = base64_encode(Configuration::get('bitpay_APIKEY')); $header = array('Content-Type: application/json', 'Content-Length: ' . $length, 'Authorization: Basic ' . $uname, 'X-BitPay-Plugin-Info: prestashop0.4'); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_setopt($curl, CURLOPT_PORT, $this->sslport); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer); // verify certificate (1) curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost); // check existence of CN and verify that it matches hostname (2) curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); $responseString = curl_exec($curl); if (!$responseString) { $response = curl_error($curl); die(Tools::displayError("Error: no data returned from API server!")); } else { if (function_exists('json_decode')) { $response = json_decode($responseString, true); } else { $response = rmJSONdecode($responseString); } } curl_close($curl); if (isset($response['error'])) { bplog($response['error']); die(Tools::displayError("Error occurred! (" . $response['error']['type'] . " - " . $response['error']['message'] . ")")); } else { if (!$response['url']) { die(Tools::displayError("Error: Response did not include invoice url!")); } else { header('Location: ' . $response['url']); } } }
fclose($handle); if (function_exists('json_decode')) { $posData = json_decode($decoded['posData']); } else { $posData = rmJSONdecode($decoded['posData']); } $order = (int) Order::getOrderByCartId($posData->cart_id); if ($posData->hash == crypt($posData->cart_id, Configuration::get('bitpay_APIKEY'))) { $bitpay = new bitpay(); if (in_array($decoded['status'], array('paid', 'confirmed', 'complete'))) { if ($order == 0) { $key = $posData->key; $bitpay->validateOrder($posData->cart_id, Configuration::get('PS_OS_PAYMENT'), $decoded['price'], $bitpay->displayName, null, array(), null, false, $key); } else { if (empty(Context::getContext()->link)) { Context::getContext()->link = new Link(); } // workaround a prestashop bug so email is sent $key = $posData->key; $order = new Order((int) Order::getOrderByCartId($posData->cart_id)); $new_history = new OrderHistory(); $new_history->id_order = (int) $order->id; $order_status = (int) Configuration::get('PS_OS_PAYMENT'); $new_history->changeIdOrderState((int) $order_status, $order, true); $new_history->addWithemail(true); } } $bitpay->writeDetails($bitpay->currentOrder, $posData->cart_id, $decoded['id'], $decoded['status']); } else { bplog('Hash does not match'); }
/** * @param $cart * @param $order * * @return */ function plgVmConfirmedOrder($cart, $order) { if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return false; } // $params = new JParameter($payment->payment_params); // $lang = JFactory::getLanguage(); // $filename = 'com_virtuemart'; // $lang->load($filename, JPATH_ADMINISTRATOR); $vendorId = 0; $html = ""; VmConfig::loadJLang('com_virtuemart', true); VmConfig::loadJLang('com_virtuemart_orders', TRUE); $this->getPaymentCurrency($method); if (!class_exists('VirtueMartModelOrders')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'; } $this->getPaymentCurrency($method, true); $currency_code_3 = shopFunctions::getCurrencyByID($method->payment_currency, 'currency_code_3'); $email_currency = $this->getEmailCurrency($method); // END printing out HTML Form code (Payment Extra Info) $q = 'SELECT `currency_code_3` FROM `#__virtuemart_currencies` WHERE `virtuemart_currency_id`="' . $method->payment_currency . '" '; $db = JFactory::getDBO(); $db->setQuery($q); $paymentCurrency = CurrencyDisplay::getInstance($method->payment_currency); $totalInPaymentCurrency = round($paymentCurrency->convertCurrencyTo($method->payment_currency, $order['details']['BT']->order_total, false), 2); $cd = CurrencyDisplay::getInstance($cart->pricesCurrency); $usrBT = $order['details']['BT']; $usrST = isset($order['details']['ST']) ? $order['details']['ST'] : $order['details']['BT']; $options['transactionSpeed'] = $method->speed; $options['currency'] = $currency_code_3; $options['notificationURL'] = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification&tmpl=component'); $options['redirectURL'] = JROUTE::_(JURI::root() . 'index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&on=' . $order['details']['BT']->order_number . '&pm=' . $order['details']['BT']->virtuemart_paymentmethod_id . '&Itemid=' . JRequest::getInt('Itemid')); $options['posData'] = '{"id_order": "' . $order['details']['BT']->order_number . '"'; $options['posData'] .= ', "hash": "' . crypt($order['details']['BT']->order_number, $method->merchant_apikey) . '"'; $options['posData'] .= '}'; $options['orderID'] = $order['details']['BT']->order_number; $options['price'] = $order['details']['BT']->order_total; $postOptions = array('orderID', 'itemDesc', 'itemCode', 'notificationEmail', 'notificationURL', 'redirectURL', 'posData', 'price', 'currency', 'physical', 'fullNotifications', 'transactionSpeed', 'buyerName', 'buyerAddress1', 'buyerAddress2', 'buyerCity', 'buyerState', 'buyerZip', 'buyerEmail', 'buyerPhone'); foreach ($postOptions as $o) { if (array_key_exists($o, $options)) { $post[$o] = $options[$o]; } } $post = json_encode($post); // Call BitPay if ($method->network == "test") { $network_uri = 'test.bitpay.com'; } else { $network_uri = 'bitpay.com'; } $curl = curl_init('https://' . $network_uri . '/api/invoice/'); $length = 0; if ($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); $length = strlen($post); } $uname = base64_encode($method->merchant_apikey); $header = array('Content-Type: application/json', "Content-Length: {$length}", "Authorization: Basic {$uname}", 'X-BitPay-Plugin-Info: virtuemart033114'); curl_setopt($curl, CURLOPT_PORT, 443); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); // verify certificate curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); // check existence of CN and verify that it matches hostname curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); $responseString = curl_exec($curl); if ($responseString == false) { $response = curl_error($curl); } else { $response = json_decode($responseString, true); } curl_close($curl); $this->logInfo('invoice ' . implode(' / ', $response), 'message'); if (isset($response['url'])) { $cart->emptyCart(); header('Location: ' . $response['url']); exit; } else { $html = vmText::_('BitPay could not process your payment for the following reasons:') . " <br /> -------------------- " . "<br />" . vmText::_($response['error']['message']) . "<br /> " . vmText::_('Please contact the store owner'); bplog("VM BitPayError: " . $response['error']['message'] . " with order id: " . $order['details']['BT']->order_number); bplog('curl error - no invoice url'); $returnValue = 0; return $this->processConfirmedOrderPaymentResponse($returnValue, $cart, $order, $html, '', ''); } }
*/ require 'bitpay/bp_lib.php'; require 'includes/application_top.php'; function bplog($contents) { if (true === isset($contents)) { if (true === is_resource($contents)) { error_log(serialize($contents)); } else { error_log(var_export($contents, true)); } } } $response = bpVerifyNotification(MODULE_PAYMENT_BITPAY_APIKEY); if (true === is_string($response)) { bplog(date('H:i') . " bitpay callback error: " . $response . "\n"); } else { global $db; $order_id = $response['posData']; switch ($response['status']) { case 'confirmed': case 'complete': $db->Execute("update " . TABLE_ORDERS . " set orders_status = " . MODULE_PAYMENT_BITPAY_PAID_STATUS_ID . " where orders_id = " . intval($order_id)); break; case 'expired': if (true === function_exists('zen_remove_order')) { zen_remove_order($order_id, $restock = true); } break; } }
* 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; }
public function execPayment($cart) { // Create invoice $currency = Currency::getCurrencyInstance((int) $cart->id_currency); $options = $_POST; $clientid = Configuration::get('tinklit_CLIENTID'); $token = Configuration::get('tinklit_TOKEN'); $options['currency'] = $currency->iso_code; // only EUR at the moment $total = $cart->getOrderTotal(true); $options['notification_url'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/ipn.php'; if (_PS_VERSION_ <= '1.5') { $options['redirect_url'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . $cart->id . '&id_module=' . $this->id . '&id_order=' . $this->currentOrder; } else { $options['redirect_url'] = Context::getContext()->link->getModuleLink('tinklit', 'validation'); } // item_code will provide cart id // order_id will provide customer secure_key $options['item_code'] = $cart->id; $options['order_id'] = $this->context->customer->secure_key; $options['price'] = $total; // send these to invoice API $postOptions = array('item_code', 'order_id', 'notification_url', 'redirect_url', 'price', 'currency'); foreach ($postOptions as $o) { if (array_key_exists($o, $options)) { $post[$o] = $options[$o]; } } if (function_exists('json_encode')) { $post = json_encode($post); } else { $post = rmJSONencode($post); } // Call Tinklit $curl = curl_init($this->apiurl . '/v1/invoices'); //$curl = curl_init('https://api-staging.tinkl.it/v1/invoices'); $length = 0; if ($post) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); $length = strlen($post); } $header = array('Content-Type: application/json', 'Content-Length: ' . $length, 'X-Tinklit-Plugin-Info: ' . $this->name . '_' . $this->version, 'X-CLIENT-ID: ' . $clientid, 'X-AUTH-TOKEN: ' . $token); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_setopt($curl, CURLOPT_PORT, $this->sslport); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_TIMEOUT, 10); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer); // verify certificate (1) curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost); // check existence of CN and verify that it matches hostname (2) curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); $responseString = curl_exec($curl); if (!$responseString) { $response = curl_error($curl); p("Error: "); p($response); p($this->apiurl); die(Tools::displayError("Error: no data returned from tinklit API server!")); } else { if (function_exists('json_decode')) { $response = json_decode($responseString, true); } else { $response = rmJSONdecode($responseString); } } curl_close($curl); if (isset($response['error'])) { bplog($response['error']); die(Tools::displayError("Error occurred! (" . $response['error']['type'] . " - " . $response['error']['message'] . ")")); } else { if (!$response['url']) { die(Tools::displayError("Error: Response did not include invoice url!")); } else { header('Location: ' . $response['url']); } } }