abstract class PayPalBasic in PayPal for Payment 8
Same name in this branch
- 8 src/Plugin/Payment/MethodConfiguration/PayPalBasic.php \Drupal\paypal_payment\Plugin\Payment\MethodConfiguration\PayPalBasic
- 8 src/Plugin/Payment/Method/PayPalBasic.php \Drupal\paypal_payment\Plugin\Payment\Method\PayPalBasic
Same name and namespace in other branches
- 2.0.x src/Plugin/Payment/Method/PayPalBasic.php \Drupal\paypal_payment\Plugin\Payment\Method\PayPalBasic
Abstract class for PayPal payment methods.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\payment\Plugin\Payment\Method\PaymentMethodBase implements ConfigurableInterface, DependentPluginInterface, CacheableDependencyInterface, ContainerFactoryPluginInterface, PluginFormInterface, PaymentMethodCapturePaymentInterface, PaymentMethodInterface, PaymentMethodRefundPaymentInterface uses PaymentAwareTrait
- class \Drupal\payment\Plugin\Payment\Method\Basic implements ContainerFactoryPluginInterface, PaymentMethodCapturePaymentInterface, PaymentMethodRefundPaymentInterface, PaymentMethodUpdatePaymentStatusInterface
- class \Drupal\paypal_payment\Plugin\Payment\Method\PayPalBasic
- class \Drupal\payment\Plugin\Payment\Method\Basic implements ContainerFactoryPluginInterface, PaymentMethodCapturePaymentInterface, PaymentMethodRefundPaymentInterface, PaymentMethodUpdatePaymentStatusInterface
- class \Drupal\payment\Plugin\Payment\Method\PaymentMethodBase implements ConfigurableInterface, DependentPluginInterface, CacheableDependencyInterface, ContainerFactoryPluginInterface, PluginFormInterface, PaymentMethodCapturePaymentInterface, PaymentMethodInterface, PaymentMethodRefundPaymentInterface uses PaymentAwareTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of PayPalBasic
3 files declare their use of PayPalBasic
- PayPalBasic.php in src/
Plugin/ Payment/ MethodConfiguration/ PayPalBasic.php - Redirect.php in src/
Controller/ Redirect.php - Webhook.php in src/
Controller/ Webhook.php
File
- src/
Plugin/ Payment/ Method/ PayPalBasic.php, line 22
Namespace
Drupal\paypal_payment\Plugin\Payment\MethodView source
abstract class PayPalBasic extends Basic {
const PAYPAL_CONTEXT_TYPE_ADMIN = 'admin';
const PAYPAL_CONTEXT_TYPE_CREATE = 'create';
const PAYPAL_CONTEXT_TYPE_WEBHOOK = 'webhook';
const PAYPAL_CONTEXT_TYPE_REDIRECT = 'redirect';
const PAYPAL_DEFAULT_CURRENCY = 'USD';
/**
* @var \Drupal\payment\Response\Response
*/
protected $paymentExecutionResult;
/**
* @return string
*/
public abstract function getWebhookUrl() : string;
/**
* @return string
*/
public abstract function getWebhookId() : string;
/**
* @param string $type
* @return \PayPal\Rest\ApiContext
*/
public abstract function getApiContext($type) : ApiContext;
/**
* @param $paymentId
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
private function setPaymentId($paymentId) {
$this->configuration['paymentID'] = $paymentId;
$this
->getPayment()
->save();
}
/**
* @return mixed|null
*/
public function getPaymentId() {
return $this->configuration['paymentID'] ?? NULL;
}
/**
* {@inheritdoc}
*/
public function getPaymentExecutionResult() {
return new OperationResult($this->paymentExecutionResult);
}
/**
* {@inheritdoc}
*/
protected function doExecutePayment() {
parent::doExecutePayment();
$payer = new Payer();
$payer
->setPaymentMethod('paypal');
$itemList = new ItemList();
$totalAmount = 0;
$currency = self::PAYPAL_DEFAULT_CURRENCY;
foreach ($this
->getPayment()
->getLineItems() as $line_item) {
$totalAmount += $line_item
->getTotalAmount();
$line_item_currency = $line_item
->getCurrencyCode();
$item = new Item();
$item
->setName($line_item
->getName())
->setCurrency($line_item_currency)
->setQuantity($line_item
->getQuantity())
->setPrice($line_item
->getAmount());
$itemList
->addItem($item);
if ($line_item_currency !== $currency) {
if ($currency !== self::PAYPAL_DEFAULT_CURRENCY) {
// This is the second time we are changing the currency which means
// that our line items have mixed currencies. This aion't gonna work!
# TODO: clarify with the payment maintainer how we should handle this
$this
->messenger()
->addError($this
->t('Mixed currencies detected which is not yet supported.'));
return;
}
$currency = $line_item_currency;
}
}
$redirectSuccess = new Url('paypal_payment.redirect.success', [
'payment' => $this
->getPayment()
->id(),
], [
'absolute' => TRUE,
]);
$redirectCancel = new Url('paypal_payment.redirect.cancel', [
'payment' => $this
->getPayment()
->id(),
], [
'absolute' => TRUE,
]);
$redirectUrls = new RedirectUrls();
$redirectUrls
->setReturnUrl($redirectSuccess
->toString(TRUE)
->getGeneratedUrl())
->setCancelUrl($redirectCancel
->toString(TRUE)
->getGeneratedUrl());
$amount = new Amount();
$amount
->setCurrency($currency)
->setTotal($totalAmount);
$transaction = new Transaction();
$transaction
->setAmount($amount)
->setItemList($itemList)
->setDescription($this
->getPayment()
->id())
->setInvoiceNumber($this
->getPayment()
->id())
->setNotifyUrl($this
->getWebhookUrl());
$payment = new Payment();
$payment
->setIntent('sale')
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions([
$transaction,
]);
try {
$payment
->create($this
->getApiContext(self::PAYPAL_CONTEXT_TYPE_CREATE));
$this
->setPaymentId($payment
->getId());
$url = Url::fromUri($payment
->getApprovalLink());
$this->paymentExecutionResult = new Response($url);
} catch (Exception $ex) {
# TODO: clarify with the payment maintainer how we should handle Exceptions
$this->paymentExecutionResult = NULL;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Basic:: |
protected | property | The payment status manager. | |
Basic:: |
public static | function |
Creates an instance of the plugin. Overrides PaymentMethodBase:: |
|
Basic:: |
public | function |
Performs the actual payment capture. Overrides PaymentMethodBase:: |
|
Basic:: |
public | function |
Performs a payment method-specific access check for payment capture. Overrides PaymentMethodBase:: |
|
Basic:: |
public | function |
Performs the actual payment refund. Overrides PaymentMethodBase:: |
|
Basic:: |
public | function |
Performs a payment method-specific access check for payment refunds. Overrides PaymentMethodBase:: |
|
Basic:: |
public | function | Gets whether or not capture is supported. | |
Basic:: |
public | function | Gets the status to set on payment capture. | |
Basic:: |
public | function | Gets the ID of the payment method this plugin is for. | |
Basic:: |
public | function | Gets the status to set on payment execution. | |
Basic:: |
public | function | Gets whether or not capture is supported. | |
Basic:: |
public | function | Gets the status to set on payment refund. | |
Basic:: |
public | function |
Returns the statuses that can be set on a payment. Overrides PaymentMethodUpdatePaymentStatusInterface:: |
|
Basic:: |
public | function |
Returns the supported currencies. Overrides PaymentMethodBase:: |
|
Basic:: |
public | function |
Checks if the payment status can be updated. Overrides PaymentMethodUpdatePaymentStatusInterface:: |
|
Basic:: |
public | function |
Constructs a new instance. Overrides PaymentMethodBase:: |
|
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. | |
PaymentAwareTrait:: |
protected | property | The payment. | |
PaymentAwareTrait:: |
public | function | ||
PaymentAwareTrait:: |
public | function | ||
PaymentMethodBase:: |
protected | property | The event dispatcher. | |
PaymentMethodBase:: |
protected | property | The module handler. | |
PaymentMethodBase:: |
protected | property | The token API. | |
PaymentMethodBase:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
PaymentMethodBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
PaymentMethodBase:: |
public | function |
Captures the payment. Overrides PaymentMethodCapturePaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Checks if the payment can be captured. Overrides PaymentMethodCapturePaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurableInterface:: |
|
PaymentMethodBase:: |
protected | function | Performs a payment method-specific access check for payment execution. | |
PaymentMethodBase:: |
public | function |
Executes the payment. Overrides PaymentMethodInterface:: |
|
PaymentMethodBase:: |
public | function |
Checks if the payment can be executed. Overrides PaymentMethodInterface:: |
|
PaymentMethodBase:: |
protected | function | Checks a payment's currency against this plugin. | |
PaymentMethodBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
PaymentMethodBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
PaymentMethodBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
PaymentMethodBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PaymentMethodBase:: |
public | function | Gets the payer message text. | |
PaymentMethodBase:: |
public | function | Gets the payer message text format. | |
PaymentMethodBase:: |
public | function |
Gets the payment capture status. Overrides PaymentMethodCapturePaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Gets the payment refund status. Overrides PaymentMethodRefundPaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Refunds the payment. Overrides PaymentMethodRefundPaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Checks if the payment can be refunded. Overrides PaymentMethodRefundPaymentInterface:: |
|
PaymentMethodBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
PaymentMethodBase:: |
public | function |
Form submission handler. Overrides PluginFormInterface:: |
|
PaymentMethodBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
PayPalBasic:: |
protected | property | ||
PayPalBasic:: |
protected | function |
Performs the actual payment execution. Overrides Basic:: |
|
PayPalBasic:: |
abstract public | function | 2 | |
PayPalBasic:: |
public | function |
Gets the payment execution status. Overrides PaymentMethodBase:: |
|
PayPalBasic:: |
public | function | ||
PayPalBasic:: |
abstract public | function | 2 | |
PayPalBasic:: |
abstract public | function | 2 | |
PayPalBasic:: |
constant | |||
PayPalBasic:: |
constant | |||
PayPalBasic:: |
constant | |||
PayPalBasic:: |
constant | |||
PayPalBasic:: |
constant | |||
PayPalBasic:: |
private | function | ||
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. | |
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. |