/** * @param Form $form * * @return string */ public function generateFormID($form) { if ($id = $form->getHTMLID()) { return Convert::raw2htmlid($id); } return Convert::raw2htmlid(get_class($form) . '_' . str_replace(array('.', '/'), '', $form->getName())); }
/** * Get form fields for manipulating the current order, * according to the responsibilty 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([BraintreeHostedField::create('number', _t('BraintreePaymentCheckoutComponent.CardNumber', 'Debit/Credit Card Number')), BraintreeHostedField::create('cvv', _t('BraintreePaymentCheckoutComponent.CVV', 'Security Code')), BraintreeHostedField::create('expirationDate', _t('BraintreePaymentCheckoutComponent.ExpirationDate', 'Expiration Date (MM/YYYY)'))]); if ($this->config()->use_placeholders) { foreach ($fields as $field) { if ($field->Title()) { $field->setAttribute('placeholder', $field->Title())->setTitle(null); } } } $this->extend('updateFormFields', $fields); // Generate a basic config and allow it to be customised $config = ['id' => $form ? $form->getHTMLID() : 'PaymentForm_OrderForm', 'hostedFields' => $this->getFieldConfig($fields)]; $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}', 'custom', {$rawConfig});", 'BrainTreeJS'); return $fields; }
/** * @param Form $form * * @return string */ public function generateFormID($form) { if ($id = $form->getHTMLID()) { return Convert::raw2htmlid($id); } $reflection = new ReflectionClass($form); $shortName = str_replace(array('.', '/'), '', $form->getName()); return Convert::raw2htmlid($reflection->getShortName() . '_' . $shortName); }
/** * 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; }