Beispiel #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;
 }
 /**
  * Hack: separate tax for each product in $order object
  * HACK START
  */
 function uc_dibsflex_recalculate_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 = $this->uc_dibsflex_action_apply_tax($order, $tax);
             if ($line_item) {
                 $order->taxes[$line_item->id] = $line_item;
             }
         }
     }
     return $order->taxes;
 }
/**
 * Calculates 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_uc_calculate_tax($order)
{
    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;
    }
    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;
                }
            }
        }
        $set = rules_config_load('uc_taxes_' . $tax->id);
        if ($set->execute($order)) {
            $line_item = uc_taxes_apply_tax($order, $tax);
            if ($line_item) {
                $order->taxes[$line_item->id] = $line_item;
            }
        }
    }
    return $order->taxes;
}