/** * Show the "choose payment method" form */ function ProcessForm() { $fields = new FieldList(); // Create a dropdown select field for choosing gateway $supported_methods = PaymentProcessor::get_supported_methods(); $source = array(); foreach ($supported_methods as $methodName) { $methodConfig = PaymentFactory::get_factory_config($methodName); $source[$methodName] = $methodConfig['title']; } $fields->push(new DropDownField('PaymentMethod', 'Select Payment Method', $source)); $actions = new FieldList(new FormAction('proceed', 'Proceed')); $processForm = new Form($this, 'ProcessForm', $fields, $actions); $processForm->disableSecurityToken(); return $processForm; }
public function createFields() { $order = $this->order; $member = $this->customer; //Payment fields $supported_methods = PaymentProcessor::get_supported_methods(); $source = array(); foreach ($supported_methods as $methodName) { $methodConfig = PaymentFactory::get_factory_config($methodName); $source[$methodName] = $methodConfig['title']; } $outstanding = $order->TotalOutstanding()->Nice(); $paymentFields = CompositeField::create(new HeaderField(_t('CheckoutPage.PAYMENT', "Payment"), 3), LiteralField::create('RepayLit', "<p>Process a payment for the oustanding amount: {$outstanding}</p>"), DropDownField::create('PaymentMethod', 'Select Payment Method', $source)->setCustomValidationMessage(_t('CheckoutPage.SELECT_PAYMENT_METHOD', "Please select a payment method.")))->setName('PaymentFields'); $fields = FieldList::create($paymentFields); $this->extend('updateFields', $fields); $fields->setForm($this); return $fields; }
/** * Factory function to create payment processor object with associated * Payment and PaymentGateway injected into it. * * @param String $methodName * @return PaymentProcessor */ public static function factory($methodName) { $supported_methods = PaymentProcessor::get_supported_methods(); if (!in_array($methodName, $supported_methods)) { throw new Exception("The method {$methodName} is not supported"); } $methodConfig = self::get_factory_config($methodName); if (isset($methodConfig['processor'])) { $processorClass = $methodConfig['processor']; $processor = new $processorClass(); $processor->setMethodName($methodName); // Set the dependencies $processor->gateway = self::get_gateway($methodName); $processor->payment = self::get_payment_model($methodName); return $processor; } else { throw new Exception("No processor is defined for the method {$methodName}"); } }
public function createFields() { $order = $this->order; $member = $this->customer; //Personal details fields if (!$member->ID || $member->Password == '') { $link = $this->controller->Link(); $note = _t('CheckoutPage.NOTE', 'NOTE:'); $passwd = _t('CheckoutPage.PLEASE_CHOOSE_PASSWORD', 'Please choose a password, so you can login and check your order history in the future.'); $mber = sprintf(_t('CheckoutPage.ALREADY_MEMBER', 'If you are already a member please %s log in. %s'), "<a href=\"Security/login?BackURL={$link}\">", '</a>'); $personalFields = CompositeField::create(new HeaderField(_t('CheckoutPage.ACCOUNT', "Account"), 3), new CompositeField(EmailField::create('Email', _t('CheckoutPage.EMAIL', 'Email'))->setCustomValidationMessage(_t('CheckoutPage.PLEASE_ENTER_EMAIL_ADDRESS', "Please enter your email address."))), new CompositeField(new FieldGroup(new ConfirmedPasswordField('Password', _t('CheckoutPage.PASSWORD', "Password")))), new CompositeField(new LiteralField('AccountInfo', "\r\n\t\t\t\t\t\t<p class=\"alert alert-info\">\r\n\t\t\t\t\t\t\t<strong class=\"alert-heading\">{$note}</strong>\r\n\t\t\t\t\t\t\t{$passwd} <br /><br />\r\n\t\t\t\t\t\t\t{$mber}\r\n\t\t\t\t\t\t</p>\r\n\t\t\t\t\t\t")))->setID('PersonalDetails')->setName('PersonaDetails'); } //Order item fields $items = $order->Items(); $itemFields = CompositeField::create()->setName('ItemsFields'); if ($items) { foreach ($items as $item) { $itemFields->push(new OrderForm_ItemField($item)); } } //Order modifications fields $subTotalModsFields = CompositeField::create()->setName('SubTotalModificationsFields'); $subTotalMods = $order->SubTotalModifications(); if ($subTotalMods && $subTotalMods->exists()) { foreach ($subTotalMods as $modification) { $modFields = $modification->getFormFields(); foreach ($modFields as $field) { $subTotalModsFields->push($field); } } } $totalModsFields = CompositeField::create()->setName('TotalModificationsFields'); $totalMods = $order->TotalModifications(); if ($totalMods && $totalMods->exists()) { foreach ($totalMods as $modification) { $modFields = $modification->getFormFields(); foreach ($modFields as $field) { $totalModsFields->push($field); } } } //Payment fields $supported_methods = PaymentProcessor::get_supported_methods(); $source = array(); foreach ($supported_methods as $methodName) { $methodConfig = PaymentFactory::get_factory_config($methodName); $source[$methodName] = $methodConfig['title']; } $paymentFields = CompositeField::create(new HeaderField(_t('CheckoutPage.PAYMENT', "Payment"), 3), DropDownField::create('PaymentMethod', 'Select Payment Method', $source)->setCustomValidationMessage(_t('CheckoutPage.SELECT_PAYMENT_METHOD', "Please select a payment method.")))->setName('PaymentFields'); $fields = FieldList::create($itemFields, $subTotalModsFields, $totalModsFields, $notesFields = CompositeField::create(TextareaField::create('Notes', _t('CheckoutPage.NOTES_ABOUT_ORDER', "Notes about this order")))->setName('NotesFields'), $paymentFields); if (isset($personalFields)) { $fields->push($personalFields); } $this->extend('updateFields', $fields); $fields->setForm($this); return $fields; }