class PayflowLinkForm in Commerce PayPal 8
Class PayflowLinkForm.
@package Drupal\commerce_paypal\PluginForm
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_paypal\PluginForm\PayflowLinkForm
- class \Drupal\commerce_payment\PluginForm\PaymentOffsiteForm
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of PayflowLinkForm
File
- src/
PluginForm/ PayflowLinkForm.php, line 15
Namespace
Drupal\commerce_paypal\PluginFormView source
class PayflowLinkForm extends BasePaymentOffsiteForm {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$configuration = $this->plugin
->getConfiguration();
$redirect_mode = $configuration['redirect_mode'];
// Return an error if the gateway's settings haven't been configured.
foreach ([
'partner',
'vendor',
'user',
'password',
] as $key) {
if (empty($configuration[$key])) {
throw new PaymentGatewayException($this
->t('Payflow Link is not configured for use. Please contact an administrator to resolve this issue.'));
}
}
/** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
$payment = $this->entity;
$order = $payment
->getOrder();
$mode = $configuration['mode'];
$commerce_payflow_data = [
'tokenid' => str_replace('.', '', uniqid('', TRUE)),
];
$order
->setData('commerce_payflow', $commerce_payflow_data);
// Request a token from Payflow Link.
$token = $this->plugin
->createSecureToken($order);
// If we got one back...
if (!empty($token)) {
// Set the Payflow Link data array and proceed to the redirect page.
$commerce_payflow_data['token'] = $token;
$order
->setData('commerce_payflow', $commerce_payflow_data);
$order
->save();
// Determine how to process the redirect based on the payment
// gateway's settings.
switch ($configuration['redirect_mode']) {
// For GET, redirect to Payflow Link with the parameters in the URL.
case 'get':
$redirect_url = $this->plugin
->getRedirectUrl($order);
if (empty($redirect_url)) {
throw new PaymentGatewayException($this
->t('Communication with PayPal failed. Please try again or contact an administrator to resolve the issue.'));
}
$redirect = new TrustedRedirectResponse($redirect_url);
$redirect
->send();
break;
// For POST, render a form that submits to the Payflow Link server.
case 'post':
$redirect_url = $this->plugin
->getRedirectUrl();
// Set the form to submit to Payflow Link.
$form['#action'] = $redirect_url;
// Add the Secure Token and Secure Token ID from the order's data.
$data = [
'SECURETOKEN' => $order
->getData('commerce_payflow')['token'],
'SECURETOKENID' => $order
->getData('commerce_payflow')['tokenid'],
];
// If 'test' mode, add the appropriate parameter.
if ($mode === 'test') {
$data['MODE'] = 'TEST';
}
// Add the parameters as hidden form elements to the form array.
foreach ($data as $name => $value) {
if (!empty($value)) {
$form[$name] = [
'#type' => 'hidden',
'#value' => $value,
];
}
}
break;
}
}
else {
// Clear the payment related information.
$order
->unsetData('commerce_payflow');
$order
->save();
// Show an error message and remain on the current page.
throw new PaymentGatewayException($this
->t('Communication with PayPal failed. Please try again or contact an administrator to resolve the issue.'));
}
$form = $this
->buildRedirectForm($form, $form_state, $redirect_url, $data, $redirect_mode);
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 | |
PayflowLinkForm:: |
public | function |
Form constructor. Overrides PaymentOffsiteForm:: |
|
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:: |
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. |