class PaymentMethodAddForm in Commerce Square Connect 8
Payment method add form for Square.
Hierarchy
- class \Drupal\Core\Plugin\PluginFormBase implements PluginAwareInterface, PluginFormInterface
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\commerce_payment\PluginForm\PaymentMethodFormBase implements ContainerInjectionInterface
- class \Drupal\commerce_payment\PluginForm\PaymentMethodAddForm
- class \Drupal\commerce_square\PluginForm\Square\PaymentMethodAddForm
- class \Drupal\commerce_payment\PluginForm\PaymentMethodAddForm
- class \Drupal\commerce_payment\PluginForm\PaymentMethodFormBase implements ContainerInjectionInterface
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of PaymentMethodAddForm
File
- src/
PluginForm/ Square/ PaymentMethodAddForm.php, line 13
Namespace
Drupal\commerce_square\PluginForm\SquareView source
class PaymentMethodAddForm extends BasePaymentMethodAddForm {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
/** @var \Drupal\commerce_square\Plugin\Commerce\PaymentGateway\Square $plugin */
$plugin = $this->plugin;
if ($plugin
->collectsBillingInformation()) {
$billing_information_inline_form = $form['billing_information']['#inline_form'];
assert($billing_information_inline_form instanceof CustomerProfile);
$billing_profile = $billing_information_inline_form
->getEntity();
if (!$billing_profile
->get('address')
->isEmpty()) {
$address = $billing_profile
->get('address')
->first();
assert($address instanceof AddressItem);
$form['#attached']['drupalSettings']['commerceSquare']['customerPostalCode'] = $address
->getPostalCode();
}
}
return $form;
}
/**
* {@inheritdoc}
*/
public function buildCreditCardForm(array $element, FormStateInterface $form_state) {
/** @var \Drupal\commerce_square\Plugin\Commerce\PaymentGateway\Square $plugin */
$plugin = $this->plugin;
$configuration = $plugin
->getConfiguration();
$config = \Drupal::config('commerce_square.settings');
$api_mode = $configuration['mode'] == 'test' ? 'sandbox' : 'production';
$element['#attached']['library'][] = 'commerce_square/form';
$element['#attached']['drupalSettings']['commerceSquare'] = [
'applicationId' => $config
->get($api_mode . '_app_id'),
'apiMode' => $api_mode,
'drupalSelector' => 'edit-' . str_replace('_', '-', implode('-', $element['#parents'])),
];
$element['#attributes']['class'][] = 'square-form';
// Populated by the JS library.
$element['payment_method_nonce'] = [
'#type' => 'hidden',
'#attributes' => [
'class' => [
'square-nonce',
],
],
];
$element['card_type'] = [
'#type' => 'hidden',
'#attributes' => [
'class' => [
'square-card-type',
],
],
];
$element['last4'] = [
'#type' => 'hidden',
'#attributes' => [
'class' => [
'square-last4',
],
],
];
$element['exp_month'] = [
'#type' => 'hidden',
'#attributes' => [
'class' => [
'square-exp-month',
],
],
];
$element['exp_year'] = [
'#type' => 'hidden',
'#attributes' => [
'class' => [
'square-exp-year',
],
],
];
$element['number'] = [
'#type' => 'item',
'#title' => t('Card number'),
'#markup' => '<div id="square-card-number"></div>',
];
$element['details'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'credit-card-form__expiration',
],
],
];
$element['details']['expiration'] = [
'#type' => 'item',
'#title' => t('Expiration'),
'#markup' => '<div id="square-expiration-date"></div>',
];
$element['details']['cvv'] = [
'#type' => 'item',
'#title' => t('CVV'),
'#markup' => '<div id="square-cvv"></div>',
];
$element['details']['postal-code'] = [
'#type' => 'item',
'#markup' => '<div id="square-postal-code"></div>',
];
return $element;
}
/**
* {@inheritdoc}
*/
protected function validateCreditCardForm(array &$element, FormStateInterface $form_state) {
// The JS library performs its own validation.
}
/**
* {@inheritdoc}
*/
public function submitCreditCardForm(array $element, FormStateInterface $form_state) {
// The payment gateway plugin will process the submitted payment details.
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
PaymentGatewayFormBase:: |
protected | property | The form entity. | |
PaymentGatewayFormBase:: |
public | function |
Gets the form entity. Overrides PaymentGatewayFormInterface:: |
|
PaymentGatewayFormBase:: |
public | function |
Sets the form entity. Overrides PaymentGatewayFormInterface:: |
|
PaymentMethodAddForm:: |
public | function |
Form constructor. Overrides PaymentMethodAddForm:: |
|
PaymentMethodAddForm:: |
public | function |
Builds the credit card form. Overrides PaymentMethodAddForm:: |
|
PaymentMethodAddForm:: |
protected | function | Builds the PayPal form. | |
PaymentMethodAddForm:: |
public | function |
Gets the form element to which errors should be assigned. Overrides PaymentGatewayFormBase:: |
|
PaymentMethodAddForm:: |
public | function |
Form submission handler. Overrides PaymentMethodFormBase:: |
|
PaymentMethodAddForm:: |
public | function |
Handles the submission of the credit card form. Overrides PaymentMethodAddForm:: |
|
PaymentMethodAddForm:: |
protected | function | Handles the submission of the PayPal form. | |
PaymentMethodAddForm:: |
public | function |
Form validation handler. Overrides PaymentMethodFormBase:: |
|
PaymentMethodAddForm:: |
protected | function |
Validates the credit card form. Overrides PaymentMethodAddForm:: |
|
PaymentMethodAddForm:: |
protected | function | Validates the PayPal form. | |
PaymentMethodFormBase:: |
protected | property | The current store. | |
PaymentMethodFormBase:: |
protected | property | The entity type manager. | |
PaymentMethodFormBase:: |
protected | property | The inline form manager. | |
PaymentMethodFormBase:: |
protected | property | The logger. | |
PaymentMethodFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
PaymentMethodFormBase:: |
public | function | Constructs a new PaymentMethodFormBase. | |
PluginFormBase:: |
protected | property | The plugin this form is for. | 3 |
PluginFormBase:: |
public | function |
Sets the plugin for this object. Overrides PluginAwareInterface:: |
1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |