wordpress-turnstile

Wordpress paywall plugin
Log | Files | Refs | README | LICENSE

commit 6cb482abd12630480a676b6a826a4730caf86cd4
parent e61027f22fd27d34db4e41e8063ecd01333ecfbd
Author: Christian Grothoff <christian@grothoff.org>
Date:   Wed,  5 Nov 2025 20:27:15 +0100

add price/subscription hints on payment page

Diffstat:
Mincludes/class-content-filter.php | 10++++++++++
Mincludes/class-price-category.php | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Mincludes/class-taler-merchant-api.php | 4++++
3 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/includes/class-content-filter.php b/includes/class-content-filter.php @@ -194,6 +194,8 @@ class Taler_Content_Filter { $order_id = $order_info['order_id']; $session_id = $order_info['session_id']; $payment_url = $order_info['payment_url']; + $price_hint = $order_info['price_hint']; + $subscription_hint = $order_info['subscription_hint']; ob_start(); ?> @@ -220,6 +222,14 @@ class Taler_Content_Filter { </div> </div> + <h4 class="price_hint_title"><?php esc_html_e('Price per article', 'taler-turnstile'); ?></h3> + <div class="taler-price-per-article-hint"> + <?php esc_html_e($price_hint); ?> + </div> + <h4 class="subscription_hint_title"><?php esc_html_e('Acceptable subscriptions', 'taler-turnstile'); ?></h3> + <div class="taler-available-subscription-hint"> + <?php esc_html_e($subscription_hint); ?> + </div> <!-- div class="taler-payment-info"> <p class="taler-order-id"> /* translators: placeholder is the order ID of the merchant backend */ diff --git a/includes/class-price-category.php b/includes/class-price-category.php @@ -67,6 +67,56 @@ class Taler_Price_Category { } /** + * Gets a brief hint to display about non-subscriber prices. + */ + public static function getPriceHint($id) { + $category = self::get($id); + if (!$category || !isset($category['prices'])) { + return __(/* translators: Need to buy a subscription */ 'Not sold individually'); + } + + $prices = $category['prices']; + $nosub = $prices['%none%']; + $rval = NULL; + foreach ($nosub as $currency => $price) { + if (NULL === $rval) + { + $rval = "$price $currency"; + } + else + { + $rval = "$price $currency, " . $rval; + } + } + return $rval ?? __(/* translators: Need to buy a subscription */ 'Not sold individually'); + } + + /** + * Gets a brief hint to display about applicable subscriptions. + */ + public static function getSubscriptionHint($id) { + $category = self::get($id); + if (!$category || !isset($category['prices'])) { + return __(/* No subscriptions */ 'None'); + } + $prices = $category['prices']; + $rval = NULL; + foreach ($prices as $subscription => $details) { + if ('%none%' === $subscription) + continue; + if (NULL === $rval) + { + $rval = $subscription; + } + else + { + $rval = $subscription . ", " . $rval; + } + } + return $rval ?? __(/* translators: No subscriptions */ 'None'); + } + + /** * Get payment choices for GNU Taler v1 contracts */ public static function get_payment_choices($id, $subscriptions) { diff --git a/includes/class-taler-merchant-api.php b/includes/class-taler-merchant-api.php @@ -467,6 +467,8 @@ class Taler_Merchant_API { error_log('No price category, cannot setup new order'); return false; } + $price_hint = Taler_Price_Category::getPriceHint($price_category_id); + $subscription_hint = Taler_Price_Category::getSubscriptionHint($price_category_id); $subscriptions = Taler_Merchant_API::get_subscriptions(); $choices = Taler_Price_Category::get_payment_choices($price_category_id, $subscriptions); @@ -545,6 +547,8 @@ class Taler_Merchant_API { 'order_id' => $order_id, 'payment_url' => $backend_url . 'orders/' . $order_id, 'order_expiration' => $order_expiration, + 'price_hint' => $price_hint, + 'subscription_hint' => $subscription_hint, 'paid' => false, 'session_id' => $hashed_session_id );