function dopayment($data, $form) { $SQLData = Convert::raw2sql($data); if (isset($SQLData['OrderID'])) { if ($orderID = intval($SQLData['OrderID'])) { $order = Order::get_by_id_if_can_view($orderID); if ($order && $order->canPay()) { if (EcommercePayment::validate_payment($order, $form, $data)) { $payment = EcommercePayment::process_payment_form_and_return_next_step($order, $form, $data); } if ($payment) { ShoppingCart::singleton()->submit(); $order->tryToFinaliseOrder(); return $payment; } else { //error messages are set in validation return $this->controller->redirectBack(); } } else { $form->sessionMessage(_t('OrderForm.NO_PAYMENTS_CAN_BE_MADE_FOR_THIS_ORDER', 'No payments can be made for this order.'), 'bad'); return $this->controller->redirectBack(); } } } $form->sessionMessage(_t('OrderForm.COULDNOTPROCESSPAYMENT', 'Sorry, we could not find the Order for payment.'), 'bad'); $this->controller->redirectBack(); return false; }
function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldToTab("Root.Details", new LiteralField("Request", $this->getRequestDetails())); $fields->addFieldToTab("Root.Details", new LiteralField("Response", $this->getResponseDetails())); return $fields; }
function processPayment($data, $form) { $order = $this->Order(); //if currency has been pre-set use this $currency = $this->Amount->Currency; //if amout has been pre-set, use this $amount = $this->Amount->Amount; if ($order) { //amount may need to be adjusted to total outstanding //or amount may not have been set yet $amount = $order->TotalOutstanding(); //get currency from Order //this is better than the pre-set currency one //which may have been set to the default $currencyObject = $order->CurrencyUsed(); if ($currencyObject) { $currency = $currencyObject->Code; } } if (!$amount && !empty($data["Amount"])) { $amount = floatval($data["Amount"]); } if (!$currency && !empty($data["Currency"])) { $currency = floatval($data["Currency"]); } //final backup for currency if (!$currency) { $currency = EcommercePayment::site_currency(); } $this->Amount->Currency = $currency; $this->Amount->Amount = $amount; //no need to write here, as it will be done by BuildURL //$this->write(); $url = $this->buildURL($amount, $currency); return $this->executeURL($url); }
function populateDefaults() { parent::populateDefaults(); $this->AuthorisationCode = md5(uniqid(rand(), true)); }
function dopayment($data, $form) { $SQLData = Convert::raw2sql($data); if (isset($SQLData['OrderID'])) { if ($orderID = intval($SQLData['OrderID'])) { $order = Order::get_by_id_if_can_view($orderID); if ($order && $order->canPay()) { return EcommercePayment::process_payment_form_and_return_next_step($order, $form, $data); } } } $form->sessionMessage(_t('OrderForm.COULDNOTPROCESSPAYMENT', 'Sorry, we could not process your payment.'), 'bad'); Director::redirectBack(); return false; }
function getCMSFields() { $fields = parent::getCMSFields(); $fields->replaceField("DebugMessage", new ReadonlyField("DebugMessage", "Debug info")); return $fields; }
/** * Returns the currency used on the site. * @return String */ function Currency() { $currency = EcommercePayment::site_currency(); return $currency; }
/** * returns the list of supported methods * test methods are included if the site is in DEV mode OR * the current user is a ShopAdmin. * @return Array */ public static function get_supported_methods($order = null) { $obj = EcommercePayment::create(); return $obj->supportedMethodsProvider->SupportedMethods($order); }
function doAddNewPriceForm($data, $form) { $amount = $this->parseFloat($data["Amount"]); if ($this->MinimumAmount && $amount < $this->MinimumAmount) { $form->sessionMessage(_t("AnyPriceProductPage.ERRORINFORMTOOLOW", "Please enter a higher amount."), "bad"); $this->redirectBack(); return; } elseif ($this->MaximumAmount && $amount > $this->MaximumAmount) { $form->sessionMessage(_t("AnyPriceProductPage.ERRORINFORMTOOHIGH", "Please enter a lower amount."), "bad"); $this->redirectBack(); return; } Session::clear("AnyPriceProductPageAmount"); $obj = AnyPriceProductPage_ProductVariation::get()->filter(array("ProductID" => $this->ID, "Price" => $amount))->First(); //create new one if needed if (!$obj) { Currency::setCurrencySymbol(EcommercePayment::site_currency()); $titleDescriptor = new Currency("titleDescriptor"); $titleDescriptor->setValue($amount); $obj = new AnyPriceProductPage_ProductVariation(); $obj->Title = _t("AnyPriceProductPage.PAYMENTFOR", "Payment for: ") . $titleDescriptor->Nice(); $obj->Price = $amount; $obj->AllowPurchase = true; $obj->ProductID = $this->ID; $obj->write("Stage"); // line below does not work - suspected bug in framework Versioning System //$componentSet->add($obj); } //check if we have one now if (!$obj) { $obj = AnyPriceProductPage_ProductVariation::get()->filter(array("ProductID" => $this->ID, "Price" => $amount))->First(); } if ($obj) { $shoppingCart = ShoppingCart::singleton(); $shoppingCart->addBuyable($obj); } else { $form->sessionMessage(_t("AnyPriceProductPage.ERROROTHER", "Sorry, we could not add our entry."), "bad"); $this->redirectBack(); return; } $checkoutPage = CheckoutPage::get()->First(); if ($checkoutPage) { $this->redirect($checkoutPage->Link()); } return; }
/** * Process final confirmation and payment * * {@link Payment} instance is created, linked to the order, * and payment is processed {@link EcommercePayment::processPayment()} * * @param array $data Form request data submitted from OrderForm * @param Form $form Form object for this action * @param HTTPRequest $request Request object for this action */ function processOrder(array $data, Form $form, SS_HTTPRequest $request) { $this->saveDataToSession($data); //save for later if necessary $order = ShoppingCart::current_order(); //check for cart items if (!$order) { $form->sessionMessage(_t('OrderForm.ORDERNOTFOUND', 'Your order could not be found.'), 'bad'); $this->controller->redirectBack(); return false; } if ($order && $order->TotalItems($recalculate = true) < 1) { // WE DO NOT NEED THE THING BELOW BECAUSE IT IS ALREADY IN THE TEMPLATE AND IT CAN LEAD TO SHOWING ORDER WITH ITEMS AND MESSAGE $form->sessionMessage(_t('Order.NOITEMSINCART', 'Please add some items to your cart.'), 'bad'); $this->controller->redirectBack(); return false; } if ($this->extend("OrderFormBeforeFinalCalculation", $data, $form, $request)) { $form->sessionMessage(_t('Order.ERRORWITHFORM', 'There was an error with your order, please review and submit again.'), 'bad'); $this->controller->redirectBack(); return false; } //RUN UPDATES TO CHECK NOTHING HAS CHANGED $oldTotal = $order->Total(); //if the extend line below does not return null then we know there // is an error in the form (e.g. Payment Option not entered) $order->calculateOrderAttributes($force = true); $newTotal = $order->Total(); if (floatval($newTotal) != floatval($oldTotal)) { $form->sessionMessage(_t('OrderForm.PRICEUPDATED', 'The order price has been updated, please review the order and submit again.'), 'warning'); $this->controller->redirectBack(); return false; } //saving into order $form->saveInto($order); $order->write(); //saving into member, in case we add additional fields for the member //e.g. newslettersignup if ($member = Member::currentUser()) { $form->saveInto($member); $password = ShopAccountForm_PasswordValidator::clean_password($data); if ($password) { $member->changePassword($password); } if ($member->validate()) { $member->write(); } else { $form->sessionMessage(_t('OrderForm.ACCOUNTERROR', 'There was an error saving your account details.'), 'warning'); $this->controller->redirectBack(); return false; } } //----------------- CLEAR OLD DATA ------------------------------ $this->clearSessionData(); //clears the stored session form data that might have been needed if validation failed //----------------- VALIDATE PAYMENT ------------------------------ $paymentIsValid = EcommercePayment::validate_payment($order, $form, $data); if (!$paymentIsValid) { $this->controller->redirectBack(); return false; } //-------------- NOW SUBMIT ------------- $this->extend("OrderFormBeforeSubmit", $order); // this should be done before paying, as only submitted orders can be paid! ShoppingCart::singleton()->submit(); $this->extend("OrderFormAfterSubmit", $order); //-------------- ACTION PAYMENT ------------- $payment = EcommercePayment::process_payment_form_and_return_next_step($order, $form, $data); //-------------- DO WE HAVE ANY PROGRESS NOW ------------- $order->tryToFinaliseOrder(); //any changes to the order at this point can be taken care by ordsteps. //------------- WHAT DO WE DO NEXT? ----------------- if ($payment) { //redirection is taken care of by EcommercePayment return $payment; } else { //there is an error with payment if (!Controller::curr()->redirectedTo()) { $this->controller->redirect($order->Link()); } return false; } //------------------------------ }