示例#1
0
文件: Payone.php 项目: Aziz-JH/core
 /**
  * HTML form for checkout
  * @param   IsotopeProductCollection    The order being places
  * @param   Module                      The checkout module instance
  * @return  mixed
  */
 public function checkoutForm(IsotopeProductCollection $objOrder, \Module $objModule)
 {
     $i = 0;
     $arrData = array('aid' => $this->payone_aid, 'portalid' => $this->payone_portalid, 'mode' => $this->debug ? 'test' : 'live', 'request' => $this->trans_type == 'auth' ? 'preauthorization' : 'authorization', 'encoding' => 'UTF-8', 'clearingtype' => $this->payone_clearingtype, 'reference' => $objOrder->id, 'display_name' => 'no', 'display_address' => 'no', 'successurl' => \Environment::get('base') . $objModule->generateUrlForStep('complete', $objOrder), 'backurl' => \Environment::get('base') . $objModule->generateUrlForStep('failed'), 'amount' => $objOrder->getTotal() * 100, 'currency' => $objOrder->currency, 'param' => 'paymentMethodPayone' . $this->id);
     foreach ($objOrder->getItems() as $objItem) {
         // Set the active product for insert tags replacement
         if ($objItem->hasProduct()) {
             Product::setActive($objItem->getProduct());
         }
         $strOptions = '';
         $arrOptions = Isotope::formatOptions($objItem->getOptions());
         Product::unsetActive();
         if (!empty($arrOptions)) {
             array_walk($arrOptions, function (&$option) {
                 $option = $option['label'] . ': ' . $option['value'];
             });
             $strOptions = ' (' . implode(', ', $arrOptions) . ')';
         }
         $arrData['id[' . ++$i . ']'] = $objItem->getSku();
         $arrData['pr[' . $i . ']'] = round($objItem->getPrice(), 2) * 100;
         $arrData['no[' . $i . ']'] = $objItem->quantity;
         $arrData['de[' . $i . ']'] = specialchars($objItem->getName() . $strOptions);
     }
     foreach ($objOrder->getSurcharges() as $k => $objSurcharge) {
         if (!$objSurcharge->addToTotal) {
             continue;
         }
         $arrData['id[' . ++$i . ']'] = 'surcharge' . $k;
         $arrData['pr[' . $i . ']'] = $objSurcharge->total_price * 100;
         $arrData['no[' . $i . ']'] = '1';
         $arrData['de[' . $i . ']'] = $objSurcharge->label;
     }
     ksort($arrData);
     // Do not urlencode values because Payone does not properly decode POST values (whatever...)
     $strHash = md5(implode('', $arrData) . $this->payone_key);
     $objTemplate = new \Isotope\Template('iso_payment_payone');
     $objTemplate->id = $this->id;
     $objTemplate->data = $arrData;
     $objTemplate->hash = $strHash;
     $objTemplate->billing_address = $objOrder->getBillingAddress()->row();
     $objTemplate->headline = $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][0];
     $objTemplate->message = $GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][1];
     $objTemplate->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][2]);
     return $objTemplate->parse();
 }
示例#2
0
 /**
  * Return the PayPal form.
  *
  * @param IsotopeProductCollection|Order $objOrder  The order being places
  * @param \Module|Checkout               $objModule The checkout module instance
  *
  * @return  string
  */
 public function checkoutForm(IsotopeProductCollection $objOrder, \Module $objModule)
 {
     $arrData = array();
     $fltDiscount = 0;
     $i = 0;
     foreach ($objOrder->getItems() as $objItem) {
         // Set the active product for insert tags replacement
         if ($objItem->hasProduct()) {
             Product::setActive($objItem->getProduct());
         }
         $strConfig = '';
         $arrConfig = $objItem->getConfiguration();
         if (!empty($arrConfig)) {
             array_walk($arrConfig, function (&$option) {
                 $option = $option['label'] . ': ' . (string) $option;
             });
             $strConfig = ' (' . implode(', ', $arrConfig) . ')';
         }
         $arrData['item_number_' . ++$i] = $objItem->getSku();
         $arrData['item_name_' . $i] = \StringUtil::restoreBasicEntities($objItem->getName() . $strConfig);
         $arrData['amount_' . $i] = $objItem->getPrice();
         $arrData['quantity_' . $i] = $objItem->quantity;
     }
     foreach ($objOrder->getSurcharges() as $objSurcharge) {
         if (!$objSurcharge->addToTotal) {
             continue;
         }
         // PayPal does only support one single discount item
         if ($objSurcharge->total_price < 0) {
             $fltDiscount -= $objSurcharge->total_price;
             continue;
         }
         $arrData['item_name_' . ++$i] = $objSurcharge->label;
         $arrData['amount_' . $i] = $objSurcharge->total_price;
     }
     $objTemplate = new \Isotope\Template('iso_payment_paypal');
     $objTemplate->setData($this->arrData);
     $objTemplate->id = $this->id;
     $objTemplate->action = 'https://www.' . ($this->debug ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr';
     $objTemplate->invoice = $objOrder->id;
     $objTemplate->data = array_map('specialchars', $arrData);
     $objTemplate->discount = $fltDiscount;
     $objTemplate->address = $objOrder->getBillingAddress();
     $objTemplate->currency = $objOrder->currency;
     $objTemplate->return = \Environment::get('base') . $objModule->generateUrlForStep('complete', $objOrder);
     $objTemplate->cancel_return = \Environment::get('base') . $objModule->generateUrlForStep('failed');
     $objTemplate->notify_url = \Environment::get('base') . 'system/modules/isotope/postsale.php?mod=pay&id=' . $this->id;
     $objTemplate->headline = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][0]);
     $objTemplate->message = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][1]);
     $objTemplate->slabel = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][2]);
     $objTemplate->noscript = specialchars($GLOBALS['TL_LANG']['MSC']['pay_with_redirect'][3]);
     return $objTemplate->parse();
 }
示例#3
0
 /**
  * Generate item array for template
  * @param   ProductCollectionItem
  * @return  array
  */
 protected function generateItem(ProductCollectionItem $objItem)
 {
     $blnHasProduct = $objItem->hasProduct();
     $objProduct = $objItem->getProduct();
     // Set the active product for insert tags replacement
     if ($blnHasProduct) {
         Product::setActive($objProduct);
     }
     $arrCSS = $blnHasProduct ? deserialize($objProduct->cssID, true) : array();
     $arrItem = array('id' => $objItem->id, 'sku' => $objItem->getSku(), 'name' => $objItem->getName(), 'options' => Isotope::formatOptions($objItem->getOptions()), 'quantity' => $objItem->quantity, 'price' => Isotope::formatPriceWithCurrency($objItem->getPrice()), 'tax_free_price' => Isotope::formatPriceWithCurrency($objItem->getTaxFreePrice()), 'total' => Isotope::formatPriceWithCurrency($objItem->getTotalPrice()), 'tax_free_total' => Isotope::formatPriceWithCurrency($objItem->getTaxFreeTotalPrice()), 'tax_id' => $objItem->tax_id, 'href' => false, 'hasProduct' => $blnHasProduct, 'product' => $objProduct, 'item' => $objItem, 'raw' => $objItem->row(), 'rowClass' => trim('product ' . ($blnHasProduct && $objProduct->isNew() ? 'new ' : '') . $arrCSS[1]));
     if (null !== $objItem->getRelated('jumpTo') && $blnHasProduct && $objProduct->isAvailableInFrontend()) {
         $arrItem['href'] = $objProduct->generateUrl($objItem->getRelated('jumpTo'));
     }
     Product::unsetActive();
     return $arrItem;
 }
示例#4
0
 /**
  * Format product configuration using \Haste\Data
  *
  * @param array                  $arrConfig
  * @param IsotopeProduct|Product $objProduct
  *
  * @return array
  */
 public static function formatProductConfiguration(array $arrConfig, IsotopeProduct $objProduct)
 {
     Product::setActive($objProduct);
     $strTable = $objProduct->getTable();
     foreach ($arrConfig as $k => $v) {
         /** @type \Isotope\Model\Attribute $objAttribute */
         if (($objAttribute = $GLOBALS['TL_DCA'][$strTable]['attributes'][$k]) !== null && $objAttribute instanceof IsotopeAttributeWithOptions) {
             /** @type \Widget $strClass */
             $strClass = $objAttribute->getFrontendWidget();
             $arrField = $strClass::getAttributesFromDca($GLOBALS['TL_DCA'][$strTable]['fields'][$k], $k, $v, $k, $strTable, $objProduct);
             $arrOptions = array();
             $values = $v;
             if (!empty($arrField['options']) && is_array($arrField['options'])) {
                 if (!is_array($values)) {
                     $values = array($values);
                 }
                 $arrOptions = array_filter($arrField['options'], function (&$option) use(&$values) {
                     if (($pos = array_search($option['value'], $values)) !== false) {
                         $option = $option['label'];
                         unset($values[$pos]);
                         return true;
                     }
                     return false;
                 });
                 if (!empty($values)) {
                     $arrOptions = array_merge($arrOptions, $values);
                 }
             }
             $formatted = implode(', ', $arrOptions);
         } else {
             $formatted = Format::dcaValue($strTable, $k, $v);
         }
         $arrConfig[$k] = new Plain($v, Format::dcaLabel($strTable, $k), array('formatted' => Haste::getInstance()->call('replaceInsertTags', array($formatted))));
     }
     Product::unsetActive();
     return $arrConfig;
 }