public static function fromJson($json) { $r = new Checkout(); $r->setItems(array_map(function ($json) { return CheckoutItem::fromJson($json); }, $json->items)); $r->setTotal(Price::fromJson($json->total)); return $r; }
public function testBuildWithoutTotal() { $checkout = new Checkout(); $checkout->addItem(CheckoutItem::of(1, 'SKU')->setExternalId('external_id')->setName(['en' => 'Name'])->setPrice(['EUR' => '10.0'])); try { $checkout->build(); $this->fail(); } catch (\LogicException $ignored) { } }
function setShippingMethod($data, $form) { $cart = $this->owner->Cart(); $option = null; if (isset($data['ShippingMethodID'])) { $option = DataObject::get_by_id("ShippingMethod", (int) $data['ShippingMethodID']); } //assign option to order / modifier if ($option) { $checkout = new Checkout($cart); $checkout->setShippingMethod($option); } Director::redirect($this->NextStepLink('paymentmethod')); }
function testSave() { //Arrange $copy_id = 1; $patron_id = 1; $id = 1; $due_date = '2015-10-10'; $test_checkout = new Checkout($copy_id, $patron_id, $due_date, $id); $test_checkout->save(); //Act $result = Checkout::getAll(); //Assert $this->assertEquals($test_checkout, $result[0]); }
function test_find() { //Arrange $due_date = "0001-01-01"; $test_checkout = new Checkout($due_date); $test_checkout->save(); $due_date2 = "2020-01-01"; $test_checkout2 = new Checkout($due_date2); $test_checkout2->save(); //Act $result = Checkout::find($test_checkout->getId()); //Assert $this->assertEquals($test_checkout, $result); }
/** * Create member account from data array. * Data must contain unique identifier. * * @throws ValidationException * @param $data - map of member data * @return Member|boolean - new member (not saved to db), or false if there is an error. */ public function create($data) { $result = new ValidationResult(); if (!Checkout::member_creation_enabled()) { $result->error(_t("Checkout.MEMBERSHIPSNOTALLOWED", "Creating new memberships is not allowed")); throw new ValidationException($result); } $idfield = Config::inst()->get('Member', 'unique_identifier_field'); if (!isset($data[$idfield]) || empty($data[$idfield])) { $result->error(sprintf(_t("Checkout.IDFIELDNOTFOUND", "Required field not found: %s"), $idfield)); throw new ValidationException($result); } if (!isset($data['Password']) || empty($data['Password'])) { $result->error(_t("Checkout.PASSWORDREQUIRED", "A password is required")); throw new ValidationException($result); } $idval = $data[$idfield]; if (ShopMember::get_by_identifier($idval)) { $result->error(sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), _t("Member." . $idfield, $idfield), $idval)); throw new ValidationException($result); } $member = new Member(Convert::raw2sql($data)); $validation = $member->validate(); if (!$validation->valid()) { //TODO need to handle i18n here? $result->error($validation->message()); } if (!$result->valid()) { throw new ValidationException($result); } return $member; }
protected function tearDown() { Author::deleteAll(); Book::deleteAll(); Checkout::deleteAll(); Patron::deleteAll(); }
function test_getCheckouts() { //Arrange $name = "Jerald the crotchety grandpa"; $test_patron = new Patron($name); $test_patron->save(); $checked_in_status = 0; $due_date = "1234-12-12"; $copy_id = 5; $new_checkout = new Checkout($checked_in_status, $due_date, $copy_id, $test_patron->getId()); $new_checkout->save(); //Act $result = $test_patron->getCheckouts(); //Assert $this->assertEquals([$new_checkout], $result); }
public function is_active($country = 0) { global $temp_orders_id; $temp_data = Checkout::get_all_data_from_temp_db($temp_orders_id); foreach ($this->instances as $data) { if ($data['status'] == 'true') { if ($temp_orders_id > 0) { if ($country > 0) { if (parent::checkZone($data['zone'], $country)) { return true; } } else { if (parent::checkZone($data['zone'], $temp_data[$temp_orders_id]['orders']['delivery_country'])) { return true; } } } else { if ($country > 0) { if (parent::checkZone($data['zone'], $country)) { return true; } } else { return true; } } } } return false; }
public function run() { parent::run(); $assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets', false, -1, true); $cs = Yii::app()->clientScript; $cs->registerCssFile($assets . '/css/wsaddtocartmodal.css'); Yii::app()->clientScript->registerScript('instantiate checkout', sprintf('$(document).ready(function () { checkout = new Checkout(%s); });', Checkout::getCheckoutJSOptions()), CClientScript::POS_HEAD); // No item added to cart. if (empty($this->objCartItem)) { return; } $this->objCart = Yii::app()->shoppingcart; $this->intItemCount = Yii::app()->shoppingcart->totalItemCount; $this->strItems = $this->intItemCount > 1 ? Yii::t('cart', 'items') : Yii::t('cart', 'item'); $arrItems = Yii::app()->shoppingcart->cartItems; if (count($arrItems)) { $this->intImageID = $this->objCartItem->Prod->image_id; $dataProvider = $this->objCartItem->Prod->related(); $arrRel = $dataProvider->Data; $dataProvider = $this->objCartItem->Prod->autoadd(); $arrAuto = $dataProvider->Data; $arr = array_merge($arrAuto, $arrRel); // right now we only want 3 related items at most while (count($arr) > $this->intCountRelated) { array_pop($arr); } $this->arrObjRelated = $arr; } else { $this->objCartItem = new CartItem(); // empty object } $this->render('addtocartmodal'); }
public function getPasswordFields() { $loginlink = "Security/login?BackURL=" . CheckoutPage::find_link(true); $fields = FieldList::create(HeaderField::create(_t('CheckoutField.MembershipDetails', 'Membership Details'), 3), LiteralField::create('MemberInfo', '<p class="message warning">' . _t('CheckoutField.MemberLoginInfo', 'If you are already a member please <a href="{LoginUrl}">log in</a>', '', array('LoginUrl' => $loginlink)) . '</p>'), LiteralField::create('AccountInfo', '<p>' . _t('CheckoutField.AccountInfo', 'Please choose a password, so you can login and check your order history in the future') . '</p>'), $pwf = $this->getPasswordField()); if (!Checkout::user_membership_required()) { $pwf->setCanBeEmpty(true); } return $fields; }
public function getPasswordFields() { $loginlink = "Security/login?BackURL=" . CheckoutPage::find_link(true); $fields = FieldList::create(HeaderField::create(_t('CheckoutField.MEMBERSHIPDETAILS', 'Membership Details'), 3), LiteralField::create('MemberInfo', '<p class="message warning">' . _t('CheckoutField.MEMBERINFO', 'If you are already a member please') . " <a href=\"{$loginlink}\">" . _t('OrderForm.LogIn', 'log in') . '</a>.' . '</p>'), LiteralField::create('AccountInfo', '<p>' . _t('CheckoutField.ACCOUNTINFO', 'Please choose a password, so you can login and check your order history in the future') . '</p>'), $this->getPasswordField()); if (!Checkout::user_membership_required()) { $pwf->setCanBeEmpty(true); } return $fields; }
public function getData(Order $order) { $data = array(); $gateway = Checkout::get($order)->getSelectedPaymentMethod(); //provide valid dummy credit card data if ($gateway === "Dummy") { $data = array_merge(array('name' => 'Joe Bloggs', 'number' => '4242424242424242', 'cvv' => 123), $data); } return $data; }
/** * @param Order $order * * @return \Omnipay\Common\AbstractGateway|\Omnipay\Braintree\Gateway */ protected function getGateway($order) { if (!isset($this->gateway)) { $tempPayment = new Payment(['Gateway' => Checkout::get($order)->getSelectedPaymentMethod(false)]); $service = PurchaseService::create($tempPayment); $this->gateway = $service->oGateway(); $this->isBraintree = $this->gateway instanceof \Omnipay\Braintree\Gateway; } return $this->gateway; }
function test_deleteAll() { //Arrange $copy_id = 1; $patron_id = 4; $due_date = "2015-09-03"; $test_checkout = new Checkout($copy_id, $patron_id, $due_date); $test_checkout->save(); $copy_id2 = 2; $patron_id2 = 1; $due_date2 = "2015-10-05"; $test_checkout2 = new Checkout($copy_id2, $patron_id2, $due_date2); $test_checkout2->save(); //Act Checkout::deleteAll(); //Assert $result = Checkout::getAll(); $this->assertEquals([], $result); }
static function findDueDate($search_id) { $found_checkout = null; $checkouts = Checkout::getAll(); foreach ($checkouts as $checkout) { $checkout_id = $checkout->getId(); if ($checkout_id == $search_id) { $found_checkout = $checkout; } } return $found_checkout; }
/** * */ function onHook() { global $application; $request =& $application->getInstance("Request"); # , CCInfo if ($paymentModule = $request->getValueByKey("paymentModule")) { $pm_id = $paymentModule["method_code"]; $mmObj =& $application->getInstance('Modules_Manager'); $mmObj->includeAPIFileOnce("Checkout"); Checkout::AdditionalPersonInfoSetCurrStepHook($pm_id); } modApiFunc("Checkout", "saveState"); }
public function is_active() { global $temp_orders_id; $temp_data = Checkout::get_all_data_from_temp_db($temp_orders_id); foreach ($this->instances as $data) { if ($data['status'] == 'true') { if (parent::checkZone($data['zone'], $temp_data[$temp_orders_id]['orders']['billing_country']) && parent::checkShippingMethod($data['shipping_module'])) { return true; } } } return false; }
public function onBeforeInit() { $controller = $this->owner->request->param("Controller"); $action = $this->owner->request->param("Action"); if ($controller != "DevelopmentAdmin" && $action != "build") { $config = SiteConfig::current_site_config(); // Set the default currency symbol for this site Currency::config()->currency_symbol = Checkout::config()->currency_symbol; // Auto inject the order prefix to the orders module if it exists if (class_exists("Order") && class_exists("SiteConfig") && $config) { Order::config()->order_prefix = $config->PaymentNumberPrefix; } } }
public function index($request) { $this->extend('onBeforeIndex'); $site = SiteConfig::current_site_config(); $order = $this->getOrderData(); $cart = ShoppingCart::get(); // Setup the paypal gateway URL if (Director::isDev()) { $gateway_url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; } else { $gateway_url = "https://www.paypal.com/cgi-bin/webscr"; } $callback_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "callback", $this->payment_gateway->ID); $success_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete'); $error_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', 'error'); $back_url = Controller::join_links(Director::absoluteBaseURL(), Checkout_Controller::config()->url_segment, "finish"); $fields = new FieldList(HiddenField::create('business', null, $this->payment_gateway->BusinessID), HiddenField::create('item_name', null, $site->Title), HiddenField::create('cmd', null, "_cart"), HiddenField::create('paymentaction', null, "sale"), HiddenField::create('invoice', null, $order->OrderNumber), HiddenField::create('custom', null, $order->OrderNumber), HiddenField::create('upload', null, 1), HiddenField::create('discount_amount_cart', null, number_format($cart->DiscountAmount, 2)), HiddenField::create('currency_code', null, Checkout::config()->currency_code), HiddenField::create('first_name', null, $order->FirstName), HiddenField::create('last_name', null, $order->Surname), HiddenField::create('address1', null, $order->Address1), HiddenField::create('address2', null, $order->Address2), HiddenField::create('city', null, $order->City), HiddenField::create('zip', null, $order->PostCode), HiddenField::create('country', null, $order->Country), HiddenField::create('email', null, $order->Email), HiddenField::create('return', null, $success_url), HiddenField::create('notify_url', null, $callback_url), HiddenField::create('cancel_return', null, $error_url)); if (!Checkout::config()->simple_checkout && !$cart->isCollection()) { // Shipping Details $fields->add(HiddenField::create('shipping_addressee_name', null, $order->DeliveryFirstnames . " " . $order->DeliverySurname)); $fields->add(HiddenField::create('shipping_address1', null, $order->DeliveryAddress1)); $fields->add(HiddenField::create('shipping_address2', null, $order->DeliveryAddress2)); $fields->add(HiddenField::create('shipping_city', null, $order->DeliveryCity)); $fields->add(HiddenField::create('shipping_zip', null, $order->DeliveryPostCode)); $fields->add(HiddenField::create('shipping_country', null, $order->DeliveryCountry)); } $i = 1; foreach ($cart->getItems() as $item) { $fields->add(HiddenField::create('item_name_' . $i, null, $item->Title)); $fields->add(HiddenField::create('amount_' . $i, null, number_format($item->Price, 2))); $fields->add(HiddenField::create('quantity_' . $i, null, $item->Quantity)); $i++; } if (!Checkout::config()->simple_checkout && !$cart->isCollection()) { // Add shipping as an extra product $fields->add(HiddenField::create('item_name_' . $i, null, $order->PostageType)); $fields->add(HiddenField::create('amount_' . $i, null, number_format($cart->PostageCost, 2))); $fields->add(HiddenField::create('quantity_' . $i, null, "1")); } // Add tax (if needed) else just total if ($cart->TaxCost) { $fields->add(HiddenField::create('tax_cart', null, number_format($cart->TaxCost, 2))); } $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red checkout-action-back">' . _t('Checkout.Back', 'Back') . '</a>'), FormAction::create('Submit', _t('Checkout.ConfirmPay', 'Confirm and Pay'))->addExtraClass('btn')->addExtraClass('btn-green')); $form = Form::create($this, 'Form', $fields, $actions)->addExtraClass('forms')->setFormMethod('POST')->setFormAction($gateway_url); $this->customise(array("Title" => _t('Checkout.Summary', "Summary"), "MetaTitle" => _t('Checkout.Summary', "Summary"), "Form" => $form, "Order" => $order)); $this->extend('onAfterIndex'); return $this->renderWith(array("PayPal", "Payment", "Checkout", "Page")); }
/** * Behaviour can be overwritten by creating a processPaymentResponse method * on the controller owning this form. It takes a Symfony\Component\HttpFoundation\Response argument, * and expects an SS_HTTPResponse in return. */ public function submitpayment($data, $form) { $data = $form->getData(); if ($this->getSuccessLink()) { $data['returnUrl'] = $this->getSuccessLink(); } $data['cancelUrl'] = $this->getFailureLink() ? $this->getFailureLink() : $this->controller->Link(); $order = $this->config->getOrder(); //final recalculation, before making payment $order->calculate(); //handle cases where order total is 0. Note that the order will appear //as "paid", but without a Payment record attached. if ($order->GrandTotal() == 0 && Order::config()->allow_zero_order_total) { if (!$this->orderProcessor->placeOrder()) { $form->sessionMessage($this->orderProcessor->getError()); return $this->controller->redirectBack(); } return $this->controller->redirect($this->getSuccessLink()); } //try to place order before payment, if configured if (Order::config()->place_before_payment) { if (!$this->orderProcessor->placeOrder()) { $form->sessionMessage($this->orderProcessor->getError()); return $this->controller->redirectBack(); } $data['cancelUrl'] = $this->orderProcessor->getReturnUrl(); } $paymentResponse = $this->orderProcessor->makePayment(Checkout::get($order)->getSelectedPaymentMethod(false), $data); $response = null; if ($paymentResponse) { if ($this->controller->hasMethod('processPaymentResponse')) { $response = $this->controller->processPaymentResponse($paymentResponse, $form); } else { if ($paymentResponse->isRedirect() || $paymentResponse->isSuccessful()) { $response = $paymentResponse->redirect(); } else { $form->sessionMessage($paymentResponse->getMessage(), 'bad'); $response = $this->controller->redirectBack(); } } } else { $form->sessionMessage($this->orderProcessor->getError(), 'bad'); $response = $this->controller->redirectBack(); } return $response; }
public function run() { parent::run(); $cs = Yii::app()->clientScript; $this->assetUrl = $assets = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets'); $cs->registerCssFile('//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'); $cs->registerCssFile($assets . '/css/wseditcartmodal.css'); $this->widget('ext.jquery-history-js.jqueryHistoryJs'); Yii::app()->clientScript->registerScript('instantiate checkout', sprintf('$(document).ready(function () { checkout = new Checkout(%s); });', Checkout::getCheckoutJSOptions()), CClientScript::POS_HEAD); Yii::app()->clientScript->registerScript('instantiate wsEditCartModal', sprintf('$(document).ready(function () { wsEditCartModal = new WsEditCartModal(%s); wsEditCartModal.checkout = checkout; });', CJSON::encode(array('checkoutUrl' => Yii::app()->createUrl('checkout'), 'updateCartItemEndpoint' => Yii::app()->createUrl('cart/updatecartitem'), 'csrfToken' => Yii::app()->request->csrfToken, 'cartId' => CHtml::activeId('EditCart', 'promoCode'), 'invalidQtyMessage' => Yii::t('checkout', '<strong>Only {qty} are available at this time.</strong><br> If you’d like ' . 'to order more please return at a later time or contact us.')))), CClientScript::POS_HEAD); $this->render('editcartmodal'); }
function testAddCheckout() { $title = "Three Blind Mice"; $test_book = new Book($title); $test_book->save(); $test_copy = new Copy($amount = 1, $test_book->getId()); $test_copy->save(); $name = "Joe Bongtana"; $test_patron = new Patron($name); $test_patron->save(); $due_date = "01-01-2016"; $status = 1; $test_checkout = new Checkout($test_copy->getId(), $test_patron->getId(), $due_date, $status); $test_checkout->save(); $test_patron->addCheckout($test_checkout); $result = Checkout::getAll(); $this->assertEquals($test_checkout, $result); }
public function process_data() { global $temp_orders_id, $currencies, $cart; $strlen = strlen(get_class($this)); if ($temp_orders_id == 0) { $temp_orders_id = Checkout::create_order(); } $ot_query = tep_db_query('SELECT orders_total_id FROM temp_orders_total WHERE orders_id = "' . $temp_orders_id . '" AND class="' . $this->type . '"'); if (tep_db_num_rows($ot_query) > 0) { tep_db_query('UPDATE temp_orders_total SET title="' . Translate($this->config['title']) . '", text="' . $currencies->display_price($cart->show_total(), 0) . '", value="' . $cart->show_total() . '", sort_order="' . $this->config['sort_order'] . '" WHERE orders_id = "' . $temp_orders_id . '" AND class="' . $this->type . '"'); } else { tep_db_query('INSERT INTO temp_orders_total (orders_id, title, text, value, class, sort_order) VALUES ("' . $temp_orders_id . '", "' . Translate($this->config['title']) . '", "' . $currencies->display_price($cart->show_total(), 0) . '", "' . $cart->show_total() . '", "' . $this->type . '", "' . $this->config['sort_order'] . '")'); } if (extension_loaded('apc') && ini_get('apc.enabled')) { apc_delete('temp_orders_total_' . $temp_orders_id); } return true; }
/** * Process the callback data from the payment provider */ public function callback($request) { if (Director::isDev()) { $secret_key = StripePayment::config()->test_secret_key; $publish_key = StripePayment::config()->test_publish_key; } else { $secret_key = StripePayment::config()->live_secret_key; $publish_key = StripePayment::config()->live_publish_key; } Stripe::setApiKey($secret_key); $site = SiteConfig::current_site_config(); $order = $this->getOrderData(); $cart = ShoppingCart::get(); $this->extend('onBeforeCallback'); $error_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', 'error'); $data = $this->request->postVars(); $status = "error"; // Get the credit card details submitted by the form $token = $data['stripeToken']; $order_no = Session::get("StripePayment.OrderNumber"); $order = Estimate::get()->filter("OrderNumber", $order_no)->first(); if ($order_no && $order) { // Create the charge on Stripe's servers - this will charge // the user's card try { $success_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', $order_no); $charge = StripeCharge::create(array("amount" => round($order->Total->Value * 100), "currency" => strtolower(Checkout::config()->currency_code), "source" => $token, "metadata" => array("Order" => $order_no))); $order->convertToOrder(); $order->write(); $order = Order::get()->byID($order->ID); $order->Status = "paid"; $order->PaymentProvider = "Stripe"; $order->PaymentNo = $charge->id; $order->write(); return $this->redirect($success_url); } catch (Exception $e) { $order->Status = "failed"; $order->write(); return $this->redirect($error_url); } } else { return $this->redirect($error_url); } }
public function index($request) { $this->extend('onBeforeIndex'); // Setup payment gateway form $order = $this->getOrderData(); $cart = ShoppingCart::get(); // Setup the gateway URL if (Director::isDev()) { $gateway_url = "https://secure-test.worldpay.com/wcc/purchase"; } else { $gateway_url = "https://secure.worldpay.com/wcc/purchase "; } $callback_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "callback", $this->payment_gateway->ID); $back_url = Controller::join_links(Director::absoluteBaseURL(), Checkout_Controller::config()->url_segment, "finish"); $fields = FieldList::create(HiddenField::create('instId', null, $this->payment_gateway->InstallID), HiddenField::create('cartId', null, $order->OrderNumber), HiddenField::create('MC_callback', null, $callback_url), HiddenField::create('amount', null, number_format($cart->TotalCost, 2)), HiddenField::create('currency', null, Checkout::config()->currency_code), HiddenField::create('name', null, $order->FirstName . " " . $order->Surname), HiddenField::create('address1', null, $order->Address1), HiddenField::create('address2', null, $order->Address2), HiddenField::create('town', null, $order->City), HiddenField::create('region', null, $order->Country), HiddenField::create('postcode', null, $order->PostCode), HiddenField::create('country', null, $order->Country), HiddenField::create('email', null, $order->Email), HiddenField::create('tel', null, $order->PhoneNumber)); // Create a string of items ordered (to manage the order via WorldPay) $desc_string = ""; foreach ($cart->getItems() as $item) { $desc_string .= $item->Title . ' x ' . $item->Quantity . ', '; } if (!Checkout::config()->simple_checkout && !$cart->isCollection()) { // Add postage type to description $desc_string .= _t("Checkout.Postage", "Postage") . ': ' . $order->PostageType . '; '; // Add postage address to description $desc_string .= _t("Checkout.PostTo", "Post to") . ': '; $desc_string .= $order->DeliveryFirstnames . " " . $order->DeliverySurname . ', '; $desc_string .= $order->DeliveryAddress1 . ', '; $desc_string .= $order->DeliveryAddress2 ? $order->DeliveryAddress2 . ', ' : ''; $desc_string .= $order->DeliveryCity . ', '; $desc_string .= $order->DeliveryCountry ? $order->DeliveryCountry . ', ' : ''; $desc_string .= $order->DeliveryPostCode . ', '; $desc_string .= $order->DeliveryCountry; } $fields->add(HiddenField::create('desc', null, $desc_string)); if (Director::isDev()) { $fields->add(HiddenField::create('testMode', null, '100')); } $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red checkout-action-back">' . _t('Checkout.Back', 'Back') . '</a>'), FormAction::create('Submit', _t('Checkout.ConfirmPay', 'Confirm and Pay'))->addExtraClass('btn')->addExtraClass('btn-green')); $form = Form::create($this, 'Form', $fields, $actions)->addExtraClass('forms')->setFormMethod('POST')->setFormAction($gateway_url); $this->customise(array("Title" => _t('Checkout.Summary', "Summary"), "MetaTitle" => _t('Checkout.Summary', "Summary"), "Form" => $form, "Order" => $order)); $this->extend("onAfterIndex"); return $this->renderWith(array("Worldpay", "Payment", "Checkout", "Page")); }
public function index($request) { $this->extend('onBeforeIndex'); // Setup payment gateway form $site = SiteConfig::current_site_config(); $order = $this->getOrderData(); $cart = ShoppingCart::get(); $pw = $this->payment_gateway->SHA; $sha_data = ""; // Setup the gateway URL if (Director::isDev()) { $gateway_url = "https://mdepayments.epdq.co.uk/ncol/test/orderstandard.asp"; } else { $gateway_url = "https://payments.epdq.co.uk/ncol/prod/orderstandard.asp"; } $success_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete'); $error_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', 'error'); $back_url = Controller::join_links(Director::absoluteBaseURL(), Checkout_Controller::config()->url_segment, "finish"); $template_url = Controller::join_links(Director::absoluteBaseURL(), "BarclaycardEpdqDynamicTemplate"); // Get an array of details, so we can generate a hash and convert // to hidden fields $data = array("PSPID" => $this->payment_gateway->PSPID, "ORDERID" => $order->OrderNumber, "AMOUNT" => round($cart->TotalCost * 100), "CURRENCY" => Checkout::config()->currency_code, "LANGUAGE" => i18n::get_locale(), "CN" => $order->FirstName . " " . $order->Surname, "EMAIL" => $order->Email, "OWNERADDRESS" => $order->Address1, "OWNERTOWN" => $order->City, "OWNERZIP" => $order->PostCode, "OWNERCTY" => $order->Country, "TITLE" => $site->Title, "BGCOLOR" => $this->payment_gateway->Background, "TXTCOLOR" => $this->payment_gateway->Text, "TBLBGCOLOR" => $this->payment_gateway->TableBackground, "TBLTXTCOLOR" => $this->payment_gateway->TableText, "BUTTONBGCOLOR" => $this->payment_gateway->ButtonBackground, "BUTTONTXTCOLOR" => $this->payment_gateway->ButtonText, "ACCEPTURL" => $success_url, "DECLINEURL" => $error_url, "EXCEPTIONURL" => $error_url, "CANCELURL" => $error_url, "TP" => $template_url); // Account for the fact the phone number might not be set if ($order->PhoneNumber) { $data["OWNERTELNO"] = $order->PhoneNumber; } $fields = FieldList::create(); ksort($data); // Generate our SHA Key and add fields foreach ($data as $k => $v) { $fields->push(HiddenField::create($k, null, $v)); $sha_data .= sprintf("%s=%s%s", $k, $v, $pw); } $hashed_data = strtoupper(hash("sha1", $sha_data)); // Finally add out hashed data $fields->push(HiddenField::create("SHASign", null, $hashed_data)); $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red checkout-action-back">' . _t('Checkout.Back', 'Back') . '</a>'), FormAction::create('Submit', _t('Checkout.ConfirmPay', 'Confirm and Pay'))->addExtraClass('btn')->addExtraClass('btn-green')); $form = Form::create($this, 'Form', $fields, $actions)->addExtraClass('forms')->setFormMethod('POST')->setFormAction($gateway_url); $this->customise(array("Title" => _t('Checkout.Summary', "Summary"), "MetaTitle" => _t('Checkout.Summary', "Summary"), "Form" => $form, "Order" => $order)); $this->extend("onAfterIndex"); return $this->renderWith(array("BarclaysEpqd", "Payment", "Checkout", "Page")); }
function asc_ctor($parameter) { loadCoreFile('UUIDUtils.php'); $payment_module_id = $parameter; // javaScript . $parameter = UUIDUtils::convert("minuses_and_capitals", "js", $parameter); // checkout prerequisite' , Person Info (e.g. CustomerInfo) $this->CHECKOUT_PREREQUISITE_NAME = Checkout::getAdditionalPrerequisiteName("bankAccountInfo", $payment_module_id); // store , checkout prerequisite' . $this->CHECKOUT_STORE_BLOCK_NAME = "bank-account-info-input" . $parameter; // html , Person Info. $this->HTML_TAGS_PREFIX = "BankAccountInfo" . $parameter; // html , Person Info. // . Container . $this->HTML_TAGS_PREFIX_WITHOUT_MODULE_UID = "BankAccountInfo"; // . . (e.g. CheckoutCustomerInfoInput) $this->BLOCK_TAG_NAME = "CheckoutBankAccountInfoInput" . $parameter; // , // : $this->{get_parent_class(__CLASS__)}(); }
public function index($request) { $this->extend("onBeforeIndex"); $site = SiteConfig::current_site_config(); $order = $this->getOrderData(); $cart = ShoppingCart::get(); $key = $this->payment_gateway->ConfigKey; $merchant_id = Director::isDev() ? "TEST" : $this->payment_gateway->MerchantID; $callback_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "callback", $this->payment_gateway->ID); $return_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete'); $back_url = Controller::join_links(Director::absoluteBaseURL(), Checkout_Controller::config()->url_segment, "finish"); $payment_details = array('username' => $this->payment_gateway->Username, 'password' => $this->payment_gateway->Password, 'biller_code' => $this->payment_gateway->BillerCode, 'merchant_id' => $merchant_id, 'receipt_address' => $order->Email, 'payment_amount' => number_format($cart->TotalCost, 2), 'payment_reference' => $order->OrderNumber, 'payment_reference_minimum_length' => 10, 'payment_reference_maximum_length' => 20, 'payment_reference_text' => _t("PayWay.PaymentReferenceText", "Order Number"), 'return_link_url' => $return_url, 'reply_link_url' => $callback_url, 'reply_link_email' => $this->payment_gateway->PaymentReplyEmail, 'reply_link_post_type' => 'extended'); foreach ($cart->getItems() as $item) { $payment_details[$item->Title] = $item->Quantity . ',' . number_format($item->Price, 2); } if (!Checkout::config()->simple_checkout) { $payment_details[$order->PostageType] = number_format($cart->PostageCost, 2); } // Add tax (if needed) else just total if ($cart->TaxCost) { $payment_details[_t("PayWay.Tax", 'Tax')] = number_format($cart->TaxCost, 2); } // If we cannot get payway's token, generate a friendly error try { $token = $this->get_token($payment_details); } catch (Exception $e) { error_log("Exception caught: " . $e->getMessage()); $content = "<p>"; $content = _t("PayWay.UnableToPayContent", "Please return to the previous page and try again"); $content = "</p>"; $content = '<p><a href="' . $back_url . '" class="btn">Back</a></p>'; $this->customise(array("Title" => _t("PayWay.UnableToPay", "Unable to take payment"), "MetaTitle" => _t("PayWay.UnableToPay", "Unable to take payment"), "Content" => $content)); return $this->renderWith(array("Page")); } $hand_off_url = Controller::join_links($this->config()->gateway_url, "MakePayment"); $hand_off_url .= "?biller_code=" . $this->payment_gateway->BillerCode; $hand_off_url .= "&token=" . urlencode($token); $this->extend('onAfterIndex'); return $this->redirect($hand_off_url); }
public function index($request) { $this->extend('onBeforeIndex'); $site = SiteConfig::current_site_config(); $order = $this->getOrderData(); $cart = ShoppingCart::get(); $key = $this->payment_gateway->ConfigKey; $sofort = new SofortMultipayPayment($key); $sofort->setAmount(number_format($cart->TotalCost, 2)); $sofort->setCurrencyCode(Checkout::config()->currency_code); $callback_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, "callback", $this->payment_gateway->ID); $success_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', $order->OrderNumber); $error_url = Controller::join_links(Director::absoluteBaseURL(), Payment_Controller::config()->url_segment, 'complete', 'error'); $back_url = Controller::join_links(Director::absoluteBaseURL(), Checkout_Controller::config()->url_segment, "finish"); $sofort->setSuccessUrl($success_url, true); $sofort->setAbortUrl($error_url); $sofort->setNotificationUrl($callback_url); $desc_string = ""; foreach ($cart->getItems() as $item) { $desc_string .= $item->Title . ' x ' . $item->Quantity . ', '; } $sofort->setReason($desc_string); $sofort->sendRequest(); $fields = new FieldList(); $i = 1; $actions = FieldList::create(LiteralField::create('BackButton', '<a href="' . $back_url . '" class="btn btn-red checkout-action-back">' . _t('Checkout.Back', 'Back') . '</a>')); $form = Form::create($this, 'Form', $fields, $actions)->addExtraClass('forms')->setFormMethod('GET'); if ($sofort->getPaymentUrl()) { $actions->add(FormAction::create('Submit', _t('Checkout.ConfirmPay', 'Confirm and Pay'))->addExtraClass('btn')->addExtraClass('btn-green')); $form->setFormAction($sofort->getPaymentUrl()); // Set the Payment No to our order data (accessable by // onAfterIndex) $order->PaymentID = $sofort->getTransactionId(); } else { $actions->add(LiteralField::create('BackButton', '<strong class="error">' . _t('Sofort.TransactionError', 'Error with transaction') . '</strong>')); } $this->customise(array("Title" => _t('Checkout.Summary', "Summary"), "MetaTitle" => _t('Checkout.Summary', "Summary"), "Form" => $form, "Order" => $order)); $this->extend("onAfterIndex"); return $this->renderWith(array("Sofort", "Payment", "Checkout", "Page")); }