コード例 #1
0
    // Apply CSS class for subscription products
    if (Cart66Session::get('Cart66Cart')->hasSubscriptionProducts() || Cart66Session::get('Cart66Cart')->hasMembershipProducts()) {
        echo ' subscription';
    }
    ?>
">
      <input type="hidden" class="ajax-tax-cart" name="ajax-tax-cart" value="<?php 
    echo Cart66Session::get('Cart66Cart')->hasTaxableProducts() ? 'true' : 'false';
    ?>
" />
      <input type="hidden" name="cart66-gateway-name" value="<?php 
    echo $gatewayName;
    ?>
" id="cart66-gateway-name" />
      <?php 
    $url = Cart66Common::appendWurlQueryString('cart66AjaxCartRequests');
    if (Cart66Common::isHttps()) {
        $url = preg_replace('/http[s]*:/', 'https:', $url);
    } else {
        $url = preg_replace('/http[s]*:/', 'http:', $url);
    }
    ?>
      <input type="hidden" name="confirm_url" value="<?php 
    echo $url;
    ?>
" id="confirm-url" />
      <?php 
    if ($cart->requireShipping()) {
        ?>
        <h2><?php 
        _e('Shipping Address', 'cart66');
コード例 #2
0
 public function initCheckout($amount)
 {
     $cart = Cart66Session::get('Cart66Cart');
     $tax = $this->getTaxAmount();
     $order = array('return_url' => Cart66Common::appendWurlQueryString('task=mijireh_notification'), 'tax' => $tax, 'shipping' => $cart->getShippingCost(), 'discount' => $cart->getDiscountAmount(), 'subtotal' => $cart->getSubTotal(), 'total' => number_format($cart->getGrandTotal() + $tax, 2, '.', ''), 'items' => array());
     // Prepare the shipping address if it is available
     if (strlen($this->_shipping['address']) > 3) {
         $order['shipping_address'] = array('first_name' => $this->_shipping['firstName'], 'last_name' => $this->_shipping['lastName'], 'street' => $this->_shipping['address'], 'apt_suite' => $this->_shipping['address2'], 'city' => $this->_shipping['city'], 'state_province' => $this->_shipping['state'], 'zip_code' => $this->_shipping['zip'], 'country' => $this->_shipping['country'], 'phone' => $this->_payment['phone']);
     }
     // Add shipping method and promotion code as meta_data
     $order['meta_data'] = array('shipping_method' => Cart66Session::get('Cart66Cart')->getShippingMethodName(), 'coupon' => Cart66Common::getPromoMessage(), 'custom-field' => $this->_payment['custom-field']);
     // Add logged in users id to the meta_data for membership product upgrades/extensions
     $account_id = Cart66Common::isLoggedIn();
     if ($account_id) {
         $order['meta_data']['account_id'] = $account_id;
     }
     // Add coupon code as meta_data
     foreach ($cart->getItems() as $key => $item) {
         $sku = $item->getItemNumber();
         $order_item_data = array('sku' => $sku, 'name' => $item->getFullDisplayName(), 'price' => $item->getProductPrice(), 'quantity' => $item->getQuantity());
         if ($custom_desc = $item->getCustomFieldDesc()) {
             $order_item_data['name'] .= "\n" . $custom_desc;
         }
         if ($custom_info = $item->getCustomFieldInfo()) {
             $order_item_data['name'] .= "\n" . $custom_info;
         }
         $order['items'][$key] = $order_item_data;
         $option_info = trim($item->getOptionInfo());
         if (!empty($option_info)) {
             $order['meta_data']['options_' . $sku] = $option_info;
         }
         if ($item->hasAttachedForms()) {
             $form_ids = $item->getFormEntryIds();
             if (is_array($form_ids) && count($form_ids)) {
                 $form_ids = implode(',', $form_ids);
                 $order['meta_data'][$key]['gforms_' . $sku] = $form_ids;
             }
         }
     }
     // DBG
     /*
     echo "<pre>";
     print_r($order);
     echo "</pre>";
     die();
     */
     try {
         //Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Sending Order To Mijireh" . print_r($order, true));
         $access_key = Cart66Setting::getValue('mijireh_access_key');
         $rest = new PestJSON(MIJIREH_CHECKOUT);
         $rest->setupAuth($access_key, '');
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Sending Order To Mijireh: " . print_r($order, true));
         $result = $rest->post('/api/1/orders', $order);
         wp_redirect($result['checkout_url']);
         //wp_redirect(MIJIREH_CHECKOUT .  '/checkout/' . $result['order_number']);
         exit;
     } catch (Pest_Unauthorized $e) {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] REST Request Failed because it was unauthorized: " . $e->getMessage());
         $this->response['error_message'] = __("Your Mijireh Access key is invalid, please check your access settings and try again", "cart66");
         $this->response['error_code'] = 1;
         if (strlen($this->_shipping['address']) < 3) {
             $gatewayResponse = $this->getTransactionResponseDescription();
             $exception = Cart66Exception::exceptionMessages(66500, __('Your order could not be processed for the following reasons:', 'cart66'), array('error_code' => 'Error: ' . $gatewayResponse['errorcode'], strtolower($gatewayResponse['errormessage'])));
             echo Cart66Common::getView('views/error-messages.php', $exception);
         }
     } catch (Exception $e) {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] REST Request Failed: " . $e->getMessage());
     }
 }