class TestGateway in Ubercart 8.4
Defines the test gateway payment method.
This is a dummy payment gateway to use for testing or as an example. All payments using this test gateway will succeed, except when one of the following is TRUE:
- Credit card number equals '0000000000000000'. (Note that ANY card number that fails the Luhn algorithm check performed by uc_credit will not even be submitted to this gateway).
- CVV equals '000'.
- Credit card is expired.
- Payment amount equals 12.34 in store currency units.
- Customer's billing first name equals 'Fictitious'.
- Customer's billing telephone number equals '8675309'.
Plugin annotation
@UbercartPaymentMethod(
id = "test_gateway",
name = @Translation("Test gateway"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\uc_payment\PaymentMethodPluginBase implements ContainerFactoryPluginInterface, PaymentMethodPluginInterface
- class \Drupal\uc_credit\CreditCardPaymentMethodBase
- class \Drupal\uc_credit\Plugin\Ubercart\PaymentMethod\TestGateway
- class \Drupal\uc_credit\CreditCardPaymentMethodBase
- class \Drupal\uc_payment\PaymentMethodPluginBase implements ContainerFactoryPluginInterface, PaymentMethodPluginInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TestGateway
File
- payment/
uc_credit/ src/ Plugin/ Ubercart/ PaymentMethod/ TestGateway.php, line 29
Namespace
Drupal\uc_credit\Plugin\Ubercart\PaymentMethodView source
class TestGateway extends CreditCardPaymentMethodBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'debug' => FALSE,
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['debug'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Debug'),
'#description' => $this
->t('Log debug payment information to dblog when card is "charged" by this gateway.'),
'#default_value' => $this->configuration['debug'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['debug'] = $form_state
->getValue('debug');
return parent::submitConfigurationForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
protected function chargeCard(OrderInterface $order, $amount, $txn_type, $reference = NULL) {
$user = \Drupal::currentUser();
// cc_exp_month and cc_exp_year are also validated by
// CreditCardPaymentMethodBase::validateExpirationDate().
$month = $order->payment_details['cc_exp_month'];
$year = $order->payment_details['cc_exp_year'];
if ($year < 100) {
$year = $year + 2000;
}
// Card is expired at 0:00 on the first day of the next month.
$expiration_date = mktime(0, 0, 0, $month + 1, 1, $year);
// Conditions for failure are described in file documentation block above.
// All other transactions will succeed.
if ($order->payment_details['cc_number'] == '0000000000000000') {
$error = 'Invalid credit card number';
$success = FALSE;
}
elseif (isset($order->payment_details['cc_cvv']) && $order->payment_details['cc_cvv'] == '000') {
$error = 'Invalid CVV';
$success = FALSE;
}
elseif ($expiration_date - REQUEST_TIME <= 0) {
$error = 'Card is expired';
$success = FALSE;
}
elseif ($amount == 12.34) {
$error = 'Invalid payment amount';
$success = FALSE;
}
elseif ($order->billing_first_name == 'Fictitious') {
$error = 'Invalid customer name';
$success = FALSE;
}
elseif ($order->billing_phone == '8675309') {
$error = 'Obviously fake phone number';
$success = FALSE;
}
else {
$success = TRUE;
}
// The information for the payment is in the $order->payment_details array.
if ($this->configuration['debug']) {
\Drupal::logger('uc_credit')
->notice('Test gateway payment details @details.', [
'@details' => print_r($order->payment_details, TRUE),
]);
}
if ($success) {
$message = $this
->t('Credit card charged: @amount', [
'@amount' => uc_currency_format($amount),
]);
$comment = $this
->t('Card charged, resolution code: 0022548315');
}
else {
$message = $this
->t('Credit card charge failed.');
$comment = $this
->t('Card failed authorization, reason: @error', [
'@error' => $error,
]);
}
uc_order_comment_save($order
->id(), $user
->id(), $message, 'admin');
return [
'success' => $success,
'comment' => $comment,
'message' => $message,
'uid' => $user
->id(),
];
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CreditCardPaymentMethodBase:: |
public | function |
Returns the form or render array to be displayed at checkout. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Called when checkout is submitted with this payment method selected. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Returns the payment method review details. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Returns the payment method title to be used on the checkout review page. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Called when an order is being viewed by a customer. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
protected | function | Returns a credit card number with appropriate masking. | |
CreditCardPaymentMethodBase:: |
public | function |
Returns the payment method label with logo. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function | Returns the set of fields which are used by this payment method. | |
CreditCardPaymentMethodBase:: |
public | function | Returns the set of card types which are used by this payment method. | |
CreditCardPaymentMethodBase:: |
public | function | Returns the set of transaction types allowed by this payment method. | 1 |
CreditCardPaymentMethodBase:: |
public | function |
Called when an order is being edited with this payment method. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Called when an order is being loaded with this payment method. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Called when an order is being saved with this payment method. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Called when an order is being submitted with this payment method. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function |
Called when an order is being viewed by an administrator. Overrides PaymentMethodPluginBase:: |
|
CreditCardPaymentMethodBase:: |
public | function | Process a payment through the credit card gateway. | |
CreditCardPaymentMethodBase:: |
protected | function | Validates a credit card number during checkout. | |
CreditCardPaymentMethodBase:: |
protected | function | Validates a CVV number during checkout. | |
CreditCardPaymentMethodBase:: |
protected | function | Validates an expiration date on a card. | |
CreditCardPaymentMethodBase:: |
protected | function | Validates an issue number on a card. | |
CreditCardPaymentMethodBase:: |
protected | function | Validates a start date on a card. | |
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. | |
PaymentMethodPluginBase:: |
protected | property | The database service. | |
PaymentMethodPluginBase:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
PaymentMethodPluginBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
PaymentMethodPluginBase:: |
public | function |
Called when an order is being deleted. Overrides PaymentMethodPluginInterface:: |
1 |
PaymentMethodPluginBase:: |
public | function |
Called when an order is being submitted after being edited. Overrides PaymentMethodPluginInterface:: |
1 |
PaymentMethodPluginBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
PaymentMethodPluginBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
PaymentMethodPluginBase:: |
public | function |
Constructs the PaymentMethodPluginBase object. Overrides PluginBase:: |
|
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. | |
TestGateway:: |
public | function |
Form constructor. Overrides CreditCardPaymentMethodBase:: |
|
TestGateway:: |
protected | function |
Called when a credit card should be processed. Overrides CreditCardPaymentMethodBase:: |
|
TestGateway:: |
public | function |
Gets default configuration for this plugin. Overrides CreditCardPaymentMethodBase:: |
|
TestGateway:: |
public | function |
Form submission handler. Overrides CreditCardPaymentMethodBase:: |