예제 #1
0
 public function render()
 {
     $content = $this->wp->getPostField('post_content', $this->options->getPageId(Pages::THANK_YOU));
     /** @var Order $order */
     $order = $this->orderService->find((int) $_REQUEST['order']);
     if ($order->getKey() != $_REQUEST['key']) {
         $this->messages->addError(__('Invalid security key. The order was processed.', 'jigoshop'));
         $this->wp->redirectTo($this->options->getPageId(Pages::SHOP));
     }
     return Render::get('shop/checkout/thanks', array('content' => $content, 'messages' => $this->messages, 'order' => $order, 'showWithTax' => $this->options->get('tax.price_tax') == 'with_tax', 'shopUrl' => $this->wp->getPermalink($this->options->getPageId(Pages::SHOP)), 'cancelUrl' => \Jigoshop\Helper\Order::getCancelLink($order), 'getTaxLabel' => function ($taxClass) use($order) {
         return Tax::getLabel($taxClass, $order);
     }));
 }
예제 #2
0
 /**
  * Executes actions associated with selected page.
  */
 public function action()
 {
     $cart = $this->cartService->getCurrent();
     if ($cart->isEmpty()) {
         $this->messages->addWarning(__('Your cart is empty, please add products before proceeding.', 'jigoshop'));
         $this->wp->redirectTo($this->options->getPageId(Pages::SHOP));
     }
     if (!$this->isAllowedToEnterCheckout()) {
         $this->messages->addError(__('You need to log in before processing to checkout.', 'jigoshop'));
         $this->wp->redirectTo($this->options->getPageId(Pages::CART));
     }
     if (isset($_POST['action']) && $_POST['action'] == 'purchase') {
         try {
             $allowRegistration = $this->options->get('shopping.allow_registration');
             if ($allowRegistration && !$this->wp->isUserLoggedIn()) {
                 $this->createUserAccount();
             }
             if (!$this->isAllowedToCheckout($cart)) {
                 if ($allowRegistration) {
                     throw new Exception(__('You need either to log in or create account to purchase.', 'jigoshop'));
                 }
                 throw new Exception(__('You need to log in before purchasing.', 'jigoshop'));
             }
             if ($this->options->get('advanced.pages.terms') > 0 && (!isset($_POST['terms']) || $_POST['terms'] != 'on')) {
                 throw new Exception(__('You need to accept terms & conditions!', 'jigoshop'));
             }
             $this->cartService->validate($cart);
             $this->customerService->save($cart->getCustomer());
             if (!Country::isAllowed($cart->getCustomer()->getBillingAddress()->getCountry())) {
                 $locations = array_map(function ($location) {
                     return Country::getName($location);
                 }, $this->options->get('shopping.selling_locations'));
                 throw new Exception(sprintf(__('This location is not supported, we sell only to %s.'), join(', ', $locations)));
             }
             $shipping = $cart->getShippingMethod();
             if ($this->isShippingRequired($cart) && (!$shipping || !$shipping->isEnabled())) {
                 throw new Exception(__('Shipping is required for this order. Please select shipping method.', 'jigoshop'));
             }
             $payment = $cart->getPaymentMethod();
             $isPaymentRequired = $this->isPaymentRequired($cart);
             $this->wp->doAction('jigoshop\\checkout\\payment', $payment);
             if ($isPaymentRequired && (!$payment || !$payment->isEnabled())) {
                 throw new Exception(__('Payment is required for this order. Please select payment method.', 'jigoshop'));
             }
             $order = $this->orderService->createFromCart($cart);
             /** @var Order $order */
             $order = $this->wp->applyFilters('jigoshop\\checkout\\order', $order);
             $this->orderService->save($order);
             $this->cartService->remove($cart);
             $url = '';
             if ($isPaymentRequired) {
                 $url = $payment->process($order);
             } else {
                 $order->setStatus(\Jigoshop\Helper\Order::getStatusAfterCompletePayment($order));
                 $this->orderService->save($order);
             }
             // Redirect to thank you page
             if (empty($url)) {
                 $url = $this->wp->getPermalink($this->wp->applyFilters('jigoshop\\checkout\\redirect_page_id', $this->options->getPageId(Pages::THANK_YOU)));
                 $url = $this->wp->getHelpers()->addQueryArg(array('order' => $order->getId(), 'key' => $order->getKey()), $url);
             }
             $this->wp->wpRedirect($url);
             exit;
         } catch (Exception $e) {
             $this->messages->addError($e->getMessage());
         }
     }
 }
예제 #3
0
 /**
  * Change order status.
  */
 public function ajaxChangeStatus()
 {
     try {
         $status = trim($_POST['status']);
         if (empty($status)) {
             throw new \Exception('Empty status');
         }
         $orderId = (int) $_POST['orderId'];
         if ($orderId < 1) {
             throw new \Exception('Bad order id');
         }
         /** @var Entity $order */
         $order = $this->orderService->find($orderId);
         if ($this->isAvailbleChange($order->getStatus(), $status)) {
             $order->setStatus($status);
             $this->orderService->save($order);
             ob_start();
             OrderHelper::renderStatus($order);
             $html = ob_get_clean();
             echo json_encode(array('success' => true, 'html' => $html));
         } else {
             throw new \Exception('Not possible');
         }
     } catch (\Exception $e) {
         echo json_encode(array('status' => false, 'error' => $e->getMessage()));
     }
     exit;
 }
예제 #4
0
 public function processResponse()
 {
     if ($this->isResponseValid()) {
         $posted = $this->wp->getHelpers()->stripSlashesDeep($_POST);
         // 'custom' holds post ID (Order ID)
         if (!empty($posted['custom']) && !empty($posted['txn_type']) && !empty($posted['invoice'])) {
             $accepted_types = array('cart', 'instant', 'express_checkout', 'web_accept', 'masspay', 'send_money', 'subscr_payment');
             /** @var \Jigoshop\Service\OrderService $service */
             $service = $this->di->get('jigoshop.service.order');
             $order = $service->find((int) $posted['custom']);
             // Sandbox fix
             if (isset($posted['test_ipn']) && $posted['test_ipn'] == 1 && strtolower($posted['payment_status']) == 'pending') {
                 $posted['payment_status'] = 'completed';
             }
             $merchant = $this->settings['test_mode'] ? $this->settings['test_email'] : $this->settings['email'];
             if ($order->getStatus() !== Order\Status::COMPLETED) {
                 // We are here so lets check status and do actions
                 switch (strtolower($posted['payment_status'])) {
                     case 'completed':
                         if (!in_array(strtolower($posted['txn_type']), $accepted_types)) {
                             // Put this order on-hold for manual checking
                             $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Unknown "txn_type" of "%s" for Order ID: %s.', 'jigoshop'), $posted['txn_type'], $posted['custom']));
                             break;
                         }
                         if ($order->getNumber() !== $posted['invoice']) {
                             // Put this order on-hold for manual checking
                             $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Order Invoice Number does NOT match PayPal posted invoice (%s) for Order ID: .', 'jigoshop'), $posted['invoice'], $posted['custom']));
                             $service->save($order);
                             exit;
                         }
                         // Validate Amount
                         if (number_format($order->getTotal(), $this->decimals, '.', '') != $posted['mc_gross']) {
                             // Put this order on-hold for manual checking
                             $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Payment amounts do not match initial order (gross %s).', 'jigoshop'), $posted['mc_gross']));
                             $service->save($order);
                             exit;
                         }
                         if (strcasecmp(trim($posted['business']), trim($merchant)) != 0) {
                             // Put this order on-hold for manual checking
                             $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Payment Merchant email received does not match PayPal Gateway settings. (%s)', 'jigoshop'), $posted['business']));
                             $service->save($order);
                             exit;
                         }
                         if ($posted['mc_currency'] != $this->options->get('general.currency')) {
                             // Put this order on-hold for manual checking
                             $order->setStatus(Order\Status::ON_HOLD, sprintf(__('PayPal Validation Error: Payment currency received (%s) does not match Shop currency.', 'jigoshop'), $posted['mc_currency']));
                             $service->save($order);
                             exit;
                         }
                         $order->setStatus(OrderHelper::getStatusAfterCompletePayment($order), __('PayPal payment completed', 'jigoshop'));
                         break;
                     case 'denied':
                     case 'expired':
                     case 'failed':
                     case 'voided':
                         // Failed order
                         $order->setStatus(Order\Status::ON_HOLD, sprintf(__('Payment %s via PayPal.', 'jigoshop'), strtolower($posted['payment_status'])));
                         break;
                     case 'refunded':
                     case 'reversed':
                     case 'chargeback':
                         // TODO: Implement refunds
                         break;
                     default:
                         // No action
                         break;
                 }
                 $service->save($order);
             }
         }
     }
 }
예제 #5
0
$product = $item->getProduct();
$variation = $product->getVariation($item->getMeta('variation_id')->getValue());
$url = apply_filters('jigoshop\\cart\\product_url', get_permalink($product->getId()), $key);
// TODO: Support for "Prices includes tax"
$price = $showWithTax ? $item->getPrice() + $item->getTax() / $item->getQuantity() : $item->getPrice();
?>
<tr data-id="<?php 
echo $key;
?>
" data-product="<?php 
echo $product->getId();
?>
">
	<td class="product-remove">
		<a href="<?php 
echo Order::getRemoveLink($key);
?>
" class="remove" title="<?php 
echo __('Remove', 'jigoshop');
?>
">&times;</a>
	</td>
	<td class="product-thumbnail"><a href="<?php 
echo $url;
?>
"><?php 
echo Product::getFeaturedImage($product, 'shop_tiny');
?>
</a></td>
	<td class="product-name">
		<a href="<?php 
예제 #6
0
    }, 0);
    ?>
		<li>
			<a href="<?php 
    echo get_edit_post_link($order->getId());
    ?>
">#<?php 
    echo $order->getNumber();
    ?>
</a>
			<span class="order-customer"><?php 
    echo $order->getCustomer()->getName();
    ?>
</span>
			<?php 
    echo Helper\Order::getStatus($order);
    ?>
			<span class="order-time"><?php 
    echo get_the_time(_x('M d, Y', 'dashboard', 'jigoshop'), $order->getId());
    ?>
</span>
			<small>
				<?php 
    echo count($order->getItems());
    ?>
 <?php 
    echo _n('Item', 'Items', count($order->getItems()), 'jigoshop');
    ?>
,
				<span	class="total-quantity"><?php 
    echo __('Total Quantity', 'jigoshop');
예제 #7
0
 /**
  * @param $order Order The order.
  *
  * @return array Available arguments with proper values.
  */
 private function getOrderEmailArguments($order)
 {
     $billingAddress = $order->getCustomer()->getBillingAddress();
     $shippingAddress = $order->getCustomer()->getShippingAddress();
     return $this->wp->applyFilters('jigoshop\\emails\\order_variables', array('blog_name' => $this->wp->getBloginfo('name'), 'order_number' => $order->getNumber(), 'order_date' => $this->wp->getHelpers()->dateI18n($this->wp->getOption('date_format')), 'shop_name' => $this->options->get('general.company_name'), 'shop_address_1' => $this->options->get('general.company_address_1'), 'shop_address_2' => $this->options->get('general.company_address_2'), 'shop_tax_number' => $this->options->get('general.company_tax_number'), 'shop_phone' => $this->options->get('general.company_phone'), 'shop_email' => $this->options->get('general.company_email'), 'customer_note' => $order->getCustomerNote(), 'order_items' => $this->formatItems($order), 'subtotal' => ProductHelper::formatPrice($order->getSubtotal()), 'shipping' => ProductHelper::formatPrice($order->getShippingPrice()), 'shipping_cost' => ProductHelper::formatPrice($order->getShippingPrice()), 'shipping_cost_raw' => $order->getShippingPrice(), 'shipping_method' => $order->getShippingMethod() ? $order->getShippingMethod()->getName() : '', 'discount' => ProductHelper::formatPrice($order->getDiscount()), 'total_tax' => ProductHelper::formatPrice($order->getTotalTax()), 'total' => ProductHelper::formatPrice($order->getTotal()), 'is_local_pickup' => $order->getShippingMethod() && $order->getShippingMethod()->getId() == LocalPickup::NAME ? true : null, 'checkout_url' => $order->getStatus() == Order\Status::PENDING ? OrderHelper::getPayLink($order) : null, 'payment_method' => $order->getPaymentMethod()->getName(), 'billing_first_name' => $billingAddress->getFirstName(), 'billing_last_name' => $billingAddress->getLastName(), 'billing_company' => $billingAddress instanceof CompanyAddress ? $billingAddress->getCompany() : '', 'billing_address_1' => $billingAddress->getAddress(), 'billing_address_2' => '', 'billing_postcode' => $billingAddress->getPostcode(), 'billing_city' => $billingAddress->getCity(), 'billing_country' => Country::getName($billingAddress->getCountry()), 'billing_country_raw' => $billingAddress->getCountry(), 'billing_state' => Country::hasStates($billingAddress->getCountry()) ? Country::getStateName($billingAddress->getCountry(), $billingAddress->getState()) : $billingAddress->getState(), 'billing_state_raw' => $billingAddress->getState(), 'billing_email' => $billingAddress->getEmail(), 'billing_phone' => $billingAddress->getPhone(), 'shipping_first_name' => $shippingAddress->getFirstName(), 'shipping_last_name' => $shippingAddress->getLastName(), 'shipping_company' => $shippingAddress instanceof CompanyAddress ? $shippingAddress->getCompany() : '', 'shipping_address_1' => $shippingAddress->getAddress(), 'shipping_address_2' => '', 'shipping_postcode' => $shippingAddress->getPostcode(), 'shipping_city' => $shippingAddress->getCity(), 'shipping_country' => Country::getName($shippingAddress->getCountry()), 'shipping_country_raw' => $shippingAddress->getCountry(), 'shipping_state' => Country::hasStates($shippingAddress->getCountry()) ? Country::getStateName($shippingAddress->getCountry(), $shippingAddress->getState()) : $shippingAddress->getState(), 'shipping_state_raw' => $shippingAddress->getState()), $order);
 }
예제 #8
0
</dt>
					<dd><?php 
    echo Status::getName($order->getStatus());
    ?>
</dd>
					<dt><?php 
    _e('Total', 'jigoshop');
    ?>
</dt>
					<dd><?php 
    echo Product::formatPrice($order->getTotal());
    ?>
</dd>
				</dl>
				<a href="<?php 
    echo Order::getPayLink($order);
    ?>
" class="btn btn-success pull-right"><?php 
    _e('Pay', 'jigoshop');
    ?>
</a>
			</li>
			<?php 
}
?>
			<li class="list-group-item">
				<a href="<?php 
echo $myOrdersUrl;
?>
" class="btn btn-default"><?php 
_e('See more...', 'jigoshop');