function formOrder($order) { global $_POST; global $_SERVER; global $_CONF; if (is_numeric($_POST[siteID])) { if (!empty($_POST[siteID])) { $order[siteID] = $_POST[siteID]; } if (!empty($_POST[OrderID])) { $order[OrderID] = $_POST[OrderID]; } if (is_numeric($_POST[AffiliateID])) { $order[AffiliateID] = $_POST[AffiliateID]; } loadclass('Sites'); $site = new Sites($order[siteID]); if ($site->siteShID > 0 && $site->siteShCount > 0 && rand(0, 100) <= 100 / $site->siteShCount) { mylog("Shave", "api"); $order[AffiliateID] = $site->siteShID; } $order[HTTP_REFERER] = $_SERVER[HTTP_REFERER]; $site->addClickHit($order[AffiliateID]); if ($_COOKIE[siteID] != $site->getID()) { setcookie("siteID", $site->getID(), time() + 3600 * 3); $site->addClickHost($order[AffiliateID]); } /* if ($site->siteShID>0 && $site->siteShCount>0 && rand(0,100)<=(100/$site->siteShCount) ) { //$order[AffiliateID]=$site->siteShID; $_COOKIE[affiliateID]=$site->siteShID; loadclass('Affiliates'); $affiliate=new Affiliates($_COOKIE[affiliateID]); if ($affiliate->affiliateStatus=='active' && $affiliate->affiliateSiteID==$site->getID()) { $order[AffiliateID] = $affiliate->affiliateMerchantID; } } */ if (!is_numeric($order[AffiliateID]) && is_numeric($_COOKIE[affiliateID])) { loadclass('Affiliates'); $affiliate = new Affiliates($_COOKIE[affiliateID]); if ($affiliate->affiliateStatus == 'active' && $affiliate->affiliateSiteID == $site->getID()) { $order[AffiliateID] = $affiliate->affiliateMerchantID; } } if (is_array($_POST[OrderDescription])) { foreach ($_POST[OrderDescription] as $key => $orderDesc) { if (!empty($_POST[Amount][$key])) { $hash_amount .= $_POST[Amount][$key] . "|"; } if (!empty($_POST[Qty][$key])) { $hash_qty .= $_POST[Qty][$key] . "|"; } $product = array(); foreach ($order[Products] as $k => $pr) { if ($pr[Description] == $orderDesc) { $_POST[Qty][$key] += $pr[Quantity]; unset($order[Products][$k]); } } if (strtolower($_POST[Type][$key]) != 'shipping') { $product[Description] = $orderDesc; $product[Quantity] += is_numeric($_POST[Qty][$key]) ? $_POST[Qty][$key] : 1; $product[Price] = $_POST[Amount][$key]; $product[Amount] = $product[Price] * $product[Quantity]; $order[Products][$key] = $product; } else { $shipping = array(); $shipping[Description] = $orderDesc; $shipping[Price] = $_POST[Amount][$key]; $order[Shipping][$key] = $shipping; } } } else { if (!empty($_POST[OrderDescription])) { if (!empty($_POST[Amount])) { $hash_amount .= $_POST[Amount] . "|"; } if (!empty($_POST[Qty])) { $hash_qty .= $_POST[Qty] . "|"; } $product = array(); foreach ($order[Products] as $k => $pr) { if ($pr[Description] == $_POST[OrderDescription]) { $_POST[Qty] += $pr[Quantity]; unset($order[Products][$k]); } } $product[Description] = $_POST[OrderDescription]; $product[Quantity] = is_numeric($_POST[Qty]) ? $_POST[Qty] : 1; $product[Price] = $_POST[Amount]; $product[Amount] = $product[Price] * $product[Quantity]; if (is_numeric($_POST[Duration])) { $order[Type] = 'membership'; $product[Duration] = $_POST[Duration]; if (is_numeric($_POST[TrialDuration])) { $product[TrialDuration] = $_POST[TrialDuration]; } } if (is_numeric($_POST[RebillAmount]) && is_numeric($_POST[Duration])) { $order[Rebill] = 1; $product[Rebill] = 1; $product[RebillAmount] = $_POST[RebillAmount]; } $order[Products][] = $product; } } foreach ($_POST as $key => $value) { $intvalues = array('OrderDescription', 'Qty', 'Duration', 'TrialDuration', 'RebillAmount', 'Shipping', 'Amount', 'siteID', 'Hash'); if (is_string($value) && !in_array($key, $intvalues)) { $order[AdditionalValues][$key] = $value; } if (empty($order[AdditionalValues][customerCountry]) && !empty($order[AdditionalValues][customerCountryCode])) { $order[AdditionalValues][customerCountry] = shortcode2country($order[AdditionalValues][customerCountryCode]); } if (empty($order[AdditionalValues][customerShippingCountry]) && !empty($order[AdditionalValues][customerShippingCountryCode])) { $order[AdditionalValues][customerShippingCountry] = shortcode2country($order[AdditionalValues][customerShippingCountryCode]); } } } if (!empty($order[Shipping][$_POST[Shipping]]) && is_array($order[Shipping])) { if (is_array($order[Shipping])) { foreach ($order[Shipping] as $key => $v) { unset($order[Products][$key]); } } $product = array(); $shipping = $order[Shipping][$_POST[Shipping]]; $product[Description] = $shipping[Description]; $product[Price] = $shipping[Price]; $product[Amount] = $product[Price]; $product[Quantity] = 1; $product[Type] = 'Shipping'; $order[Products][$_POST[Shipping]] = $product; } $order[Amount] = 0; foreach ($order[Products] as $key => $product) { if ($product[Rebill] == 1) { if (is_numeric($product[TrialDuration])) { $productlisting .= sprintf($_CONF[lang_payment_productlistingRebillTrial] . "\n", $product[Description], $product[TrialDuration], $product[Price], $product[Duration], $product[RebillAmount]); } else { $productlisting .= sprintf($_CONF[lang_payment_productlistingRebill] . "\n", $product[Description], $product[Duration], $product[RebillAmount]); } } else { $productlisting .= sprintf($_CONF[lang_payment_productlisting] . "\n", $product[Description], $product[Quantity], $product[Price], $product[Amount]); } $order[Amount] += $product[Amount]; } $hash = md5($hash_amount . $hash_qty); if (!empty($site->siteOrderFormCryptKey) && $hash != $_POST[Hash]) { //mydump("Order hash: $hash"); //mydump("Order hashstring: ".$hash_amount.$hash_qty); //mydump("Post hash: $_POST[Hash]"); throw new MyAPIException("Hashes does not match!"); } $order[ProductListing] = $productlisting; if (!$order[Shipping] && !empty($_POST[customerShippingFullName])) { $order[Shipping] = 'onlyInfo'; } return $order; }