gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-gnu-taler-payment-for-woocommerce] branch master updated: organiz


From: gnunet
Subject: [taler-gnu-taler-payment-for-woocommerce] branch master updated: organize code a bit more in line with contemporary examples from WooCommerce; add 'Bearer' prefix to Authorization: header
Date: Thu, 23 Feb 2023 12:27:45 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnu-taler-payment-for-woocommerce.

The following commit(s) were added to refs/heads/master by this push:
     new c8640f4  organize code a bit more in line with contemporary examples 
from WooCommerce; add 'Bearer' prefix to Authorization: header
c8640f4 is described below

commit c8640f4a212995b4f7a41bcc2a1a1c1209d5edff
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Feb 23 12:27:40 2023 +0100

    organize code a bit more in line with contemporary examples from 
WooCommerce; add 'Bearer' prefix to Authorization: header
---
 class-wc-gnutaler-gateway.php | 149 ++++++++++++++++++++++++------------------
 1 file changed, 85 insertions(+), 64 deletions(-)

diff --git a/class-wc-gnutaler-gateway.php b/class-wc-gnutaler-gateway.php
index 62d3e15..31fc632 100644
--- a/class-wc-gnutaler-gateway.php
+++ b/class-wc-gnutaler-gateway.php
@@ -9,7 +9,7 @@
  * Plugin Name: GNU Taler Payment for WooCommerce
  * Plugin URI: https://git.taler.net/woocommerce-taler
  * Description: This plugin enables payments via the GNU Taler payment system
- * Version: 0.9
+ * Version: 0.9.2
  * Author: Dominique Hofmann, Jan StrĂ¼bin, Christian Grothoff
  * Author URI: https://taler.net/
  *
@@ -118,7 +118,7 @@ function gnutaler_init_gateway_class() {
                 *
                 * @var Plugin loggger.
                 */
-               private static $logger = false;
+               private static $log = false;
 
                /**
                 * True if logging is enabled in our configuration.
@@ -131,14 +131,14 @@ function gnutaler_init_gateway_class() {
                 * Class constructor
                 */
                public function __construct() {
-                       $this->id     = 'gnutaler'; // Payment gateway plugin 
ID.
-                       $this->logger = new WC_logger( $this->id ); // Setup 
logging.
-                       $this->icon   = plugins_url( 
'/assets/images/taler.png', __FILE__ );
-                       // We cannot use custom fields to show the QR code / do 
the wallet integration as WC doesn't give us the order_id at that time. Bummer.
-                       $this->has_fields = false;
-                       // The following texts will be displayed on the payment 
plugins settings page.
-                       $this->method_title       = 'GNU Taler';
-                       $this->method_description = __( 'This plugin enables 
payments via the GNU Taler payment system', 'gnutaler' );
+                       // Setup logging.
+                       $this->log = new WC_logger( $this->id ); // Setup 
logging.
+                       $this->debug       = 'yes' === $this->get_option( 
'debug', 'no' );
+                       self::$log_enabled = $this->debug;
+
+                       $this->setup_properties();
+                       $this->init_form_fields();
+                       $this->init_settings();
 
                        // This gateway can support refunds, saved payment 
methods.
                        $this->supports = array(
@@ -146,11 +146,63 @@ function gnutaler_init_gateway_class() {
                                'refunds',
                        );
 
-                       // Setup logging.
-                       $this->debug       = 'yes' === $this->get_option( 
'debug', 'no' );
-                       self::$log_enabled = $this->debug;
+                       $this->title              = $this->get_option( 'title' 
);
+                       $this->description        = $this->get_option( 
'description' );
+                       $this->instructions       = $this->get_option( 
'instructions' );
+                       $this->enable_for_virtual = true;
+
+                       $this->enabled               = $this->get_option( 
'enabled' );
+                       $this->gnu_taler_backend_url = $this->get_option( 
'gnu_taler_backend_url' );
+                       // Remove trailing '/', we add one always ourselves...
+                       if ( substr( $this->gnu_taler_backend_url, -1 ) === '/' 
) {
+                               $this->gnu_taler_backend_url = substr( 
$this->gnu_taler_backend_url, 0, -1 );
+                       }
+
+                       // Make transaction ID a link. We use the public version
+                       // here, as a user clicking on the link could not supply
+                       // the authorization header.
+                       // See also: 
https://woocommerce.wordpress.com/2014/08/05/wc-2-2-payment-gateways-adding-refund-support-and-transaction-ids/.
+                       $this->view_transaction_url = 
$this->gnu_taler_backend_url . '/orders/%s';
+
+                       // Register handler for the fulfillment URL.
+                       add_action(
+                               'woocommerce_api_' . strtolower( get_class( 
$this ) ),
+                               array( &$this, 'fulfillment_url_handler' )
+                       );
+
+                       // This action hook saves the settings.
+                       add_action(
+                               'woocommerce_update_options_payment_gateways_' 
. $this->id,
+                               array( $this, 'process_admin_options' )
+                       );
 
-                       // Setup 'form_fields'.
+                       // Modify WC canonical refund e-mail notifications to 
add link to order status page.
+                       // (according to 
https://www.businessbloomer.com/woocommerce-add-extra-content-order-email/).
+                       add_action(
+                               'woocommerce_email_before_order_table',
+                               array( $this, 'add_content_refund_email' ),
+                               20,
+                               4
+                       );
+               }
+
+
+               /**
+                * Setup general properties for the gateway.
+                */
+               protected function setup_properties() {
+                       $this->id     = 'gnutaler'; // Payment gateway plugin 
ID.
+                       $this->icon   = plugins_url( 
'/assets/images/taler.png', __FILE__ );
+                       $this->method_title       = 'GNU Taler';
+                       $this->method_description = __( 'This plugin enables 
payments via the GNU Taler payment system', 'gnutaler' );
+                       // We cannot use custom fields to show the QR code / do 
the wallet integration as WC doesn't give us the order_id at that time. Bummer.
+                       $this->has_fields = false;
+               }
+
+               /**
+                * Initialise Gateway Settings Form Fields.
+                */
+               public function init_form_fields() {
                        $this->form_fields = array(
                                'enabled'                   => array(
                                        'title'       => __( 'Enable/Disable', 
'gnutaler' ),
@@ -169,8 +221,16 @@ function gnutaler_init_gateway_class() {
                                'description'               => array(
                                        'title'       => __( 'Description', 
'gnutaler' ),
                                        'type'        => 'textarea',
-                                       'description' => __( 'This controls the 
description for the payment option which the customer sees during checkout.', 
'gnutaler' ),
-                                       'default'     => __( 'Pay with GNU 
Taler', 'gnutaler' ),
+                                       'description' => __( 'Payment method 
description which the customer sees during checkout.', 'gnutaler' ),
+                                       'default'     => __( 'Pay digitally 
with GNU Taler', 'gnutaler' ),
+                                       'desc_tip'    => true,
+                               ),
+                               'instructions'              => array(
+                                       'title'       => __( 'Instructions', 
'gnutaler' ),
+                                       'type'        => 'textarea',
+                                       'description' => __( 'Instructions that 
will be added to the thank you page.', 'gnutaler' ),
+                                       'default'     => __( 'Thank you for 
paying with GNU Taler', 'gnutaler' ),
+                                       'desc_tip'    => true,
                                ),
                                'gnu_taler_backend_url'     => array(
                                        'title'       => __( 'Taler backend 
URL', 'gnutaler' ),
@@ -181,8 +241,8 @@ function gnutaler_init_gateway_class() {
                                'GNU_Taler_Backend_API_Key' => array(
                                        'title'       => __( 'Taler Backend API 
Key', 'gnutaler' ),
                                        'type'        => 'text',
-                                       'description' => __( 'Enter your API 
key to authenticate with the Taler backend.', 'gnutaler' ),
-                                       'default'     => 'ApiKey sandbox',
+                                       'description' => __( 'Enter your API 
key to authenticate with the Taler backend. Will be sent as a "Bearer" token 
using the HTTP "Authorization" header. Typically should be prefixed with 
"secret-token:" (RFC 8959).', 'gnutaler' ),
+                                       'default'     => 'secret-token:Sandbox 
ApiKey',
                                ),
                                'Order_text'                => array(
                                        'title'       => __( 'Summary Text of 
the Order', 'gnutaler' ),
@@ -208,45 +268,6 @@ function gnutaler_init_gateway_class() {
                                        'default'     => 'no',
                                ),
                        );
-
-                       // Load the settings.
-                       $this->init_settings();
-                       $this->title                 = $this->get_option( 
'title' );
-                       $this->description           = $this->get_option( 
'description' );
-                       $this->enabled               = $this->get_option( 
'enabled' );
-                       $this->gnu_taler_backend_url = $this->get_option( 
'gnu_taler_backend_url' );
-                       // Remove trailing '/', we add one always ourselves...
-                       if ( substr( $this->gnu_taler_backend_url, -1 ) === '/' 
) {
-                               $this->gnu_taler_backend_url = substr( 
$this->gnu_taler_backend_url, 0, -1 );
-                       }
-
-                       // Make transaction ID a link. We use the public version
-                       // here, as a user clicking on the link could not supply
-                       // the authorization header.
-                       // See also: 
https://woocommerce.wordpress.com/2014/08/05/wc-2-2-payment-gateways-adding-refund-support-and-transaction-ids/.
-                       $this->view_transaction_url = 
$this->gnu_taler_backend_url . '/orders/%s';
-
-                       // Register handler for the fulfillment URL.
-                       $hname = 'woocommerce_api_' . strtolower( get_class( 
$this ) );
-                       add_action(
-                               $hname,
-                               array( &$this, 'fulfillment_url_handler' )
-                       );
-
-                       // This action hook saves the settings.
-                       add_action(
-                               'woocommerce_update_options_payment_gateways_' 
. $this->id,
-                               array( $this, 'process_admin_options' )
-                       );
-
-                       // Modify WC canonical refund e-mail notifications to 
add link to order status page.
-                       // (according to 
https://www.businessbloomer.com/woocommerce-add-extra-content-order-email/).
-                       add_action(
-                               'woocommerce_email_before_order_table',
-                               array( $this, 'add_content_refund_email' ),
-                               20,
-                               4
-                       );
                }
 
                /**
@@ -284,10 +305,10 @@ function gnutaler_init_gateway_class() {
 
                        // Maybe clear logs.
                        if ( 'yes' !== $this->get_option( 'debug', 'no' ) ) {
-                               if ( empty( self::$logger ) ) {
-                                       self::$logger = wc_get_logger();
+                               if ( empty( self::$log ) ) {
+                                       self::$log = wc_get_logger();
                                }
-                               self::$logger->clear( 'gnutaler' );
+                               self::$log->clear( 'gnutaler' );
                        }
 
                        return $saved;
@@ -412,7 +433,7 @@ function gnutaler_init_gateway_class() {
                                'user-agent'          => '', // Minimize 
information leakage.
                                'blocking'            => true, // We do nothing 
without it.
                                'headers'             => array(
-                                       'Authorization: ' . $apikey,
+                                       'Authorization: Bearer ' . $apikey,
                                ),
                                'decompress'          => true,
                                'limit_response_size' => 1024 * 1024, // More 
than enough.
@@ -1023,10 +1044,10 @@ function gnutaler_init_gateway_class() {
                         // phpcs:disable WordPress.Security.NonceVerification
                        $order_id = sanitize_text_field( wp_unslash( 
$_GET['order_id'] ) );
                         // phpcs:enable
-                       if ( empty( self::$logger ) ) {
-                               self::$logger = wc_get_logger();
+                       if ( empty( self::$log ) ) {
+                               self::$log = wc_get_logger();
                        }
-                       self::$logger->log( $level, $user_id . '-' . $order_id 
. ': ' . $msg, array( 'source' => 'gnutaler' ) );
+                       self::$log->log( $level, $user_id . '-' . $order_id . 
': ' . $msg, array( 'source' => 'gnutaler' ) );
                }
 
        }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]