public function getFormFields(Order $order)
 {
     $gateway = Checkout::get($order)->getSelectedPaymentMethod();
     $gatewayfieldsfactory = new GatewayFieldsFactory($gateway, array('Card'));
     $fields = $gatewayfieldsfactory->getCardFields();
     if ($gateway === "Dummy") {
         $fields->unshift(LiteralField::create("dummypaymentmessage", "<p class=\"message good\">Dummy data has been added to the form for testing convenience.</p>"));
     }
     return $fields;
 }
 /**
  * Make sure all omnipay fields are required
  *
  * @todo: make this more flexible
  *
  * @return RequiredFields
  */
 public function getRequiredFields()
 {
     $required = parent::getRequiredFields();
     $gateway = $this->data()->PaymentGateway;
     $fieldgroups = $this->getPaymentFieldsGroupArray();
     $factory = new GatewayFieldsFactory($gateway, $fieldgroups);
     $fields = $factory->getFields();
     foreach ($fields as $field) {
         if (!$field->hasMethod('getName')) {
             continue;
         }
         $fieldname = $field->getName();
         if ($fieldname == "billingAddress2") {
             continue;
         }
         $required->addRequiredField($fieldname);
     }
     $paymentfieldname = $this->PaymentAmountField()->Name;
     $required->addRequiredField($paymentfieldname);
     return $required;
 }
 public function testFieldGroups()
 {
     $factory = new GatewayFieldsFactory("Dummy", array('Card', 'Billing', 'Shipping', 'Company', 'Email'));
     $fields = $factory->getFields();
     //TODO: assertions
 }
Example #4
0
 /**
  * Form for collecting gateway data.
  */
 public function GatewayDataForm()
 {
     $payment = $this->getCurrentPayment();
     if (!$payment) {
         //redirect if there is no payment object available
         return $this->redirect($this->Link());
     }
     $factory = new GatewayFieldsFactory($payment->Gateway);
     $fields = $factory->getFields();
     //TODO: never let CC details be stored in session (e.g. validation)
     //TODO: force requirement of SSL on live sites
     $actions = new FieldList($cancelaction = new FormAction("cancel", _t("PaymentController.DIFFERENTMETHOD", "Choose Different Method")), $payaction = new FormAction("pay", _t("PaymentController.DIFFERENTMETHOD", "Make Payment")));
     $cancelaction->setAttribute("formnovalidate", "formnovalidate");
     $validator = new RequiredFields(GatewayInfo::required_fields($payment->Gateway));
     $form = new Form($this, "GatewayDataForm", $fields, $actions, $validator);
     $this->extend('updateGatewayDataForm', $form);
     //allow cancel action to run without validation
     if (!empty($_REQUEST['action_cancel'])) {
         $form->unsetValidator();
     }
     return $form;
 }