README.md (4578B)
1 # GNU Taler Turnstile 2 3 A Drupal module that asks user to subscribe or pay using GNU Taler 4 before granting access to nodes. 5 6 7 ## Features 8 9 - Adds a "price category" field to configurable content types 10 - Implements access control without tracking (but does use session cookies) 11 - Truncates node bodies to show teasers for users that did not (yet) pay 12 - Configurable which content types are subject to access control 13 - Integration with external GNU Taler merchant backend for payment processing 14 - Admin interface for configuration 15 16 17 ## Installation 18 19 1. Download and extract the module to your `modules/custom/` directory 20 2a. Enable the module via Drush: `drush en taler_turnstile`, or 21 2b. Enable via the Drupal admin interface at `/admin/modules` 22 23 24 ## Configuration 25 26 1. Navigate to `/admin/config/content/taler-turnstile` to configure: 27 28 - **Enabled Content Types**: Select which content types should have the price field and access restriction 29 - **Payment Backend URL**: Taler merchant backend HTTP(S) URL of your payment backend service 30 - **Access Token**: Authentication token for the Taler merchant backend 31 - **Enable access if backend is down**: Disables GNU Taler Turnstile if we 32 cannot setup payments with the Taler merchant backend for any reason 33 34 2. Make sure your Taler merchant backend is properly configured: 35 2a. Bank account added 36 2b. Legitimization as account owner with payment service provider is done 37 3. Configure one or more classes of subscriptions (optional) 38 39 Navigate to `/admin/config/system/taler-turnstile/subscription-prices` to configure: 40 41 - **Subscription prices**: Price for each type of subscription and currency 42 43 44 ## Usage 45 46 1. Define one or more price categories under `/admin/structure/price-categories`: 47 1a. Define a price in each currency that you accept 48 1b. Define a possibly discounted price (including 0) for subscribers 49 2. Create or edit a node of an enabled content type 50 3. Set a price category in the respective field to require payment 51 4. Earn money: 52 4a. Users that need to pay will see truncated content 53 4b. Users with the cookie will see the original full content 54 55 56 ## How it Works 57 58 The module uses `hook_entity_view_alter()` to intercept node rendering and 59 checks if the customer has been granted access. 60 61 If they need to pay, we truncate the content body and add a link to 62 enable the user to pay. If the user did pay (or subscribe), we 63 display the original content 64 65 66 ## File Structure 67 68 ``` 69 taler_turnstile/ 70 ├── config/ 71 │ ├── install/ 72 │ │ └── taler_turnstile.settings.yml - default configuration values 73 │ └── schema/ 74 │ └── taler_turnstile.schema.yml - configuration schema (partial, without subscription prices) 75 ├── js/ 76 │ ├── qrcode.min.js - QR code library from https://github.com/davidshimjs/qrcodejs 77 │ └── payment-button.js - shows QR code and long-polls with backend for payment 78 ├── src/ 79 │ ├── Entity/ 80 │ │ └── TurnstilePriceCategory.php - Main entity class for price categories 81 │ ├── Form/ 82 │ │ ├── PriceCategoryForm.php - Add/edit form handler 83 │ │ ├── PriceCategoryDeleteForm.php - Delete confirmation form 84 │ │ ├── SubscriptionPricesForm.php - Configure subscription prices 85 │ │ └── TurnstileSettingsForm.php - Configure basics of Turnstile 86 │ ├── PriceCategoryListBuilder.php - Admin list page builder 87 │ ├── TalerMerchantApiService.php - API service for merchant backend interaction 88 │ └── TurnstileFieldManager.php - Manages price-category field injection 89 ├── taler_turnstile.libraries.yml - JS libraries and dependencies 90 ├── taler_turnstile.info.yml - Module metadata and dependencies 91 ├── taler_turnstile.install - Install/uninstall hooks 92 ├── taler_turnstile.module - Hook implementations and debug functions 93 ├── taler_turnstile.permissions.yml - Permission definitions 94 ├── taler_turnstile.routing.yml - Route definitions for pages 95 ├── taler_turnstile.services.yml - Service container definitions 96 ├── taler_turnstile.links.menu.yml - Menu link to Structure menu 97 ├── taler_turnstile.links.action.yml - Action link for adding price categories 98 └── README.md 99 ``` 100 101 102 ## Requirements 103 104 - Drupal 9 or 10 105 - PHP 7.4 or higher 106 107 108 ## License 109 110 GPLv2-or-later, see COPYING for the full license terms. 111 112 113 ## TODO 114 115 - test subscriptions 116 - test repurchase detection works! 117 - LATER: use order expiration from merchant backend (with new v1.1 implementation) 118 instead of hard-coding 1 day!