Skip to content

tuutti/commerce_paytrail

Repository files navigation

Commerce paytrail

CI codecov

This module integrates Paytrail payment method with Drupal Commerce.

Installation

Install the Commerce paytrail module as you would normally install a contributed Drupal module. Visit https://www.drupal.org/node/1897420 for further information.

Configuration

  1. Configure the Commerce Paytrail gateway from the Administration > Commerce > Configuration > Payment Gateways (/admin/commerce/config/payment-gateways), by editing an existing or adding a new payment gateway.
  2. Select Paytrail or Paytrail (Credit card) for the payment gateway plugin.
    • Mode: enables the Paytrail payment gateway in test or live mode.
    • Account: provide your Paytrail account.
    • Secret: provide your Paytrail secret.
    • Order discount strategy: Choose the order discount strategy.
  3. Click Save to save your configuration.

Documentation

Alter Paytrail API requests/responses

Create an event subscriber that responds to \Drupal\commerce_paytrail\Event\ModelEvent::class events:

class YourEventSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface {

  /**
   * Event callback.
   *
   * @param \Drupal\commerce_paytrail\Event\ModelEvent $event
   *   The event.
   */
  public function processEvent(ModelEvent $event): void {
    // See below for all available events.
    if ($event->event === \Drupal\commerce_paytrail\RequestBuilder\PaymentRequestBuilderInterface::PAYMENT_CREATE_EVENT) {
      // Do something based on event name.
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() : array {
    return [
      ModelEvent::class => ['processEvent'],
    ];
  }
}

See https://www.drupal.org/docs/develop/creating-modules/subscribe-to-and-dispatch-events for more information about events.

Available events

Prevent saved payment method from being deleted

/**
 * Implements hook_entity_predelete().
 */
function hook_entity_predelete(\Drupal\Core\Entity\EntityInterface $entity) : void {
  if (condition) {
    throw new \Drupal\commerce_payment\Exception\PaymentGatewayException('Card cannot be deleted').
  }
}

Maintainers