コード例 #1
0
 public function storePendingOrder()
 {
     $orderInfo = array();
     $orderInfo['bill_address'] = '';
     $orderInfo['coupon'] = Cart66Common::getPromoMessage();
     $orderInfo['shipping'] = Cart66Session::get('Cart66Cart')->getShippingCost();
     $orderInfo['trans_id'] = '';
     $orderInfo['status'] = 'checkout_pending';
     $orderInfo['ordered_on'] = date('Y-m-d H:i:s', Cart66Common::localTs());
     $orderInfo['shipping_method'] = Cart66Session::get('Cart66Cart')->getShippingMethodName();
     $orderInfo['account_id'] = 0;
     $orderId = Cart66Session::get('Cart66Cart')->storeOrder($orderInfo);
     return $orderId;
 }
コード例 #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());
     }
 }
コード例 #3
0
 /**
  * Store order in database after successful transaction is processed
  */
 public function saveOrder($total, $tax, $transId, $status, $accountId = 0)
 {
     $address = $this->getShipping();
     $b = $this->getBilling();
     $p = $this->getPayment();
     $orderInfo['ship_first_name'] = $address['firstName'];
     $orderInfo['ship_last_name'] = $address['lastName'];
     $orderInfo['ship_address'] = $address['address'];
     $orderInfo['ship_address2'] = $address['address2'];
     $orderInfo['ship_city'] = $address['city'];
     $orderInfo['ship_state'] = $address['state'];
     $orderInfo['ship_zip'] = $address['zip'];
     $orderInfo['ship_country'] = Cart66Common::getCountryName($address['country']);
     $orderInfo['bill_first_name'] = $b['firstName'];
     $orderInfo['bill_last_name'] = $b['lastName'];
     $orderInfo['bill_address'] = $b['address'];
     $orderInfo['bill_address2'] = $b['address2'];
     $orderInfo['bill_city'] = $b['city'];
     $orderInfo['bill_state'] = $b['state'];
     $orderInfo['bill_zip'] = $b['zip'];
     $orderInfo['bill_country'] = Cart66Common::getCountryName($b['country']);
     $orderInfo['phone'] = preg_replace("/[^0-9]/", "", $p['phone']);
     $orderInfo['email'] = $p['email'];
     $orderInfo['custom_field'] = isset($p['custom-field']) ? $p['custom-field'] : '';
     $orderInfo['coupon'] = Cart66Common::getPromoMessage();
     $orderInfo['tax'] = $tax;
     $orderInfo['shipping'] = Cart66Session::get('Cart66Cart')->getShippingCost();
     $orderInfo['subtotal'] = Cart66Session::get('Cart66Cart')->getSubTotal();
     $orderInfo['total'] = preg_replace("/[^0-9\\.]/", "", $total);
     $orderInfo['trans_id'] = $transId;
     $orderInfo['status'] = $status;
     $orderInfo['ordered_on'] = date('Y-m-d H:i:s', Cart66Common::localTs());
     $orderInfo['shipping_method'] = Cart66Session::get('Cart66Cart')->getShippingMethodName();
     $orderInfo['account_id'] = $accountId;
     $additional_fields = array();
     $custom_payment_fields = apply_filters('cart66_after_payment_form', '');
     if (is_array($custom_payment_fields)) {
         foreach ($custom_payment_fields as $key => $payment_field) {
             if (isset($p[$payment_field['slug']])) {
                 $additional_fields[$payment_field['section']][$payment_field['slug']] = array('label' => $payment_field['label'], 'value' => $p[$payment_field['slug']]);
             }
         }
     }
     $custom_billing_fields = apply_filters('cart66_after_billing_form', '');
     if (is_array($custom_billing_fields)) {
         foreach ($custom_billing_fields as $key => $billing_field) {
             if (isset($b[$billing_field['slug']])) {
                 $additional_fields[$billing_field['section']][$billing_field['slug']] = array('label' => $billing_field['label'], 'value' => $b[$billing_field['slug']]);
             }
         }
     }
     $custom_shipping_fields = apply_filters('cart66_after_shipping_form', '');
     if (is_array($custom_shipping_fields)) {
         foreach ($custom_shipping_fields as $key => $shipping_field) {
             if (isset($address[$shipping_field['slug']])) {
                 $additional_fields[$shipping_field['section']][$shipping_field['slug']] = array('label' => $shipping_field['label'], 'value' => $address[$shipping_field['slug']]);
             }
         }
     }
     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] additional fields: " . print_r($additional_fields, true));
     if (!empty($additional_fields)) {
         $orderInfo['additional_fields'] = serialize($additional_fields);
     }
     $orderInfo = Cart66Common::deNullArrayValues($orderInfo);
     $orderId = Cart66Session::get('Cart66Cart')->storeOrder($orderInfo);
     return $orderId;
 }
コード例 #4
0
 public function storePendingOrder()
 {
     $orderInfo = array();
     $orderInfo['bill_address'] = '';
     $orderInfo['coupon'] = Cart66Common::getPromoMessage();
     $orderInfo['shipping'] = Cart66Session::get('Cart66Cart')->getShippingCost();
     $orderInfo['trans_id'] = '';
     $orderInfo['status'] = 'checkout_pending';
     $orderInfo['ordered_on'] = date('Y-m-d H:i:s', Cart66Common::localTs());
     $orderInfo['shipping_method'] = Cart66Session::get('Cart66Cart')->getShippingMethodName();
     $orderInfo['account_id'] = 0;
     $orderInfo['total'] = Cart66Session::get('Cart66Cart')->getGrandTotal() + Cart66Session::get('Cart66Tax');
     $orderInfo['tax'] = Cart66Session::get('Cart66Tax');
     $orderInfo['ship_first_name'] = $this->_shipping['firstName'];
     $orderInfo['ship_last_name'] = $this->_shipping['lastName'];
     $orderInfo['ship_address'] = $this->_shipping['address'];
     $orderInfo['ship_address2'] = $this->_shipping['address2'];
     $orderInfo['ship_city'] = $this->_shipping['city'];
     $orderInfo['ship_state'] = $this->_shipping['state'];
     $orderInfo['ship_zip'] = $this->_shipping['zip'];
     $orderInfo['ship_country'] = $this->_shipping['country'];
     $orderId = Cart66Session::get('Cart66Cart')->storeOrder($orderInfo);
     return $orderId;
 }