/** * * @param CanteenOrder $CanteenOrder * @param String $method charge | auth * @return void */ public function chargeOnlineOrder($CanteenOrder, $method = "charge") { $gateway_id = CanteenConfig::get("gateway_account_id"); $possible_fraud = false; $trans = GatewayTransactionVO::formatCanteenOrder($CanteenOrder); //check geo country if ($_SERVER['GEOIP_COUNTRY_CODE'] != $CanteenOrder['BillingAddress']['country_code']) { $method = "auth"; $possible_fraud = true; } $res = $this->GatewayTransaction->GatewayAccount->run($method, $gateway_id, $trans); //verb to update order status $verb = "declined"; //if the charge succeeded if ($res) { switch (strtoupper($method)) { case "CHARGE": $verb = "approved"; break; case "AUTH": $verb = "authorized"; break; } unset($CanteenOrder['CardData']); } $this->create(); $this->id = $CanteenOrder['CanteenOrder']['id']; $this->save(array("order_status" => $verb)); if ($res) { //allocate inventory $_SERVER['FORCEMASTER'] = true; $this->processOrderInventory($CanteenOrder['CanteenOrder']['id']); $this->CanteenShippingRecord->createShipment($CanteenOrder['CanteenOrder']['id']); unset($_SERVER['FORCEMASTER']); //queue order email $this->EmailMessage->canteenOrderConfirmation($CanteenOrder); if ($possible_fraud) { $this->CanteenOrderNote->addHiddenNote(array("canteen_order_id" => $CanteenOrder['CanteenOrder']['id'], "message" => "Possible Fraud. Confirm Order With Customer")); } } return $res; }
public function add() { if (count($this->request->data) > 0) { $this->fixPublishDate(); $this->request->data['Tag'] = $this->CanteenProduct->Tag->parseTags($this->request->data['CanteenProduct']['tags']); if (empty($this->request->data['CanteenProduct']['uri'])) { $brand = $this->CanteenProduct->Brand->find("first", array("conditions" => array("Brand.id" => $this->request->data['CanteenProduct']['brand_id']), "contain" => array())); $ustr = $brand['Brand']['name'] . " " . $this->request->data['CanteenProduct']['name'] . " " . $this->request->data['CanteenProduct']['sub_title']; $this->request->data['CanteenProduct']['uri'] = Tools::safeUrl($ustr) . ".html"; } $this->request->data['CanteenProduct']['display_weight'] = 99; $this->CanteenProduct->save($this->request->data); $new_id = $this->CanteenProduct->id; //add in all the product prices in the default config $curr = CanteenConfig::get("currencies"); foreach ($curr as $c) { $this->CanteenProduct->CanteenProductPrice->create(); $this->CanteenProduct->CanteenProductPrice->save(array("canteen_product_id" => $new_id, "currency_id" => $c)); } return $this->flash("Product Added Successfully", "/canteen_products/edit/" . $new_id); } else { $this->request->data['CanteenProduct']['pub_date'] = date("Y-m-d", strtotime("+30 Day")); $this->request->data['CanteenProduct']['pub_time'] = "00:00"; } $this->canteenProductSelects(); }