webgriffe/payum-lock-request-extension

A Payum extension providing the ability to lock concurrent requests.

0.1.0 2023-10-17 10:20 UTC

This package is auto-updated.

Last update: 2024-10-27 16:56:13 UTC


README

A Payum extension providing the ability to lock concurrent requests

Tests

This extension provides the ability to lock concurrent requests to a Payum gateway (for example when the PSP send both a notify action and a traditional capture action in the same moment). It uses Symfony Lock Component to provide a simple and reliable locking mechanism.

Installation

composer require webgriffe/payum-lock-request-extension

Usage

<?php

// Use your preferred \Symfony\Component\Lock\PersistingStoreInterface implementation
$persistingStore = new Symfony\Component\Lock\Store\SemaphoreStore();

$lockFactory = new \Symfony\Component\Lock\LockFactory($persistingStore);

$lockRequestExtension = new \Webgriffe\PayumLockRequestExtension\LockRequestExtension(
    $lockFactory,
    'my_lock_prefix', // Optional, default value is 'webgriffe_payum_lock_request_extension'
    30.0, // Optional, default value is 30.0
    true // Optional, default value is true
);

/** @var \Payum\Core\Gateway $gateway */
$gateway->addExtension($lockRequestExtension);

// here the extension will be called to wrap the execute acton in a lock
$gateway->execute(new FooRequest);

Configuration

The extension can be configured with the following options:

  • Lock prefix: to ensure lock key is unique, default is webgriffe_payum_lock_request_extension.
  • Lock TTL: the maximum time in seconds that a lock can be hold, default is 30.
  • Lock autorelease: release the lock or not when the lock instance is destroyed, default is true.