public function add($product_id, $shipping_id, $order_id, $flags = '') { //$i = count($this->orderProducts) + 1; $this->orderProducts[$product_id] = new OrderProduct(); $this->orderProducts[$product_id]->allFields = true; $this->orderProducts[$product_id]->product_id = $product_id; $this->orderProducts[$product_id]->shipping_id = $shipping_id; $this->orderProducts[$product_id]->order_id = $order_id; $this->orderProducts[$product_id]->flags = $flags; $p = new Product(); $p->fillFromDbPk($product_id); $this->orderProducts[$product_id]->product_name = $p->product_name; $this->orderProducts[$product_id]->product_sku = $p->product_sku; $this->orderProducts[$product_id]->product_price = $p->product_price; // do we need to set recurring billing? if ($p->subscription_days) { $d = new DateTime(); $interval = 'P' . $p->subscription_days . 'D'; $d->add(new DateInterval($interval)); // P1D means a period of 1 day $this->orderProducts[$product_id]->recurring_next = $d->format('Y-m-d 00:00:00'); $this->orderProducts[$product_id]->addFlags('recurring'); unset($d); } unset($p); $this->updateTotal(); $this->num_products++; }
public static function createRecurringOrder($item) { if (!$item['product_next_id']) { return; } //Current order $newOrderModel = new Order(); $newOrderModel->fillFromArray($item); //Next product $productModel = new Product(); $productModel->fillFromDbPk($item['product_next_id']); //Current shipping $shippingModel = new Shipping(); $shippingModel->fillFromDbPk($item['shipping_id']); //Update order $newOrderModel->updated = 'NOW():sql'; $newOrderModel->created = 'NOW():sql'; unset($newOrderModel->order_id); $newOrderModel->status = 'pending'; $newOrderModel->amount_product = $item['discount_next'] ? round($productModel->product_price - $productModel->product_price * $item['discount_next'] / 100, 2) : $productModel->product_price; $newOrderModel->amount_shipping = $productModel->shippable ? $shippingModel->amount_subscription : 0.0; $newOrderModel->amount_refunded = 0.0; $newOrderModel->payment_total = 0.0; $newOrderModel->pixel_fired = 0; $newOrderModel->discount_next = 0; $newOrderModel->click_id = ''; $newOrderModel->rocket = 0; $newOrderModel->product_id = $item['product_next_id']; $newOrderModel->rma_code = 'NULL:sql'; $newOrderModel->recurring = 0; //(!$productModel->subscription_days || $item['recurring'] === '-1') ? 'NULL:sql' : 0; $newOrderModel->billing_cycle++; $newOrderModel->recurring_next = !$productModel->subscription_days || $item['recurring'] === '-1' ? 'NULL:sql' : date('Y-m-d', time() + 86400 * $item['subscription_days']); $newOrderModel->setRecuringShipWith($item['ship_with']); /* if($item['ship_with']) { $newOrderModel->setRecuringShipWith(); } else $newOrderModel->ship_with = 'NULL:sql'; */ //Save new order $newOrderModel->flags = isset($item['flags']) && $item['flags'] ? $item['flags'] : 'NULL:sql'; $newOrderModel->tracking_number = 'NULL:sql'; $newOrderModel->save(false); $paymentID = $item['status'] == 'upsell' ? $item['ship_with'] : $item['order_id']; //Current Payment $paymentModelName = 'Order' . ucfirst($newOrderModel->payment_type); $paymentModel = new $paymentModelName(); $paymentModel->fillFromDbPk($paymentID); //Update Paument if ($newOrderModel->payment_type == 'pn') { $paymentModel->pn_status = 'new'; $paymentModel->approval_code = ''; //$paymentModel->card_number = ''; $paymentModel->response_cc_cvv = ''; $paymentModel->filename = ''; $paymentModel->request_id = ''; $paymentModel->tracking_number = ''; } elseif ($newOrderModel->payment_type == 'og') { //??? } elseif ($newOrderModel->payment_type == 'gc') { $paymentModel->gc_updated = 'NOW():sql'; $paymentModel->gc_status = ''; $paymentModel->gc_refunded = 0.0; $paymentModel->gc_ref = ''; $paymentModel->gc_mac = ''; } $paymentModel->order_id = $newOrderModel->order_id; $paymentModel->setIsNewRecord(true); //Save new Payment $paymentModel->save(false); //Update current Order $currentOrdermodel = new Order(); $currentOrdermodel->setIsNewRecord(false); $currentOrdermodel->order_id = $item['order_id']; $currentOrdermodel->recurring = $newOrderModel->order_id; $currentOrdermodel->recurring_next = 'NULL:sql'; $currentOrdermodel->save(false); }
if ($orderModel->payment_type == 'gc') { $gcOptions = Payment_gc::getOptions(); $paymentModel = new OrderGc(); $paymentModel->fillFromDbPk($orderModel->order_id); $paymentMethod = $paymentModel->gc_payment_type; if ($paymentMethod != 770) { continue; } $saveOrderModel = new Order(); $saveOrderModel->setIsNewRecord(false); $saveOrderModel->order_id = $orderModel->order_id; $paymentTypes = array(); $paymentTypes = @(include_once '../../ws/settings/payment_gc_types.php'); $paymentType = $paymentTypes[$paymentMethod]; $mainProduct = new Product(); $mainProduct->fillFromDbPk($orderModel->product_id); $dd = isset($paymentType['methodID']) && $paymentType['methodID'] == 3 ? true : false; $sql = "SELECT s.`state_name`, c.`lang_id`\n FROM `states` as s\n LEFT JOIN `countries` as c ON s.`country_id`=c.`country_id`\n WHERE s.`state_code` = ?s"; $r1 = $msql->getRow($sql, $orderModel->state_id); $gcPaymentArray = array('firstname' => $orderModel->fname, 'surname' => $orderModel->lname, 'street' => $orderModel->address1, 'city' => $orderModel->city, 'zip' => $orderModel->zip, 'state' => $r1['state_name'] ? $r1['state_name'] : $orderModel->state_id, 'hostedindicator' => $dd ? 0 : 1, 'MANDATE' => 'PRESENT'); if ($dd) { $gcPaymentArray['acceptneededindicator'] = '0'; $gcPaymentArray['directdebittext'] = $mainProduct->product_name . ' ' . $orderModel->phone; } if ($paymentModel->bank_code) { $gcPaymentArray['bankcode'] = $paymentModel->bank_code; } if ($paymentModel->issuer_id) { $gcPaymentArray['issuer_id'] = $paymentModel->issuer_id; } if ($paymentModel->bank_name) {
//$amount = round($pymtResp->get('Amount')/100, 2); $newPaymentModel->approval_code = $pymtResp->get('ApprovalCode'); $newPaymentModel->pn_payment_type = $pymtResp->get('PymtType'); $newPaymentModel->card_number = $pymtResp->get('CardNumber'); $newPaymentModel->currency = $pymtResp->get('Currency'); $newPaymentModel->response_cc_cvv = $pymtResp->get('CVV2ResponseCode'); $newPaymentModel->filename = $pymtResp->get('Filename'); $newPaymentModel->request_id = $pymtResp->get('RequestID'); $newPaymentModel->pn_status = $pymtResp->get('Status'); $newPaymentModel->tracking_number = $pymtResp->get('TrackingNumber'); $newPaymentModel->attempt = $paymentModel->attemt + 1; $newPaymentModel->save(false); //Update recurring_next if ($pymtResp->get('Status') == 'Approved') { $productModel = new Product(); $productModel->fillFromDbPk($orderModel->product_id); if ($orderModel->recurring_next) { $orderModel->recurring_next = date('Y-m-d', time() + 86400 * $productModel->subscription_days); $orderModel->recurring = 0; } else { $orderModel->recurring = 'NULL:sql'; } } else { if ($orderModel->recurring) { $orderModel->recurring = 0; } } $orderModel->status = $pymtResp->get('Status') == 'Approved' ? 'ok' : 'error'; //$orderModel->recurring_next = 'NULL:sql'; if ($orderModel->status == 'ok') { $orderModel->payment_total = round($pymtResp->get('Amount') / 100, 2);
function getproductAction() { $this->checkLogin(); AF::setJsonHeaders('json'); $product_id = AF::get($_POST, 'product_id', false); if (!$product_id) { Message::echoJsonError(__('incorrect_product_id')); } $modelProduct = new Product(); $modelProduct->fillFromDbPk($product_id); $product = $modelProduct->getDataArray(); $product['recurring_next'] = date("Y-m-d", time() + $product['subscription_days'] * 86400); Message::echoJsonSuccess(array('message' => $product)); exit; }