OnsitePaymentCheckoutComponent::getFormFields PHP Méthode

getFormFields() public méthode

public getFormFields ( Order $order )
$order Order
    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;
    }

Usage Example

 /**
  * Get form fields for manipulating the current order,
  * according to the responsibility of this component.
  *
  * @param Order $order
  * @param Form  $form
  *
  * @return FieldList
  */
 public function getFormFields(Order $order, Form $form = null)
 {
     $gateway = $this->getGateway($order);
     if (!$this->isBraintree) {
         return parent::getFormFields($order);
     }
     // Generate the token for the javascript to use
     $clientToken = $gateway->clientToken()->send()->getToken();
     // Generate the standard set of fields and allow it to be customised
     $fields = FieldList::create([LiteralField::create('BraintreePlaceholder', '<div id="braintree-ui"></div>'), HiddenField::create('payment_method_nonce', '', '')->setAttribute('data-braintree', 'nonce')]);
     $this->extend('updateFormFields', $fields);
     // Generate a basic config and allow it to be customised
     $config = ['id' => $form ? $form->getHTMLID() : 'PaymentForm_OrderForm', 'container' => 'braintree-ui'];
     $this->extend('updateBraintreeConfig', $config);
     $rawConfig = json_encode($config);
     $rawConfig = $this->injectCallbacks($rawConfig);
     $this->extend('updateRawBraintreeConfig', $rawConfig);
     // Finally, add the javascript to the page
     Requirements::javascript('https://js.braintreegateway.com/js/braintree-2.20.0.min.js');
     Requirements::customScript("braintree.setup('{$clientToken}', 'dropin', {$rawConfig});", 'BraintreeJS');
     return $fields;
 }