class PaymentOffsiteForm in Commerce Core 8.2
Same name in this branch
- 8.2 modules/payment/src/PluginForm/PaymentOffsiteForm.php \Drupal\commerce_payment\PluginForm\PaymentOffsiteForm
- 8.2 modules/payment_example/src/PluginForm/OffsiteRedirect/PaymentOffsiteForm.php \Drupal\commerce_payment_example\PluginForm\OffsiteRedirect\PaymentOffsiteForm
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\PaymentOffsiteForm
- class \Drupal\commerce_payment_example\PluginForm\OffsiteRedirect\PaymentOffsiteForm
- class \Drupal\commerce_payment\PluginForm\PaymentOffsiteForm
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of PaymentOffsiteForm
File
- modules/
payment_example/ src/ PluginForm/ OffsiteRedirect/ PaymentOffsiteForm.php, line 10
Namespace
Drupal\commerce_payment_example\PluginForm\OffsiteRedirectView source
class PaymentOffsiteForm extends BasePaymentOffsiteForm {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = $this->entity;
/** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayInterface $payment_gateway_plugin */
$payment_gateway_plugin = $payment
->getPaymentGateway()
->getPlugin();
$redirect_method = $payment_gateway_plugin
->getConfiguration()['redirect_method'];
$remove_js = $redirect_method == 'post_manual';
if (in_array($redirect_method, [
'post',
'post_manual',
])) {
$redirect_url = Url::fromRoute('commerce_payment_example.dummy_redirect_post')
->toString();
$redirect_method = 'post';
}
else {
// Gateways that use the GET redirect method usually perform an API call
// that prepares the remote payment and provides the actual url to
// redirect to. Any params received from that API call that need to be
// persisted until later payment creation can be saved in $order->data.
// Example: $order->setData('my_gateway', ['test' => '123']), followed
// by an $order->save().
$order = $payment
->getOrder();
// Simulate an API call failing and throwing an exception, for test purposes.
// See PaymentCheckoutTest::testFailedCheckoutWithOffsiteRedirectGet().
if ($order
->getBillingProfile()
->get('address')->family_name == 'FAIL') {
throw new PaymentGatewayException('Could not get the redirect URL.');
}
$redirect_url = Url::fromRoute('commerce_payment_example.dummy_redirect_302', [], [
'absolute' => TRUE,
])
->toString();
}
$data = [
'return' => $form['#return_url'],
'cancel' => $form['#cancel_url'],
'total' => $payment
->getAmount()
->getNumber(),
];
$form = $this
->buildRedirectForm($form, $form_state, $redirect_url, $data, $redirect_method);
if ($remove_js) {
// Disable the javascript that auto-clicks the Submit button.
unset($form['#attached']['library']);
}
return $form;
}
}
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 |
Gets the form element to which errors should be assigned. Overrides PaymentGatewayFormInterface:: |
1 |
PaymentGatewayFormBase:: |
public | function |
Sets the form entity. Overrides PaymentGatewayFormInterface:: |
|
PaymentOffsiteForm:: |
public | function |
Form constructor. Overrides PaymentOffsiteForm:: |
|
PaymentOffsiteForm:: |
protected | function | Builds the redirect form. | |
PaymentOffsiteForm:: |
public static | function | Prepares the complete form for a POST redirect. | |
PaymentOffsiteForm:: |
constant | |||
PaymentOffsiteForm:: |
constant | |||
PaymentOffsiteForm:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
PluginFormBase:: |
protected | property | The plugin this form is for. | 3 |
PluginFormBase:: |
public | function |
Sets the plugin for this object. Overrides PluginAwareInterface:: |
1 |
PluginFormBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
2 |
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. |