class Payment in Ubercart 8.4
Specify and collect payment for an order.
Plugin annotation
@UbercartOrderPane(
id = "payment",
title = @Translation("Payment"),
weight = 4,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\uc_order\OrderPanePluginBase implements OrderPanePluginInterface
- class \Drupal\uc_order\EditableOrderPanePluginBase implements EditableOrderPanePluginInterface
- class \Drupal\uc_payment\Plugin\Ubercart\OrderPane\Payment
- class \Drupal\uc_order\EditableOrderPanePluginBase implements EditableOrderPanePluginInterface
- class \Drupal\uc_order\OrderPanePluginBase implements OrderPanePluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Payment
3 string references to 'Payment'
- uc_payment.info.yml in payment/
uc_payment/ uc_payment.info.yml - payment/uc_payment/uc_payment.info.yml
- uc_payment.rules.events.yml in payment/
uc_payment/ uc_payment.rules.events.yml - payment/uc_payment/uc_payment.rules.events.yml
- uc_payment_views_data in payment/
uc_payment/ uc_payment.views.inc - Implements hook_views_data().
File
- payment/
uc_payment/ src/ Plugin/ Ubercart/ OrderPane/ Payment.php, line 23
Namespace
Drupal\uc_payment\Plugin\Ubercart\OrderPaneView source
class Payment extends EditableOrderPanePluginBase {
/**
* {@inheritdoc}
*/
public function getClasses() {
return [
'pos-left',
];
}
/**
* {@inheritdoc}
*/
public function view(OrderInterface $order, $view_mode) {
if ($view_mode != 'customer') {
$build['balance'] = [
'#markup' => $this
->t('Balance: @balance', [
'@balance' => uc_currency_format(uc_payment_balance($order)),
]),
];
$account = \Drupal::currentUser();
if ($account
->hasPermission('view payments')) {
$build['view_payments'] = [
'#type' => 'link',
'#prefix' => ' (',
'#title' => $this
->t('View'),
'#url' => Url::fromRoute('uc_payments.order_payments', [
'uc_order' => $order
->id(),
]),
'#suffix' => ')',
];
}
$method = \Drupal::service('plugin.manager.uc_payment.method')
->createFromOrder($order);
$build['method'] = [
'#markup' => $this
->t('Method: @payment_method', [
'@payment_method' => $method
->cartReviewTitle(),
]),
'#prefix' => '<br />',
];
$method_output = $method
->orderView($order);
if (!empty($method_output)) {
$build['output'] = $method_output + [
'#prefix' => '<br />',
];
}
}
else {
$method = \Drupal::service('plugin.manager.uc_payment.method')
->createFromOrder($order);
$build['method'] = [
'#markup' => $this
->t('Method: @payment_method', [
'@payment_method' => $method
->cartReviewTitle(),
]),
];
$method_output = $method
->customerView($order);
if (!empty($method_output)) {
$build['output'] = $method_output + [
'#prefix' => '<br />',
];
}
}
return $build;
}
/**
* {@inheritdoc}
*/
public function buildForm(OrderInterface $order, array $form, FormStateInterface $form_state) {
$options = [];
$methods = PaymentMethod::loadMultiple();
uasort($methods, 'Drupal\\uc_payment\\Entity\\PaymentMethod::sort');
foreach ($methods as $method) {
$options[$method
->id()] = $method
->label();
}
$form['payment_method'] = [
'#type' => 'select',
'#title' => $this
->t('Payment method'),
'#default_value' => $order
->getPaymentMethodId(),
'#options' => $options,
'#ajax' => [
'callback' => [
$this,
'ajaxCallback',
],
'progress' => [
'type' => 'throbber',
],
'wrapper' => 'payment-details',
],
];
// An empty <div> for Ajax.
$form['payment_details'] = [
'#type' => 'container',
'#attributes' => [
'id' => 'payment-details',
],
'#tree' => TRUE,
];
$method = $form_state
->getValue('payment_method') ?: $order
->getPaymentMethodId();
if ($method && ($details = PaymentMethod::load($method)
->getPlugin()
->orderEditDetails($order))) {
if (is_array($details)) {
$form['payment_details'] += $details;
}
else {
$form['payment_details']['#markup'] = $details;
}
}
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(OrderInterface $order, array &$form, FormStateInterface $form_state) {
$changes['payment_method'] = $form_state
->getValue('payment_method');
$changes['payment_details'] = $form_state
->getValue('payment_details') ?: [];
$order
->setPaymentMethodId($changes['payment_method']);
$method = \Drupal::service('plugin.manager.uc_payment.method')
->createFromOrder($order);
$return = $method
->orderEditProcess($order, $form, $form_state);
if (is_array($return)) {
$changes['payment_details'] = array_merge($changes['payment_details'], $return);
}
$order->payment_details = $changes['payment_details'];
}
/**
* AJAX callback to render the payment method pane.
*/
public function ajaxCallback($form, FormStateInterface $form_state) {
$response = new AjaxResponse();
$response
->addCommand(new ReplaceCommand('#payment-details', trim(drupal_render($form['payment']['payment_details']))));
$status_messages = [
'#type' => 'status_messages',
];
$response
->addCommand(new PrependCommand('#payment-details', drupal_render($status_messages)));
return $response;
}
}
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 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
OrderPanePluginBase:: |
public | function | ||
OrderPanePluginBase:: |
public | function |
Returns the title of an order pane. Overrides OrderPanePluginInterface:: |
2 |
Payment:: |
public | function | AJAX callback to render the payment method pane. | |
Payment:: |
public | function |
Form constructor. Overrides EditableOrderPanePluginInterface:: |
|
Payment:: |
public | function |
Returns the classes used to wrap an order pane. Overrides OrderPanePluginBase:: |
|
Payment:: |
public | function |
Form submission handler. Overrides EditableOrderPanePluginInterface:: |
|
Payment:: |
public | function |
Returns the contents of an order pane as a store administrator. Overrides OrderPanePluginInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |
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. |