public function indexAction()
 {
     require Mage::getBaseDir('lib') . '/bitpay/bp_lib.php';
     Mage::log(file_get_contents('php://input'), null, 'bitpay.log');
     $apiKey = Mage::getStoreConfig('payment/Bitcoins/api_key');
     $invoice = bpVerifyNotification($apiKey);
     if (is_string($invoice)) {
         Mage::log("bitpay callback error: {$invoice}", null, 'bitpay.log');
     } else {
         // get the order
         if (isset($invoice['posData']['quoteId'])) {
             $quoteId = $invoice['posData']['quoteId'];
             $order = Mage::getModel('sales/order')->load($quoteId, 'quote_id');
         } else {
             $orderId = $invoice['posData']['orderId'];
             $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
         }
         // save the ipn so that we can find it when the user clicks "Place Order"
         Mage::getModel('Bitcoins/ipn')->Record($invoice);
         // update the order if it exists already
         if ($order->getId()) {
             switch ($invoice['status']) {
                 case 'confirmed':
                 case 'complete':
                     $method = Mage::getModel('Bitcoins/paymentMethod');
                     $method->MarkOrderPaid($order);
                     break;
             }
         }
     }
 }
Example #2
0
<?php

require 'config.php';
require 'bp_lib.php';
require 'functions.php';
$notice = bpVerifyNotification($apiKey);
if (isset($notice['error'])) {
    debuglog($notice);
    die;
}
postToEcwid($notice);
Example #3
0
    if (file_exists('../../../init.php')) {
        include '../../../init.php';
    } else {
        bpLog('[ERROR] In modules/gateways/bitpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
        die('[ERROR] In modules/gateways/bitpay/createinvoice.php: include error: Cannot find dbconnect.php or init.php');
    }
}
require_once '../bit-pay/bp_lib.php';
$gatewaymodule = 'bitpay';
$GATEWAY = getGatewayVariables($gatewaymodule);
if (!$GATEWAY['type']) {
    logTransaction($GATEWAY['name'], $_POST, 'Not activated');
    bpLog('[ERROR] In modules/gateways/callback/bitpay.php: bitpay module not activated');
    die('[ERROR] In modules/gateways/callback/bitpay.php: Bitpay module not activated.');
}
$response = bpVerifyNotification($GATEWAY['apiKey'], $GATEWAY['network']);
if (true === is_string($response) || true === empty($response)) {
    logTransaction($GATEWAY['name'], $_POST, $response);
    die('[ERROR] In modules/gateways/callback/bitpay.php: Invalid response received: ' . $response);
} else {
    $invoiceid = $response['posData'];
    // Checks invoice ID is a valid invoice number or ends processing
    $invoiceid = checkCbInvoiceID($invoiceid, $GATEWAY['name']);
    $transid = $response['id'];
    // Checks transaction number isn't already in the database and ends processing if it does
    checkCbTransID($transid);
    // Successful
    $fee = 0;
    // left blank, this will auto-fill as the full balance
    $amount = '';
    switch ($response['status']) {
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * 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.
 */
require 'library/bp_lib.php';
require '../../includes/application_top_callback.php';
require 'remove_order.php';
$response = bpVerifyNotification(MODULE_PAYMENT_BITPAY_APIKEY);
if (is_string($response)) {
    bpLog('bitpay callback error: ' . $response);
} else {
    $order_id = $response['posData'];
    switch ($response['status']) {
        case 'paid':
        case 'confirmed':
        case 'complete':
            if (function_exists('xtc_db_query')) {
                xtc_db_query("update " . TABLE_ORDERS . " set orders_status = " . MODULE_PAYMENT_BITPAY_PAID_STATUS_ID . " where orders_id = " . intval($order_id));
            } else {
                bpLog('FATAL: tep_db_query function is missing. Cannot update order_id = ' . $order_id . ' as ' . $response['status']);
            }
            break;
        case 'invalid':
 function onPaymentNotification(&$statuses)
 {
     $pluginsClass = hikashop_get('class.plugins');
     $elements = $pluginsClass->getMethods('payment', 'hikabitcoin');
     if (empty($elements)) {
         return false;
     }
     $element = reset($elements);
     $payment_params = $element->payment_params;
     $mailer = JFactory::getMailer();
     $config =& hikashop_config();
     $sender = array($config->get('from_email'), $config->get('from_name'));
     $mailer->setSender($sender);
     $mailer->addRecipient(explode(',', $config->get('payment_notification_email')));
     if ($payment_params->test) {
         echo "\n\n params" . print_r($payment_params, true);
     }
     if (!$payment_params->notification) {
         return false;
     }
     require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'bitpay/bp_lib.php';
     $response = bpVerifyNotification($payment_params->apiKey);
     if ($payment_params->test) {
         echo "\n\n response" . print_r($response, true);
     }
     if (is_string($response) || !empty($response['error'])) {
         bpLog($response);
         if (is_array($response)) {
             $response = $response['error'];
         }
         $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER', 'Bitcoin') . 'invalid response Server Response:' . $response);
         $body = JText::sprintf("Hello,\r\n A bitcoin notification was refused because the response from the bitcoin server was invalid");
         $mailer->setBody($body);
         $mailer->Send();
         return false;
     } else {
         $id = $orderid = $response['posData'];
         $orderClass = hikashop_get('class.order');
         $dbOrder = $orderClass->get((int) $id);
         $order = new stdClass();
         $order->order_id = $dbOrder->order_id;
         $order->old_status->order_status = $dbOrder->order_status;
         $url = HIKASHOP_LIVE . 'administrator/index.php?option=com_hikashop&ctrl=order&task=edit&order_id=' . $order->order_id;
         $order_text = "\r\n" . JText::sprintf('NOTIFICATION_OF_ORDER_ON_WEBSITE', $dbOrder->order_number, HIKASHOP_LIVE);
         $order_text .= "\r\n" . str_replace('<br/>', "\r\n", JText::sprintf('ACCESS_ORDER_WITH_LINK', $url));
         $isValid = true;
         if ($id > 0) {
             if (empty($dbOrder)) {
                 $isValid = false;
             }
         } else {
             $isValid = false;
         }
         if (!$isValid) {
             $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER', 'Bitcoin') . 'invalid transaction Server Response:' . $response['message']);
             $body = JText::sprintf("Hello,\r\n A bitcoin notification was refused because it could not be verified by the bitcoin server") . $order_text;
             $mailer->setBody($body);
             $mailer->Send();
             if ($element->payment_params->test) {
                 echo 'invalid transaction' . "\n\n\n";
             }
             return false;
         }
         echo 'Status: ' . $response['status'] . "\n\n\n";
         echo 'Invoice id: ' . $response['id'] . "\n\n\n";
         echo 'Url: ' . $response['url'] . "\n\n\n";
         echo 'posData: ' . $response['posData'] . "\n\n\n";
         echo 'price: ' . $response['price'] . "\n\n\n";
         echo 'btcPrice: ' . $response['btcPrice'] . "\n\n\n";
         $order->history->history_reason = JText::sprintf('AUTOMATIC_PAYMENT_NOTIFICATION');
         $order->history->history_notified = 0;
         $order->history->history_amount = @$response['price'];
         $order->history->history_payment_id = $element->payment_id;
         $order->history->history_payment_method = $element->payment_type;
         $order->history->history_data = ob_get_clean();
         $order->history->history_type = 'payment';
         $currencyClass = hikashop_get('class.currency');
         $currencies = null;
         $currencies = $currencyClass->getCurrencies($dbOrder->order_currency_id, $currencies);
         $currency = $currencies[$dbOrder->order_currency_id];
         $price_check = sprintf('%.2f', $dbOrder->order_full_price, (int) $currency->currency_locale['int_frac_digits']);
         if ($price_check != @$response['price']) {
             $order->order_status = $element->payment_params->invalid_status;
             $orderClass->save($order);
             $mailer->setSubject(JText::sprintf('NOTIFICATION_REFUSED_FOR_THE_ORDER', 'Bitcoin') . JText::_('INVALID_AMOUNT'));
             $body = str_replace('<br/>', "\r\n", JText::sprintf('AMOUNT_RECEIVED_DIFFERENT_FROM_ORDER', 'Bitcoin', $order->history->history_amount, $price_check . $currency->currency_code)) . "\r\n\r\n" . $order_text;
             $mailer->setBody($body);
             $mailer->Send();
             return false;
         }
         $send_mail = false;
         switch ($response['status']) {
             //For low and medium transaction speeds, the order status is set to "Order Received". The customer receives
             //an initial email stating that the transaction has been paid.
             case 'paid':
                 $send_mail = true;
                 $order->order_status = $element->payment_params->paid_status;
                 $order_text .= "Payment has been received for order number" . $dbOrder->order_number . ", but the transaction has not been confirmed on the bitcoin network. " . "You will receive another email when the transaction has been confirmed.";
                 //"Payment Received"
                 //false because this is just for email notification
                 break;
                 //For low and medium transaction speeds, the order status will not change. For high transaction speed, the order
                 //status is set to "Order Received" here. For all speeds, an email will be sent stating that the transaction has
                 //been confirmed.
             //For low and medium transaction speeds, the order status will not change. For high transaction speed, the order
             //status is set to "Order Received" here. For all speeds, an email will be sent stating that the transaction has
             //been confirmed.
             case 'confirmed':
                 $send_mail = true;
                 $order->order_status = $element->payment_params->confirmed_status;
                 //display initial "thank you" if transaction speed is high, as the 'paid' status is skipped on high speed
                 if (get_option('bitpay_transaction_speed') == 'high') {
                     $order_text .= "Payment has been received, and the transaction has been confirmed on the bitcoin network for order number" . $dbOrder->order_number . ". " . "You will receive another email when the transaction is complete.";
                     //"Payment Received"
                 } else {
                     $order_text .= "Transaction has now been confirmed on the bitcoin network order number" . $dbOrder->order_number . ". " . "You will receive another email when the transaction is complete.";
                     //"Transaction Confirmed"
                 }
                 //false because this is just for email notification
                 break;
                 //The purchase receipt email is sent upon the invoice status changing to "complete", and the order
                 //status is changed to Accepted Payment
             //The purchase receipt email is sent upon the invoice status changing to "complete", and the order
             //status is changed to Accepted Payment
             case 'complete':
                 $send_mail = true;
                 $order->order_status = $element->payment_params->complete_status;
                 $order->history->history_notified = 1;
                 $order_text .= "Transaction is now complete! for order number" . $dbOrder->order_number;
                 //"Transaction Complete"
                 //false because this is just for email notification
                 break;
             case 'invalid':
                 $send_mail = true;
                 $order->order_status = $element->payment_params->invalid_status;
                 $order_text .= "Invalid transaction for order number" . $dbOrder->order_number;
                 //false because this is just for email notification
                 break;
         }
         if ($dbOrder->order_status == $order->order_status) {
             return true;
         }
         if ($send_mail != true) {
             return true;
         }
         $order->mail_status = $statuses[$order->order_status];
         $mailer->setSubject(JText::sprintf('PAYMENT_NOTIFICATION_FOR_ORDER', 'Bitcoin', $response['status'], $dbOrder->order_number));
         $body = str_replace('<br/>', "\r\n", JText::sprintf('PAYMENT_NOTIFICATION_STATUS', 'Bitcoin', $response['status'])) . ' ' . JText::sprintf('ORDER_STATUS_CHANGED', $order->mail_status) . "\r\n\r\n" . $order_text;
         $mailer->setBody($body);
         $mailer->Send();
         $orderClass->save($order);
         return true;
     }
 }
function bitpay_callback()
{
    if (isset($_GET['bitpay_callback'])) {
        global $wpdb;
        require 'wp-content/plugins/wp-e-commerce/wpsc-merchants/bitpay/bp_lib.php';
        $response = bpVerifyNotification(get_option('bitpay_apikey'));
        if (isset($response['error'])) {
            debuglog($response);
        } else {
            $sessionid = $response['posData'];
            //get buyer email
            $sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`=" . $sessionid;
            $purchase_log = $wpdb->get_results($sql, ARRAY_A);
            $email_form_field = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `checkout_order` ASC LIMIT 1");
            $email = $wpdb->get_var($wpdb->prepare("SELECT `value` FROM `" . WPSC_TABLE_SUBMITTED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = %d LIMIT 1", $purchase_log[0]['id'], $email_form_field));
            //get cart contents
            $sql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase_log[0]['id'];
            $cart_contents = $wpdb->get_results($sql, ARRAY_A);
            //get currency symbol
            $currency_id = get_option('currency_type');
            $sql = "SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `id`=" . $currency_id;
            $currency_data = $wpdb->get_results($sql, ARRAY_A);
            $currency_symbol = $currency_data[0]['symbol'];
            //list products and individual prices in the email
            $message_product = "\r\n\r\nTransaction Details: \r\n\r\n";
            $pnp = 0.0;
            $subtotal = 0.0;
            foreach ($cart_contents as $product) {
                $pnp += $product['pnp'];
                //shipping for each item
                $message_product .= 'x' . $product['quantity'] . ' ' . $product['name'] . ' - ' . $currency_symbol . $product['price'] * $product['quantity'] . "\r\n";
                $subtotal += $product['price'] * $product['quantity'];
            }
            //list subtotal
            $subtotal = number_format($subtotal, 2, '.', ',');
            $message_product .= "\r\n" . 'Subtotal: ' . $currency_symbol . $subtotal . "\r\n";
            //list total taxes and total shipping costs in the email
            $message_product .= 'Taxes: ' . $currency_symbol . $purchase_log[0]['wpec_taxes_total'] . "\r\n";
            $message_product .= 'Shipping: ' . $currency_symbol . ($purchase_log[0]['base_shipping'] + $pnp) . "\r\n\r\n";
            //display total price in the email
            $message_product .= 'Total Price: ' . $currency_symbol . $purchase_log[0]['totalprice'];
            switch ($response['status']) {
                //For low and medium transaction speeds, the order status is set to "Order Received". The customer receives
                //an initial email stating that the transaction has been paid.
                case 'paid':
                    $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed`= '2' WHERE `sessionid`=" . $sessionid;
                    if (is_numeric($sessionid)) {
                        $wpdb->query($sql);
                    }
                    $message = 'Thank you! Your payment has been received, but the transaction has not been confirmed on the bitcoin network. You will receive another email when the transaction has been confirmed.';
                    $message .= $message_product;
                    wp_mail($email, 'Payment Received', $message);
                    $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `email_sent`= '1' WHERE `sessionid`=" . $sessionid;
                    transaction_results($sessionid, false);
                    //false because this is just for email notification
                    break;
                    //For low and medium transaction speeds, the order status will not change. For high transaction speed, the order
                    //status is set to "Order Received" here. For all speeds, an email will be sent stating that the transaction has
                    //been confirmed.
                //For low and medium transaction speeds, the order status will not change. For high transaction speed, the order
                //status is set to "Order Received" here. For all speeds, an email will be sent stating that the transaction has
                //been confirmed.
                case 'confirmed':
                    $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed`= '2' WHERE `sessionid`=" . $sessionid;
                    if (is_numeric($sessionid)) {
                        $wpdb->query($sql);
                    }
                    //display initial "thank you" if transaction speed is high, as the 'paid' status is skipped on high speed
                    if (get_option('bitpay_transaction_speed') == 'high') {
                        $message = 'Thank you! Your payment has been received, and the transaction has been confirmed on the bitcoin network. You will receive another email when the transaction is complete.';
                        $message .= $message_product;
                        wp_mail($email, 'Payment Received', $message);
                    } else {
                        $message = 'Your transaction has now been confirmed on the bitcoin network. You will receive another email when the transaction is complete.';
                        wp_mail($email, 'Transaction Confirmed', $message);
                    }
                    $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `email_sent`= '1' WHERE `sessionid`=" . $sessionid;
                    transaction_results($sessionid, false);
                    //false because this is just for email notification
                    break;
                    //The purchase receipt email is sent upon the invoice status changing to "complete", and the order
                    //status is changed to Accepted Payment
                //The purchase receipt email is sent upon the invoice status changing to "complete", and the order
                //status is changed to Accepted Payment
                case 'complete':
                    $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `processed`= '3' WHERE `sessionid`=" . $sessionid;
                    if (is_numeric($sessionid)) {
                        $wpdb->query($sql);
                    }
                    $message = 'Your transaction is now complete! Thank you for using BitPay!';
                    wp_mail($email, 'Transaction Complete', $message);
                    $sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `email_sent`= '1' WHERE `sessionid`=" . $sessionid;
                    transaction_results($sessionid, false);
                    //false because this is just for email notification
                    break;
            }
        }
    }
}