예제 #1
0
 /**
  * @param \Jigoshop\Entity\Order $order
  *
  * @return string
  */
 public static function getStatusAfterCompletePayment(\Jigoshop\Entity\Order $order)
 {
     if ($order->isShippingRequired()) {
         return Status::PROCESSING;
     }
     return Status::COMPLETED;
 }
예제 #2
0
 /**
  * @param Order $order Order to process payment for.
  *
  * @return string URL to redirect to.
  * @throws Exception On any payment error.
  */
 public function process($order)
 {
     $order->setStatus(Order\Status::ON_HOLD, __('Waiting for cheque to arrive.', 'jigoshop'));
     $this->orderService->save($order);
     return '';
 }
예제 #3
0
 /**
  * @param Order $order Order to process payment for.
  *
  * @return string URL to redirect to.
  * @throws Exception On any payment error.
  */
 public function process($order)
 {
     $order->setStatus(Order\Status::PROCESSING, __('Payment on delivery.', 'jigoshop'));
     $this->orderService->save($order);
     return '';
 }
예제 #4
0
 /**
  * @param Order $order Order to process payment for.
  *
  * @return bool Is processing successful?
  */
 public function process($order)
 {
     if ($this->settings['test_mode']) {
         $url = self::TEST_URL . '&';
     } else {
         $url = self::LIVE_URL . '?';
     }
     $billingAddress = $order->getCustomer()->getBillingAddress();
     if (in_array($billingAddress->getCountry(), array('US', 'CA'))) {
         $phone = str_replace(array('(', '-', ' ', ')'), '', $billingAddress->getPhone());
         $phone = array('night_phone_a' => substr($phone, 0, 3), 'night_phone_b' => substr($phone, 3, 3), 'night_phone_c' => substr($phone, 6, 4), 'day_phone_a' => substr($phone, 0, 3), 'day_phone_b' => substr($phone, 3, 3), 'day_phone_c' => substr($phone, 6, 4));
     } else {
         $phone = array('night_phone_b' => $billingAddress->getPhone(), 'day_phone_b' => $billingAddress->getPhone());
     }
     $args = array_merge(array('cmd' => '_cart', 'business' => $this->settings['test_mode'] ? $this->settings['test_email'] : $this->settings['email'], 'no_note' => 1, 'currency_code' => Currency::code(), 'charset' => 'UTF-8', 'rm' => 2, 'upload' => 1, 'return' => OrderHelper::getThankYouLink($order), 'cancel_return' => OrderHelper::getCancelLink($order), 'custom' => $order->getId(), 'notify_url' => Api::getUrl(self::ID), 'first_name' => $billingAddress->getFirstName(), 'last_name' => $billingAddress->getLastName(), 'company' => $billingAddress instanceof CompanyAddress ? $billingAddress->getCompany() : '', 'address1' => $billingAddress->getAddress(), 'address2' => '', 'city' => $billingAddress->getCity(), 'state' => $billingAddress->getState(), 'zip' => $billingAddress->getPostcode(), 'country' => $billingAddress->getCountry(), 'email' => $billingAddress->getEmail(), 'invoice' => $order->getNumber(), 'amount' => number_format($order->getTotal(), $this->options->get('general.currency_decimals')), 'bn' => 'Jigoshop_SP'), $phone);
     if ($this->settings['send_shipping']) {
         $shippingAddress = $order->getCustomer()->getShippingAddress();
         $args['no_shipping'] = 1;
         $args['address_override'] = 1;
         $args['first_name'] = $shippingAddress->getFirstName();
         $args['last_name'] = $shippingAddress->getLastName();
         $args['address1'] = $shippingAddress->getAddress();
         $args['address2'] = '';
         $args['city'] = $shippingAddress->getCity();
         $args['state'] = $shippingAddress->getState();
         $args['zip'] = $shippingAddress->getPostcode();
         $args['country'] = $shippingAddress->getCountry();
         // PayPal counts Puerto Rico as a US Territory, won't allow payment without it
         if ($args['country'] == 'PR') {
             $args['country'] = 'US';
             $args['state'] = 'PR';
         }
     } else {
         $args['no_shipping'] = 1;
         $args['address_override'] = 0;
     }
     // If prices include tax, send the whole order as a single item
     // TODO: Price includes tax
     //		$priceIncludesTax = $this->options->get('tax.included');
     //		if($priceIncludesTax){
     //			// Discount
     //			//$args['discount_amount_cart'] = number_format($order->getDiscount(), $this->decimals);
     //
     //			// Don't pass items - PayPal breaks tax due to catalog prices include tax.
     //			// PayPal has no option for tax inclusive pricing.
     //			// Pass 1 item for the order items overall
     //			$item_names = array();
     //
     //			foreach($order->items as $item){
     //				$_product = $order->get_product_from_item($item);
     //				$title = $_product->get_title();
     //
     //				//if variation, insert variation details into product title
     //				if($_product instanceof jigoshop_product_variation){
     //					$title .= ' ('.jigoshop_get_formatted_variation($_product, $item['variation'], true).')';
     //				}
     //
     //				$item_names[] = $title.' x '.$item['qty'];
     //			}
     //
     //			$args['item_name_1'] = sprintf(__('Order %s', 'jigoshop'), $order->get_order_number()).' - '.implode(', ', $item_names);
     //			$args['quantity_1'] = 1;
     //			$args['amount_1'] = number_format($order->order_total - $order->order_shipping - $order->order_shipping_tax + $order->order_discount, $this->decimals, '.', '');
     //
     //			if(($order->order_shipping + $order->order_shipping_tax) > 0){
     //				$args['item_name_2'] = __('Shipping cost', 'jigoshop');
     //				$args['quantity_2'] = '1';
     //				$args['amount_2'] = number_format($order->order_shipping + $order->order_shipping_tax, $this->decimals, '.', '');
     //			}
     //		} else {
     // Cart Contents
     $item_loop = 0;
     foreach ($order->getItems() as $item) {
         /** @var $item Order\Item */
         $item_loop++;
         $product = $item->getProduct();
         $title = $product->getName();
         //if variation, insert variation details into product title
         if ($product instanceof Product\Variable) {
             $title .= '(' . join(', ', array_filter(array_map(function ($attribute) use($item) {
                 /** @var $attribute Product\Variable\Attribute */
                 if ($attribute->getValue() !== '') {
                     $value = $attribute->getValue();
                 } else {
                     $value = $item->getMeta($attribute->getAttribute()->getSlug())->getValue();
                 }
                 return sprintf(_x('%s: %s', 'product_variation', 'jigoshop'), $attribute->getAttribute()->getLabel(), $attribute->getAttribute()->getOption($value)->getLabel());
             }, $product->getVariation($item->getMeta('variation_id')->getValue())->getAttributes()))) . ')';
         }
         $args['item_name_' . $item_loop] = $title;
         $args['quantity_' . $item_loop] = $item->getQuantity();
         // Apparently, PayPal did not like "28.4525" as the amount. Changing that to "28.45" fixed the issue.
         $args['amount_' . $item_loop] = number_format($this->wp->applyFilters('jigoshop\\paypal\\item_price', $item->getPrice(), $item), $this->decimals);
     }
     // Shipping Cost
     if ($this->options->get('shipping.enabled') && $order->getShippingPrice() > 0) {
         $item_loop++;
         $args['item_name_' . $item_loop] = __('Shipping cost', 'jigoshop');
         $args['quantity_' . $item_loop] = '1';
         $args['amount_' . $item_loop] = number_format($order->getShippingPrice(), $this->decimals);
     }
     $args['tax'] = $args['tax_cart'] = number_format($order->getTotalCombinedTax(), $this->decimals);
     $args['discount_amount_cart'] = number_format($order->getDiscount(), $this->decimals);
     if ($this->settings['force_payment'] && $order->getTotal() == 0) {
         $item_loop++;
         $args['item_name_' . $item_loop] = __('Force payment on free orders', 'jigoshop');
         $args['quantity_' . $item_loop] = '1';
         $args['amount_' . $item_loop] = 0.01;
     }
     //		}
     $args = $this->wp->applyFilters('jigoshop\\paypal\\args', $args);
     $order->setStatus(Order\Status::PENDING, __('Waiting for PayPal payment.', 'jigoshop'));
     return $url . http_build_query($args);
 }
예제 #5
0
 /**
  * @param Order $order Order to process payment for.
  *
  * @return string URL to redirect to.
  * @throws Exception On any payment error.
  */
 public function process($order)
 {
     $order->setStatus(Order\Status::ON_HOLD, __('Waiting for the confirmation of the bank transfer.', 'jigoshop'));
     $this->orderService->save($order);
     return '';
 }
예제 #6
0
 public function fromCart(\Jigoshop\Entity\Cart $cart)
 {
     $order = new \Jigoshop\Entity\Order($this->options->get('tax.classes'));
     $state = $cart->getStateToSave();
     $state['items'] = unserialize($state['items']);
     $state['customer'] = unserialize($state['customer']);
     unset($state['shipping'], $state['payment']);
     $order->setTaxDefinitions($cart->getTaxDefinitions());
     $order->restoreState($state);
     $shipping = $cart->getShippingMethod();
     if ($shipping && $shipping instanceof ShippingMethod) {
         $order->setShippingMethod($shipping);
         $order->setShippingTax($cart->getShippingTax());
     }
     $payment = $cart->getPaymentMethod();
     if ($payment && $payment instanceof PaymentMethod) {
         $order->setPaymentMethod($payment);
     }
     return $order;
 }
예제 #7
0
파일: Cart.php 프로젝트: jigoshop/Jigoshop2
 public function getStateToSave()
 {
     $state = parent::getStateToSave();
     $state['items'] = serialize($state['items']);
     unset($state['update_messages'], $state['updated_at'], $state['completed_at'], $state['total'], $state['subtotal']);
     return $state;
 }
예제 #8
0
 /**
  * @param OrderEntity $order
  *
  * @return array
  */
 public static function getBasicData($order)
 {
     $data = array('id' => $order->getId(), 'created_at' => array('timestamp' => $order->getCreatedAt()->getTimestamp(), 'date' => $order->getCreatedAt()->format('Y-m-d')), 'number' => $order->getNumber(), 'status' => $order->getStatus(), 'customer' => array(), 'customers_note' => $order->getCustomerNote(), 'items' => array_values(array_map(function ($item) {
         /** @var OrderEntity\Item $item */
         return array('id' => $item->getId(), 'type' => $item->getType(), 'key' => $item->getKey(), 'name' => $item->getName(), 'product_id' => $item->getProductId(), 'meta' => array_values(array_map(function ($meta) {
             /** @var OrderEntity\Item\Meta $meta */
             return array('key' => $meta->getKey(), 'value' => $meta->getValue());
         }, $item->getAllMeta())), 'price' => $item->getPrice(), 'quantity' => $item->getQuantity(), 'tax' => $item->getTax(), 'tax_classes' => $item->getTaxClasses(), 'cost' => $item->getCost());
     }, $order->getItems())), 'products_subtotal' => $order->getProductSubtotal(), 'shipping_price' => array('method' => array('id' => $order->getShippingMethod()->getId(), 'title' => $order->getShippingMethod()->getTitle()), 'tax' => $order->getShippingTax(), 'price' => $order->getShippingPrice()), 'subtotal' => $order->getSubtotal(), 'tax' => $order->getTax(), 'total' => $order->getTotal());
     if ($order->getShippingMethod() instanceof MultipleMethod) {
         $rates = $order->getShippingMethod()->getRates($order);
         $rateId = $order->getShippingMethod()->getShippingRate();
         /** @var Rate $rate */
         $rate = isset($rates[$rateId]) ? $rates[$rateId] : null;
         if ($rate) {
             $data['shipping_price']['method']['rate'] = array('id' => $rate->getId(), 'title' => $rate->getName());
         }
     }
     return $data;
 }