Exemplo n.º 1
0
 public static function isPaymentValid($oplataSettings, $response)
 {
     list($orderId, ) = explode(self::ORDER_SEPARATOR, $response['order_id']);
     $order = uc_order_load($orderId);
     if ($order === FALSE || uc_order_status_data($order->order_status, 'state') != 'in_checkout') {
         return t('An error has occurred during payment. Please contact us to ensure your order has submitted.');
     }
     if ($oplataSettings->merchant_id != $response['merchant_id']) {
         return t('An error has occurred during payment. Merchant data is incorrect.');
     }
     $originalResponse = $response;
     foreach ($response as $k => $v) {
         if (!in_array($k, self::$responseFields)) {
             unset($response[$k]);
         }
     }
     if (self::getSignature($response, $oplataSettings->secret_key) != $originalResponse['signature']) {
         return t('An error has occurred during payment. Signature is not valid.');
     }
     if (drupal_strtolower($originalResponse['sender_email']) !== drupal_strtolower($order->primary_email)) {
         uc_order_comment_save($order->order_id, 0, t('Customer used a different e-mail address during payment: !email', array('!email' => check_plain($originalResponse['sender_email']))), 'admin');
     }
     uc_order_comment_save($order->order_id, 0, "Order status: {$response['order_status']}", 'admin');
     return true;
 }
Exemplo n.º 2
0
 protected function loadTaxLine($order_id)
 {
     $order = uc_order_load($order_id, TRUE);
     foreach ($order->line_items as $line) {
         if ($line['type'] == 'tax') {
             return $line;
         }
     }
     return FALSE;
 }
Exemplo n.º 3
0
/**
 * Calculate tax line items for an order.
 *
 * @param $order
 *   An order object or an order id.
 * @return
 *   An array of tax line item objects keyed by a module-specific id.
 */
function hook_calculate_tax($order)
{
    global $user;
    if (is_numeric($order)) {
        $order = uc_order_load($order);
        $account = user_load(array('uid' => $order->uid));
    } elseif ((int) $order->uid) {
        $account = user_load(array('uid' => intval($order->uid)));
    } else {
        $account = $user;
    }
    if (!is_object($order)) {
        return array();
    }
    if (empty($order->delivery_postal_code)) {
        $order->delivery_postal_code = $order->billing_postal_code;
    }
    if (empty($order->delivery_zone)) {
        $order->delivery_zone = $order->billing_zone;
    }
    if (empty($order->delivery_country)) {
        $order->delivery_country = $order->billing_country;
    }
    $order->taxes = array();
    if (isset($order->order_status)) {
        $state = uc_order_status_data($order->order_status, 'state');
        $use_same_rates = in_array($state, array('payment_received', 'completed'));
    } else {
        $use_same_rates = FALSE;
    }
    $arguments = array('order' => array('#entity' => 'uc_order', '#title' => t('Order'), '#data' => $order), 'tax' => array('#entity' => 'tax', '#title' => t('Tax rule')), 'account' => array('#entity' => 'user', '#title' => t('User'), '#data' => $account));
    $predicates = ca_load_trigger_predicates('calculate_taxes');
    foreach (uc_taxes_rate_load() as $tax) {
        if ($use_same_rates) {
            foreach ((array) $order->line_items as $old_line) {
                if ($old_line['type'] == 'tax' && $old_line['data']['tax_id'] == $tax->id) {
                    $tax->rate = $old_line['data']['tax_rate'];
                    break;
                }
            }
        }
        $arguments['tax']['#data'] = $tax;
        if (ca_evaluate_conditions($predicates['uc_taxes_' . $tax->id], $arguments)) {
            $line_item = uc_taxes_action_apply_tax($order, $tax);
            if ($line_item) {
                $order->taxes[$line_item->id] = $line_item;
            }
        }
    }
    return $order->taxes;
}
Exemplo n.º 4
0
/**
 * Calculate tax line items for an order.
 *
 * @param $order
 *   An order object or an order id.
 * @return
 *   An array of tax line items keyed by a module-specific id.
 */
function hook_calculate_tax($order)
{
    global $user;
    if (is_numeric($order)) {
        $order = uc_order_load($order);
        $account = user_load(array('uid' => $order->uid));
    } else {
        if ((int) $order->uid) {
            $account = user_load(array('uid' => intval($order->uid)));
        } else {
            $account = $user;
        }
    }
    if (!is_object($order)) {
        return array();
    }
    if (empty($order->delivery_postal_code)) {
        $order->delivery_postal_code = $order->billing_postal_code;
    }
    if (empty($order->delivery_zone)) {
        $order->delivery_zone = $order->billing_zone;
    }
    if (empty($order->delivery_country)) {
        $order->delivery_country = $order->billing_country;
    }
    if (is_array($order->line_items)) {
        foreach ($order->line_items as $i => $line) {
            if (substr($line['type'], 0, 4) == 'tax_' && substr($line['type'], 5) != 'subtotal') {
                unset($order->line_items[$i]);
            }
        }
    }
    $_SESSION['taxes'] = array();
    $taxes = uc_taxes_rate_load();
    foreach ($taxes as $tax) {
        // Gotta pass a fake line_item entity for the data to be saved to $_SESSION.
        workflow_ng_invoke_event('calculate_tax_' . $tax->id, $order, $tax, $account, array());
        //$order->line_items[] = array('type' => 'tax', 'amount' => $_SESSION['taxes'][$tax->id]['amount']);
    }
    $order->taxes = $_SESSION['taxes'];
    unset($_SESSION['taxes']);
    //array_unshift($order->taxes, array('id' => 'subtotal', 'name' => t('Subtotal excluding taxes'), 'amount' => $amount, 'weight' => -10));
    return $order->taxes;
}
<?php

define('DRUPAL_ROOT', dirname(__FILE__) . '/../../../../../../');
chdir(DRUPAL_ROOT);
require './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if (isset($_POST['SIGN'])) {
    $sign = strtoupper(md5(md5($_POST['SHOP_ID']) . '&' . md5($_POST["ORDER_ID"]) . '&' . md5($_POST['STATE'])));
    if ($_POST['SIGN'] == $sign) {
        switch ($_POST['STATE']) {
            case 'paid':
                $order = uc_order_load($_POST["ORDER_ID"]);
                uc_payment_enter($_POST["ORDER_ID"], 'uc_ubrir', $order->order_total, 0, NULL, $_POST["ORDER_ID"]);
                uc_cart_complete_sale($order, variable_get('uc_new_customer_login', FALSE));
                break;
        }
    }
}
Exemplo n.º 6
0
 /**
  * Handler when cart/icepay_result is callback
  *
  * @return string
  */
 public function runPageCartResult()
 {
     $logger = \Icepay_Api_Logger::getInstance();
     $logger->enableLogging()->setLoggingLevel(\Icepay_Api_Logger::LEVEL_ERRORS_AND_TRANSACTION)->logToFunction("logWrapper", "log");
     $config = \Drupal::config("uc_icepay.settings");
     /* postback */
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $icepay = \Icepay_Project_Helper::getInstance()->postback();
         $icepay->setMerchantID($config->get("merchant_id"))->setSecretCode($config->get("secret_code"))->doIPCheck(true);
         if ($config->get("ipcheck") && $config->get("ipcheck_list") != '') {
             $ipRanges = explode(",", $config->get("ipcheck_list"));
             foreach ($ipRanges as $ipRange) {
                 $ip = explode("-", $ipRange);
                 $icepay->setIPRange($ip[0], $ip[1]);
             }
         }
         if ($icepay->validate()) {
             $data = $icepay->GetPostback();
             $orderID = $data->reference;
             $order = uc_order_load($orderID);
             if (!$order) {
                 return t("Order not exists");
             }
             $firstPostback = Database::getConnection()->select('uc_payment_icepay', 'i')->fields('i', array('transaction_id'))->condition('transaction_id', $data->transactionID, '=')->execute()->fetchAssoc();
             $paymentDetails = IcepayApi::getPaymentDetailsByOrderId($orderID);
             if ($icepay->canUpdateStatus($paymentDetails->icepay_status)) {
                 $order->icepay_status = $data->status;
                 $order->transaction_id = $data->transactionID;
                 IcepayApi::enterPayment($order);
                 // updating order status, this one is deprecated
                 //uc_order_update_status($orderID, IcepayApi::getUbercartStatusCode($data->status));
                 // updating order status, using direct save into order
                 $order->setStatusId(IcepayApi::getUbercartStatusCode($data->status))->save();
             }
             // adding new comment order
             uc_order_comment_save($orderID, 1, t($data->statusCode), 'order', IcepayApi::getUbercartStatusCode($data->status), true);
             // need to save into order payment if postback from Icepay is confirming payment received
             // @see Drupal/uc_payment/Form/OrderPaymentsForm::submitForm()
             if (strtoupper($data->status) == "OK" || strtoupper($data->status) == "REFUND") {
                 $orderTotal = $order->getTotal();
                 // when refund, means order total is requested back
                 if (strtoupper($data->status) == "REFUND") {
                     $orderTotal *= -1;
                 }
                 uc_payment_enter($orderID, $paymentDetails->payment_method, $orderTotal, \Drupal::currentUser()->id(), '', $data->statusCode, REQUEST_TIME);
             }
             // best to record this into watch log
             // https://drupalize.me/blog/201510/how-log-messages-drupal-8
             \Drupal::logger('uc_icepay')->info('Icepay Postback :: ' . $data->statusCode);
             // need to send notification due to order status update
             if (isset($firstPostback['transaction_id'])) {
                 // this rules invoke to send order status update by email is deprecated
                 //rules_invoke_event('uc_order_status_email_update', $order);
             }
         } else {
             if ($icepay->isVersionCheck()) {
                 $dump = array("module" => sprintf(t("Version %s using PHP API 2 version %s"), ICEPAY_VERSION, Icepay_Project_Helper::getInstance()->getReleaseVersion()), "notice" => "Checksum validation passed!");
                 if ($icepay->validateVersion()) {
                     $name = "uc_cart";
                     $path = drupal_get_path('module', $name) . '/' . $name . '.info';
                     $data = drupal_parse_info_file($path);
                     $dump["additional"] = array("Drupal" => VERSION, "Ubercart" => $data["version"]);
                 } else {
                     $dump["notice"] = "Checksum failed! Merchant ID and Secret code probably incorrect.";
                 }
                 var_dump($dump);
                 exit;
             }
         }
         return t("Postback script functions properly");
     } else {
         $icepay = \Icepay_Project_Helper::getInstance()->result();
         $icepay->setMerchantID($config->get("merchant_id"))->setSecretCode($config->get("secret_code"));
         if (!$icepay->validate()) {
             $data = $icepay->getResultData();
             //$output = $data->statusCode;
             //return $output;
             drupal_set_message($data->statusCode, 'error');
             $response = new RedirectResponse(\Drupal::url('uc_cart.checkout'));
             $response->send();
         } else {
             $data = $icepay->getResultData();
             if ($data->status == 'ERR') {
                 //$output = $data->statusCode;
                 //return $output;
                 drupal_set_message($data->statusCode, 'error');
                 return new RedirectResponse(\Drupal::url('uc_cart.checkout'));
             }
             $order = uc_order_load($data->reference);
             if (!$order) {
                 return t("Order with id :orderId not exist", array(":orderId" => $data->reference));
             }
             $session = \Drupal::service('session');
             if (!$session->get('cart_order')) {
                 drupal_set_message(t("Cart is currently empty."), 'error');
                 return new RedirectResponse(\Drupal::url('uc_cart.checkout'));
             }
             //$order->icepay_status = \ICEPAY_STATUSCODE::SUCCESS;
             $order->icepay_status = $data->status;
             $order->transaction_id = $data->transactionID;
             IcepayApi::enterPayment($order);
             // update order status
             $order->setStatusId(IcepayApi::getUbercartStatusCode($data->status))->save();
             $_SESSION['uc_checkout'][$session->get('cart_order')]['do_complete'] = TRUE;
             //        $response = new RedirectResponse(Url::fromRoute('uc_cart.checkout_complete')->toString());
             //        $response->send();
             return new RedirectResponse(\Drupal::url('uc_cart.checkout_complete'));
         }
     }
 }
        print '<div class="block block-nodeblock"><div class="inner clearfix"><h2 class="title block-title">' . $block['subject'] . '</h2><div class="content">' . $block['content'] . '</div></div></div>';
        ?>
        </div>
    </div>

    <!-- Manage members link -->
    <?php 
        if (node_access('update', $node) && og_is_group_admin($node) && module_exists('og_manage_link') && $node->field_inscription_state[0]['value'] != InscriptionState::SUBMITTED) {
            $cnid = $node->field_contest[0]['nid'];
            $cnode = node_load($cnid);
            if (!empty($cnode) && $cnode->field_contest_state[0]['value'] == ContestState::OPEN) {
                if ($node->field_inscription_state[0]['value'] == InscriptionState::INSCRIPTED || $node->field_inscription_state[0]['value'] == InscriptionState::SUBMITTED) {
                    //Gets order to see if it is individual
                    $order_id = $node->field_inscription_order[0]['value'];
                    if (!empty($order_id)) {
                        $order = uc_order_load($order_id);
                        $product_attr = $order->products[0]->data['attributes'];
                        if (empty($product_attr)) {
                            print '<div class="info">' . t('You have made individual payment and can\'t invite other members.') . '</div>';
                        } else {
                            print theme_og_manage_link_default($node);
                        }
                    } else {
                        print theme_og_manage_link_default($node);
                    }
                } else {
                    print theme_og_manage_link_default($node);
                }
            } else {
                print '<div class="info">' . t('You can not invite members at this stage of the competition') . '</div>';
            }
function uc_ideal_payment_api_statreq_call($arg1, $arg2)
{
    $transaction_id = $_GET['trxid'];
    $order_id = $_GET['ec'];
    //echo $transaction_id;
    /*START ThinMPI code for TransrReq*/
    require_once drupal_get_path('module', 'ideal_payment_api') . "/lib/ThinMPI.php";
    require_once drupal_get_path('module', 'ideal_payment_api') . "/lib/AcquirerStatusRequest.php";
    //Create StatusRequest
    $q_data =& new AcquirerStatusRequest();
    $transID = str_pad($transaction_id, 16, "0");
    $q_data->setTransactionID($transID);
    //Create ThinMPI instance and process request
    $rule = new ThinMPI();
    $result = $rule->ProcessRequest($q_data);
    if (!$result->isOK()) {
        //StatusRequest failed, let the consumer click to try again
        $Msg = $result->getErrorMessage();
        drupal_set_message(t('We could not verify the payment status automaticaly, we will check your payment manualy, pleas contact us regarding this. IDEAL error:')) . '<br>' . $Msg;
        drupal_goto('ideal');
    } else {
        if (!$result->isAuthenticated()) {
            //Transaction failed, inform the consumer
            drupal_set_message(t('Your IDEAL payment has been canceled by you or by the IDEAL process. Please try again or go back to select another payment method.'), 'ERROR');
            if ($order_id == $_SESSION['ideal_payment_api_order_id']) {
                //Check if orer_id is valid
                // This lets us know it's a legitimate access of the review page.
                $_SESSION['do_review'] = TRUE;
                // Ensure the cart we're looking at is the one that payment was attempted for.
                $_SESSION['cart_order'] = uc_cart_get_id();
                drupal_goto('ideal/review');
            } else {
                drupal_goto('cart');
            }
        } else {
            drupal_set_message(t('Thank you for shopping with us, your payment is processed sucessfuly'));
            $transactionID = $result->getTransactionID();
            //Here you should retrieve the order from the database, mark it as "payed"
            $order = uc_order_load($order_id);
            if ($order == FALSE) {
                //Check if order exist
                watchdog('ideal_api', t('iDeal payment completion attempted for non-existent order.'), WATCHDOG_ERROR);
                return;
            }
            //uc_order_update_status($order_id, 1);   *Uitgezet 281107 KK
            uc_order_update_status($order->order_id, uc_order_state_default('post_checkout'));
            //Todo??
            //uc_payment_enter($order_id, 'ideal_payment_api', $payment_amount, $order->uid, NULL, $comment);
            //uc_cart_complete_sale($order);
            //uc_order_comment_save($order_id, 0, t('iDeal Pro reported a payment of !amount !currency.', array('!amount' => uc_currency_format($payment_amount, FALSE), '!currency' => $payment_currency)), 'admin');
            unset($_SESSION['ideal_payment_api_order_id']);
            // This lets us know it's a legitimate access of the complete page.
            $_SESSION['do_complete'] = TRUE;
            drupal_goto('ideal/complete');
            exit;
        }
    }
}
Exemplo n.º 9
0
 /**
  * Completes the sale and finishes checkout.
  */
 public function complete()
 {
     $session = \Drupal::service('session');
     if (!$session->has('cart_order') || empty($_SESSION['uc_checkout'][$session->get('cart_order')]['do_complete'])) {
         return $this->redirect('uc_cart.cart');
     }
     $order = uc_order_load($session->get('cart_order'), TRUE);
     if (empty($order)) {
         // Display messages to customers and the administrator if the order was lost.
         drupal_set_message($this->t("We're sorry.  An error occurred while processing your order that prevents us from completing it at this time. Please contact us and we will resolve the issue as soon as possible."), 'error');
         $this->logger('uc_cart')->error('An empty order made it to checkout! Cart order ID: @cart_order', ['@cart_order' => $session->get('cart_order')]);
         return $this->redirect('uc_cart.cart');
     }
     $cart_config = $this->config('uc_cart.settings');
     $build = $this->cart->completeSale($order, $cart_config->get('new_customer_login'));
     $session->remove('cart_order');
     unset($_SESSION['uc_checkout'][$order->id()]);
     // Add a comment to let sales team know this came in through the site.
     uc_order_comment_save($order->id(), 0, $this->t('Order created through website.'), 'admin');
     return $build;
 }