class ExpressCheckoutForm in Commerce PayPal 8
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\ExpressCheckoutForm
- class \Drupal\commerce_payment\PluginForm\PaymentOffsiteForm
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of ExpressCheckoutForm
File
- src/
PluginForm/ ExpressCheckoutForm.php, line 9
Namespace
Drupal\commerce_paypal\PluginFormView source
class ExpressCheckoutForm 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_paypal\Plugin\Commerce\PaymentGateway\ExpressCheckoutInterface $payment_gateway_plugin */
$payment_gateway_plugin = $payment
->getPaymentGateway()
->getPlugin();
$extra = [
'return_url' => $form['#return_url'],
'cancel_url' => $form['#cancel_url'],
'capture' => $form['#capture'],
];
$paypal_response = $payment_gateway_plugin
->setExpressCheckout($payment, $extra);
// If we didn't get a TOKEN back from PayPal, then the
// $paypal_response['ACK'] == 'Failure', we need to exit checkout.
if (empty($paypal_response['TOKEN'])) {
throw new PaymentGatewayException(sprintf('[PayPal error #%s]: %s', $paypal_response['L_ERRORCODE0'], $paypal_response['L_LONGMESSAGE0']));
}
$order = $payment
->getOrder();
$order
->setData('paypal_express_checkout', [
'flow' => 'ec',
'token' => $paypal_response['TOKEN'],
'payerid' => FALSE,
'capture' => $extra['capture'],
]);
$order
->save();
$data = [
'token' => $paypal_response['TOKEN'],
'return' => $form['#return_url'],
'cancel' => $form['#cancel_url'],
'total' => $payment
->getAmount()
->getNumber(),
];
return $this
->buildRedirectForm($form, $form_state, $payment_gateway_plugin
->getRedirectUrl(), $data, 'get');
}
}
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 | |
ExpressCheckoutForm:: |
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. |