/** * React to DSP response triggered by {@link processPayment()}. */ public function processResponse() { if (preg_match('/^PXHOST/i', $_SERVER['HTTP_USER_AGENT'])) { $dpsDirectlyConnecting = 1; } //$pxaccess = new PxAccess($PxAccess_Url, $PxAccess_Userid, $PxAccess_Key, $Mac_Key); $pxpay = new PxPay(DPSHostedPayment::$pxPay_Url, DPSHostedPayment::get_px_pay_userid(), DPSHostedPayment::get_px_pay_key()); $enc_hex = $_REQUEST["result"]; $rsp = $pxpay->getResponse($enc_hex); if (isset($dpsDirectlyConnecting) && $dpsDirectlyConnecting) { // DPS Service connecting directly $success = $rsp->getSuccess(); # =1 when request succeeds echo $success == '1' ? "success" : "failure"; } else { // Human visitor $paymentID = $rsp->getTxnId(); $SQL_paymentID = (int) $paymentID; $payment = DataObject::get_one('DPSHostedPayment', "`TxnID` = '{$SQL_paymentID}'"); if (!$payment) { // @todo more specific error messages return array('RedirectLink' => AccountPage::find_link()); } $success = $rsp->getSuccess(); if ($success == '1') { // @todo Use AmountSettlement for amount setting? $payment->TxnRef = $rsp->getDpsTxnRef(); $payment->Status = "Success"; $payment->AuthorizationCode = $rsp->getAuthCode(); } else { $payment->Message = $rsp->getResponseText(); $payment->Status = "Failure"; } $payment->write(); //TODO: this needs to be generalised in Payment?? $redirectURL = $payment->PaidObject() && $payment->PaidObject()->Link() ? $payment->PaidObject()->Link() : 'home'; Director::redirect($redirectURL); return null; } }
/** * work out the options for the user **/ protected function workOutMessagesAndActions() { if (!$this->workedOutMessagesAndActions) { $this->actionLinks = new ArrayList(array()); //what order are we viewing? $viewingRealCurrentOrder = $this->CurrentOrderIsInCart(); $currentUserID = Member::currentUserID(); //Continue Shopping if (isset($this->ContinueShoppingLabel) && $this->ContinueShoppingLabel) { if ($viewingRealCurrentOrder) { if ($this->isCartPage()) { $continueLink = $this->ContinueShoppingLink(); if ($continueLink) { $this->actionLinks->push(new ArrayData(array("Title" => $this->ContinueShoppingLabel, "Link" => $continueLink))); } } } } //Proceed To CheckoutLabel if (isset($this->ProceedToCheckoutLabel) && $this->ProceedToCheckoutLabel) { if ($viewingRealCurrentOrder) { if ($this->isCartPage()) { $checkoutPageLink = CheckoutPage::find_link(); if ($checkoutPageLink && $this->currentOrder && $this->currentOrder->getTotalItems()) { $this->actionLinks->push(new ArrayData(array("Title" => $this->ProceedToCheckoutLabel, "Link" => $checkoutPageLink))); } } } } //view account details if (isset($this->ShowAccountLabel) && $this->ShowAccountLabel) { if ($this->isOrderConfirmationPage() || $this->isCartPage()) { if (AccountPage::find_link()) { if ($currentUserID) { $this->actionLinks->push(new ArrayData(array("Title" => $this->ShowAccountLabel, "Link" => AccountPage::find_link()))); } } } } //go to current order if (isset($this->CurrentOrderLinkLabel) && $this->CurrentOrderLinkLabel) { if ($this->isCartPage()) { if (!$viewingRealCurrentOrder) { $this->actionLinks->push(new ArrayData(array("Title" => $this->CurrentOrderLinkLabel, "Link" => ShoppingCart::current_order()->Link()))); } } } //Save order - we assume only current ones can be saved. if (isset($this->SaveOrderLinkLabel) && $this->SaveOrderLinkLabel) { if ($viewingRealCurrentOrder) { if ($currentUserID && $this->currentOrder->MemberID == $currentUserID) { if ($this->isCartPage()) { if ($this->currentOrder && $this->currentOrder->getTotalItems() && !$this->currentOrder->IsSubmitted()) { $this->actionLinks->push(new ArrayData(array("Title" => $this->SaveOrderLinkLabel, "Link" => $this->Link("saveorder") . "/" . $this->currentOrder->ID . "/"))); } } } } } //load order if (isset($this->LoadOrderLinkLabel) && $this->LoadOrderLinkLabel) { if ($this->isCartPage() && $this->currentOrder) { if (!$viewingRealCurrentOrder) { $this->actionLinks->push(new ArrayData(array("Title" => $this->LoadOrderLinkLabel, "Link" => $this->Link("loadorder") . "/" . $this->currentOrder->ID . "/"))); } } } //delete order if (isset($this->DeleteOrderLinkLabel) && $this->DeleteOrderLinkLabel) { if ($this->isCartPage() && $this->currentOrder) { if (!$viewingRealCurrentOrder) { $this->actionLinks->push(new ArrayData(array("Title" => $this->DeleteOrderLinkLabel, "Link" => $this->Link("deleteorder") . "/" . $this->currentOrder->ID . "/"))); } } } //Start new order //Strictly speaking this is only part of the //OrderConfirmationPage but we put it here for simplicity's sake if (isset($this->StartNewOrderLinkLabel) && $this->StartNewOrderLinkLabel) { if ($this->isOrderConfirmationPage()) { $this->actionLinks->push(new ArrayData(array("Title" => $this->StartNewOrderLinkLabel, "Link" => CartPage::new_order_link($this->currentOrder->ID)))); } } //copy order //Strictly speaking this is only part of the //OrderConfirmationPage but we put it here for simplicity's sake if (isset($this->CopyOrderLinkLabel) && $this->CopyOrderLinkLabel) { if ($this->isOrderConfirmationPage() && $this->currentOrder->ID) { $this->actionLinks->push(new ArrayData(array("Title" => $this->CopyOrderLinkLabel, "Link" => OrderConfirmationPage::copy_order_link($this->currentOrder->ID)))); } } //actions from modifiers if ($this->isOrderConfirmationPage() && $this->currentOrder->ID) { $modifiers = $this->currentOrder->Modifiers(); if ($modifiers->count()) { foreach ($modifiers as $modifier) { $array = $modifier->PostSubmitAction(); if (is_array($array) && count($array)) { $this->actionLinks->push(new ArrayData($array)); } } } } //log out //Strictly speaking this is only part of the //OrderConfirmationPage but we put it here for simplicity's sake if (Member::currentUser()) { if ($this->isOrderConfirmationPage()) { $this->actionLinks->push(new ArrayData(array("Title" => _t("CartPage.LOGOUT", "log out"), "Link" => "/Security/logout/"))); } } //no items if ($this->currentOrder) { if (!$this->currentOrder->getTotalItems()) { $this->message = $this->NoItemsInOrderMessage; } } else { $this->message = $this->NonExistingOrderMessage; } $this->workedOutMessagesAndActions = true; //does nothing at present.... } }
public function testGlobals() { $this->assertFalse($this->accountpage->canCreate(), "account page exists"); $this->assertEquals(Director::baseURL() . "account/", AccountPage::find_link()); $this->assertEquals(Director::baseURL() . "account/order/10", AccountPage::get_order_link(10)); }
/** * Get the link for finishing order processing. */ public function Link() { if (Member::currentUser()) { return Controller::join_links(AccountPage::find_link(), 'order', $this->ID); } return CheckoutPage::find_link(false, "order", $this->ID); }
/** * Return the {@link Order} details for the current * Order ID that we're viewing (ID parameter in URL). * * @return array of template variables */ function order($request) { Requirements::themedCSS('Order'); Requirements::themedCSS('Order_print', 'print'); $memberID = Member::currentUserID(); $accountPageLink = AccountPage::find_link(); if ($orderID = $request->param('ID')) { if ($order = DataObject::get_one('Order', "\"Order\".\"ID\" = '{$orderID}' AND \"Order\".\"MemberID\" = '{$memberID}'")) { $paymentform = $order->TotalOutstanding() > 0 ? $this->CancelForm() : null; return array('Order' => $order, 'Form' => $paymentform); } else { return array('Order' => false, 'Message' => 'You do not have any order corresponding to this ID. However, you can <a href="' . $accountPageLink . '">edit your own personal details and view your orders.</a>.'); } } else { return array('Order' => false, 'Message' => 'There is no order by that ID. You can <a href="' . $accountPageLink . '">edit your own personal details and view your orders.</a>.'); } }
/** * Return the {@link Order} details for the current * Order ID that we're viewing (ID parameter in URL). * * @return array of template variables */ function order($request) { Requirements::themedCSS('Order'); Requirements::themedCSS('Order_print', 'print'); $memberID = Member::currentUserID(); $accountPageLink = AccountPage::find_link(); if ($orderID = $request->param('ID')) { if ($order = DataObject::get_one('Order', "Order.ID = '{$orderID}' AND MemberID = '{$memberID}'")) { return array('Order' => $order); } else { return array('Order' => false, 'Message' => 'You do not have any order corresponding to this ID. However, you can <a href="' . $accountPageLink . '">edit your own personal details and view your orders.</a>.'); } } else { return array('Order' => false, 'Message' => 'There is no order by that ID. You can <a href="' . $accountPageLink . '">edit your own personal details and view your orders.</a>.'); } }
/** * Form action handler for Order_CancelForm. * * Take the order that this was to be change on, * and set the status that was requested from * the form request data. * * @param array $data The form request data submitted * @param Form $form The {@link Form} this was submitted on */ function doCancel($data, $form) { $SQL_data = Convert::raw2sql($data); $order = DataObject::get_by_id('Order', $SQL_data['OrderID']); $order->Status = 'MemberCancelled'; $order->write(); //TODO: notify people via email?? Make it optional. if (self::$email_notification) { $email = new Email(Email::getAdminEmail(), Email::getAdminEmail(), sprintf(_t('Order.CANCELSUBJECT', 'Order #%d cancelled by member'), $order->ID), $order->renderWith('Order')); $email->send(); } if (Member::currentUser() && ($link = AccountPage::find_link())) { //TODO: set session message "order successfully cancelled". Director::redirect($link); //TODO: can't redirect to account page when not logged in } else { $form->Controller()->setSessionMessage(_t("OrderForm.ORDERCANCELLED", "Order sucessfully cancelled"), 'warning'); //assumes controller has OrderManipulation extension Director::redirectBack(); } return; }
/** * @return String (URLSegment) **/ public function AccountPageLink() { return AccountPage::find_link(); }