Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 /**
  * @param $result string Current email message.
  * @param $item   Order\Item Item to display.
  * @param $order  Order Order being displayed.
  *
  * @return string
  */
 public function emailLink($result, $item, $order)
 {
     $product = $item->getProduct();
     if ($product instanceof Product\Downloadable && in_array($order->getStatus(), array(Order\Status::COMPLETED, Order\Status::PROCESSING))) {
         $url = $this->wp->getHelpers()->addQueryArg(array('file' => $order->getKey() . '.' . $order->getId() . '.' . $item->getKey(), Api::getUrl(DownloadFile::NAME)));
         $result .= PHP_EOL . __('Your download link for this file is:', 'jigoshop');
         $result .= PHP_EOL . ' - ' . $url;
     }
     return $result;
 }