commit c8d2f5903fced36728b5ddbf388b465483e8b7f0
parent 4e5bebc04690427cc5bdb064b9771dc39aee045e
Author: Christian Grothoff <christian@grothoff.org>
Date: Thu, 9 Oct 2025 14:18:36 +0200
use named constants, add session_id in order creation
Diffstat:
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/turnstile.module b/turnstile.module
@@ -12,6 +12,16 @@ use Drupal\node\NodeInterface;
use GuzzleHttp\Exception\RequestException;
+/**
+ * Taler error codes used in this module. We do not define
+ * the full list here as that would be excessive and could
+ * just slow down PHP unnecessarily.
+ */
+enum TalerErrorCode: int {
+ case TALER_EC_NONE = 0;
+ case TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN = 2000;
+ case TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN = 2005;
+}
/**
* Implements hook_entity_bundle_field_info_alter().
@@ -342,21 +352,22 @@ function turnstile_check_order_status($order_id) {
return FALSE;
case 404:
// Order unknown or instance unknown
- $ec = $result['code'] ?? 0;
+ /** @var TalerErrorCode $ec */
+ $ec = $result['code'] ?? TALER_EC_NONE;
switch ($ec)
{
- case 0:
+ case TALER_EC_NONE:
// Protocol violation. Could happen if the backend domain was
// taken over by someone else.
$body_log = json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
\Drupal::logger('turnstile')->error('Invalid response from merchant backend when trying to obtain order status. Check your Turnstile configuration! @body', ['@body' => $body_log ?? 'N/A']);
return FALSE;
- case 2000: // FIXME: MERCHANT_GENERIC_INSTANCE_UNKNOWN
+ case TALER_EC_MERCHANT_GENERIC_INSTANCE_UNKNOWN:
// This could happen if our instance was deleted after the configuration was
// checked. Very bad, log serious error.
\Drupal::logger('turnstile')->error('Configured instance "@detail" unknown to merchant backend. Check your Turnstile configuration!', ['@detail' => $result['detail'] ?? 'N/A']);
return FALSE;
- case 2005: // FIXME: MERCHANT_GENERIC_ORDER_UNKNOWN
+ case TALER_EC_MERCHANT_GENERIC_ORDER_UNKNOWN:
// This could happen if the instance owner manually deleted
// an order while the customer was looking at the article.
\Drupal::logger('turnstile')->warning('Order "@order" disappeared in the backend.', ['@order' => $order_id]);
@@ -473,6 +484,7 @@ function turnstile_create_order(NodeInterface $node) {
't_s' => $order_expiration,
],
],
+ 'session_id' => session_id (),
'create_token' => FALSE,
];