summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-10-16 16:50:30 +0200
committerChristian Grothoff <christian@grothoff.org>2020-10-16 16:50:30 +0200
commit0c8b3644a0d6083c4249baa078c9a54140124362 (patch)
tree8a55176d476034a3f628e404acdb164c384440ff
parent618165ae76074d9a34a43cd02270254d56667d88 (diff)
downloadwoocommerce-taler-0c8b3644a0d6083c4249baa078c9a54140124362.tar.gz
woocommerce-taler-0c8b3644a0d6083c4249baa078c9a54140124362.tar.bz2
woocommerce-taler-0c8b3644a0d6083c4249baa078c9a54140124362.zip
clean up payment gateway code
-rw-r--r--plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php168
-rw-r--r--server-build/my-simple-cdd/profiles/reclaim.packages24
2 files changed, 89 insertions, 103 deletions
diff --git a/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php b/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php
index 767a765..333c987 100644
--- a/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php
+++ b/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php
@@ -7,7 +7,7 @@
* Plugin URI: https://git.taler.net/woocommerce-taler
* Description: This plugin enables payments via the GNU Taler payment system
* Version: 0.8
- * Author: Hofmann Dominique & StrĂ¼bin Jan, Adaptations by Christian Grothoff
+ * Author: Hofmann Dominique & StrĂ¼bin Jan, Adaptations by Christian Grothoff
* Author URI: https://taler.net/
*
* License: GNU General Public License v3.0
@@ -40,16 +40,6 @@ define("MERCHANT_PROTOCOL_CURRENT", 1);
*/
define("MERCHANT_PROTOCOL_AGE", 0);
-
-/*
-TODO:
-- refund needs to be tested more (with wallet!)
-
-OPEN FEATURES:
-- MAYBE: multi-currency support (i.e. use https://$CURRENCY.$backend_url/?)
-
-*/
-
require_once ABSPATH . 'wp-admin/includes/plugin.php';
//Exit if accessed directly.
@@ -74,34 +64,27 @@ function gnutaler_add_gateway_class( $gateways ) {
add_filter( 'woocommerce_payment_gateways', 'gnutaler_add_gateway_class' );
-add_filter ( 'openid-connect-generic-cookie-redirect-url',
- 'filter_redir_cb' );
-
-function filter_redir_cb ( $var ) {
- $logger = wc_get_logger();
- $logger->log ("INFO", 'REDIR input is ' . $var );
- return $var;
-}
-
-
/**
* The class itself, please note that it is inside plugins_loaded action hook
*/
add_action( 'plugins_loaded', 'gnutaler_init_gateway_class' );
-function gnutaler_init_gateway_class()
-{
- // Setup textdomain for gettext style translations
+function gnutaler_init_gateway_class(){
+
+ // Setup textdomain for gettext style translations
$plugin_rel_path = basename( dirname( __FILE__ ) ) . '/languages'; /* Relative to WP_PLUGIN_DIR */
load_plugin_textdomain( 'gnutaler', false, $plugin_rel_path );
// Check if WooCommerce is active, if not then deactivate and show error message
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) );
- wp_die( sprintf ( wp_kses (__('<strong>GNU Taler</strong> requires <strong>WooCommerce</strong> plugin to work. Please activate it or install it from <a href="http://wordpress.org/plugins/woocommerce/" target="_blank">here</a>.<br /><br />Back to the WordPress <a href="%s">Plugins page</a>.', 'gnutaler' ),
- array('strong' => array(), 'a' => array ('href' => array(), '_target' => array() ) ) ),
- get_admin_url(null, 'plugins.php') ) );
+ wp_die( sprintf ( wp_kses( __( '<strong>GNU Taler</strong> requires <strong>WooCommerce</strong> plugin to work. Please activate it or install it from <a href="http://wordpress.org/plugins/woocommerce/" target="_blank">here</a>.<br /><br />Back to the WordPress <a href="%s">Plugins page</a>.',
+ 'gnutaler' ),
+ array( 'strong' => array(),
+ 'a' => array( 'href' => array(),
+ '_target' => array() ) ) ),
+ get_admin_url(null, 'plugins.php') ) );
}
/**
@@ -109,8 +92,7 @@ function gnutaler_init_gateway_class()
*
* Handles the payments from the Woocommerce Webshop and sends the transactions to the GNU Taler Backend and the GNU Taler Wallet.
*/
- class WC_GNUTaler_Gateway extends WC_Payment_Gateway
- {
+ class WC_GNUTaler_Gateway extends WC_Payment_Gateway {
// plugin logs
private static $logger = false;
@@ -121,8 +103,7 @@ function gnutaler_init_gateway_class()
/**
* Class constructor
*/
- public function __construct()
- {
+ 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__ );
@@ -204,8 +185,9 @@ function gnutaler_init_gateway_class()
$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) == '/')
+ 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
@@ -224,8 +206,6 @@ function gnutaler_init_gateway_class()
// 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/)
- // NOTE: I didn't manage WC to send out ANY e-mail notifications for refunds, so this is
- // UNTESTED. We do send out our own e-mail on refund below. This is mostly an alternative.
add_action( 'woocommerce_email_before_order_table',
array ($this, 'add_content_refund_email'),
20,
@@ -239,7 +219,7 @@ function gnutaler_init_gateway_class()
* Adds a Taler-specific notice for where to click to obtain
* the refund.
*/
- function add_content_refund_email ( $wc_order, $sent_to_admin, $plain_text, $email ) {
+ function add_content_refund_email( $wc_order, $sent_to_admin, $plain_text, $email ){
if ( $email->id == 'customer_refunded_order' ) {
$backend_url = $this->GNU_Taler_Backend_URL;
$wc_order_id = $wc_order->get_order_key() . '-' . $wc_order->get_order_number();
@@ -252,19 +232,18 @@ function gnutaler_init_gateway_class()
/**
* Processes and saves options.
- * If there is an error thrown, will continue to
- * save and validate fields, but
+ * If there is an error thrown, will continue to save and validate fields, but
* will leave the erroring field out.
*
* @return bool was anything saved?
*/
- public function process_admin_options() {
+ public function process_admin_options(){
$saved = parent::process_admin_options();
// Maybe clear logs.
if ( 'yes' !== $this->get_option( 'debug', 'no' ) ) {
- if ( empty( self::$log ) ) {
- self::$log = wc_get_logger();
+ if ( empty( self::$log ) ) {
+ self::$log = wc_get_logger();
}
self::$log->clear( 'gnutaler' );
}
@@ -273,7 +252,7 @@ function gnutaler_init_gateway_class()
}
- public function payment_fields () {
+ public function payment_fields(){
// We do not have any.
}
@@ -284,16 +263,17 @@ function gnutaler_init_gateway_class()
* If the order ID is unknown and/or the payment did not succeed, we
* redirect to the home page and/or the user's order page (for logged in users).
*/
- function fulfillment_url_handler(): void
- {
+ function fulfillment_url_handler(): void {
global $woocommerce;
if (! isset( $_GET['order_id'] ) ) {
$this->debug( __( "Lacking 'order_id', forwarding user to neutral page", 'gnutaler' ) );
- if ( is_user_logged_in() )
+ if ( is_user_logged_in() ) {
wp_redirect( get_home_url() . wc_get_page_permalink( 'myaccount' ));
- else
+ }
+ else {
wp_redirect( get_home_url() . wc_get_page_permalink( 'shop' ));
+ }
exit;
}
@@ -330,8 +310,7 @@ function gnutaler_init_gateway_class()
// Empties the shopping cart
WC()->cart->empty_cart();
}
- else
- {
+ else {
wc_add_notice( __('Payment error:', 'gnutaler' ) .
__('backend did not confirm payment', 'gnutaler' ) );
$this->notice( __('Backend did not confirm payment', 'gnutaler' ) );
@@ -346,10 +325,12 @@ function gnutaler_init_gateway_class()
break;
} // end 'switch ($payment_http_status)
$cart_url = $woocommerce->cart->wc_get_cart_url();
- if (is_set( $cart_url ))
+ if (is_set( $cart_url )) {
wp_redirect( get_home_url() . $cart_url );
- else
+ }
+ else {
wp_redirect( wc_get_page_permalink ('shop') );
+ }
exit;
}
@@ -365,8 +346,7 @@ function gnutaler_init_gateway_class()
* @param $body - The content of the request (for POST).
* @return array The return array will either have the successful return value or a detailed error message.
*/
- function call_api( $method, $url, $body): array
- {
+ function call_api( $method, $url, $body ): array {
$curl = curl_init();
switch ( $method ) {
case 'POST':
@@ -434,7 +414,7 @@ function gnutaler_init_gateway_class()
* the admin to the setup dialog if they enable the backend and
* it is not properly configured.
*/
- public function needs_setup () {
+ public function needs_setup(){
$backend_url = $this->GNU_Taler_Backend_URL;
return ! $this->verify_backend_url( $backend_url,
null);
@@ -448,8 +428,7 @@ function gnutaler_init_gateway_class()
* @param $ecurrency - expected currency of the order
* @return bool - Returns if valid or not.
*/
- function verify_backend_url( $url, $ecurrency ): bool
- {
+ function verify_backend_url( $url, $ecurrency ): bool {
$config = $this->call_api( 'GET', $url . '/config', false);
$config_http_status = $config['http_code'];
$config_body = $config['message'];
@@ -474,21 +453,18 @@ function gnutaler_init_gateway_class()
$age = $ver[2];
if ( (! is_numeric ($current)) ||
(! is_numeric ($revision)) ||
- (! is_numeric ($age)) )
- {
+ (! is_numeric ($age)) ) {
$this->error( sprintf( __( "/config response at backend malformed: '%s' is not a valid version", 'gnutaler'),
$version ) );
return false;
}
- if (MERCHANT_PROTOCOL_CURRENT < $current - $age)
- {
+ if (MERCHANT_PROTOCOL_CURRENT < $current - $age) {
// Our implementation is too old!
$this->error( sprintf( __( "Backend protocol version %s is too new: please update the GNU Taler plugin", 'gnutaler' ),
$version ) );
return false;
}
- if (MERCHANT_PROTOCOL_CURRENT - MERCHANT_PROTOCOL_AGE > $current)
- {
+ if (MERCHANT_PROTOCOL_CURRENT - MERCHANT_PROTOCOL_AGE > $current) {
// Merchant implementation is too old!
$this->error( sprintf( __( "Backend protocol version %s unsupported: please update the backend", 'gnutaler' ),
$version ) );
@@ -521,8 +497,7 @@ function gnutaler_init_gateway_class()
* @param $order_id - ID of the order to get the Order from the WooCommerce Webshop
* @return array|void - Array with result => success and redirection url otherwise it returns void.
*/
- public function process_payment( $order_id )
- {
+ public function process_payment( $order_id ){
// we need it to get any order detailes
$wc_order = wc_get_order( $order_id );
@@ -558,8 +533,7 @@ function gnutaler_init_gateway_class()
}
$taler_order_id = $post_order_response ['order_id'];
$taler_order_token = $post_order_response ['token'];
- if (! $taler_order_id)
- {
+ if (! $taler_order_id) {
$this->error( __('Response to POST /private/orders request to Taler backend lacks order_id field: ', 'gnutaler' )
. $order_body );
wc_add_notice( __('Malformed response from Taler backend. Please contact the system administrator.', 'gnutaler' ) );
@@ -607,8 +581,7 @@ function gnutaler_init_gateway_class()
* @param $order_id - To get the order from the WooCommerce Webshop
* @return array - return the JSON Format.
*/
- public function convert_to_checkout_json( $order_id ): array
- {
+ public function convert_to_checkout_json( $order_id ): array {
$wc_order = wc_get_order( $order_id );
$wc_order_total_amount = $wc_order->get_total();
$wc_order_currency = $wc_order->get_currency();
@@ -634,8 +607,7 @@ function gnutaler_init_gateway_class()
'delivery_location' => $this->mutate_shipping_information_to_json_format( $wc_order ),
),
);
- if (isset ($refund_delay))
- {
+ if (isset ($refund_delay)) {
$order_json['refund_delay'] = array (
'd_ms' => 1000 * 60 * 60 * 24 * intval ($refund_delay)
);
@@ -650,8 +622,7 @@ function gnutaler_init_gateway_class()
* @param $wc_order_currency - The currency the WooCommerce Webshop uses.
* @return array - Returns an array of products.
*/
- function mutate_products_to_json_format( $wc_cart, $wc_order_currency, $wc_order ): array
- {
+ function mutate_products_to_json_format( $wc_cart, $wc_order_currency, $wc_order ): array {
$wc_order_products_array = array();
foreach ( $wc_cart as $product ) {
$wc_order_products_array[] = array(
@@ -674,8 +645,7 @@ function gnutaler_init_gateway_class()
* @param $wc_order
* @return array
*/
- function mutate_shipping_information_to_json_format($wc_order): array
- {
+ function mutate_shipping_information_to_json_format($wc_order): array {
$whitechar_encounter = false;
$shipping_address_street = '';
$shipping_address_streetNr = '';
@@ -688,9 +658,11 @@ function gnutaler_init_gateway_class()
foreach ( $store_address_array as $char ) {
if ( ! $whitechar_encounter ) {
$shipping_address_street .= $char;
- } elseif ( ctype_space( $char ) ) {
+ }
+ elseif ( ctype_space( $char ) ) {
$whitechar_encounter = true;
- } else {
+ }
+ else {
$shipping_address_street .= $char;
}
}
@@ -723,8 +695,7 @@ function gnutaler_init_gateway_class()
* @param string $reason - Reason for the refund request.
* @return bool|WP_Error - Returns true or throws an WP_Error message in case of error.
*/
- public function process_refund( $order_id, $amount = null, $reason = '' )
- {
+ public function process_refund( $order_id, $amount = null, $reason = '' ){
$wc_order = wc_get_order( $order_id );
/* translators: first argument is numeric amount, second argument the name of the currency ("EUR", "USD"), and third the reason. */
@@ -742,8 +713,7 @@ function gnutaler_init_gateway_class()
// Checks if current status is already set as paid
if (! ( $wc_order_status === 'processing' ||
$wc_order_status === 'on hold' ||
- $wc_order_status === 'completed' ) )
- {
+ $wc_order_status === 'completed' ) ) {
$this->error( __( 'The status of the order does not allow a refund', 'gnutaler' ) );
return new WP_Error( 'error', __('The status of the order does not allow for a refund.', 'gnutaler' ) );
}
@@ -763,16 +733,14 @@ function gnutaler_init_gateway_class()
{
case 200:
$refund_response = json_decode ($refund_body, $assoc=true);
- if (! $refund_response)
- {
+ if (! $refund_response) {
$this->error( __( 'Malformed 200 response from Taler backend: not even in JSON', 'gnutaler' ) );
return new WP_Error( 'error', __( 'Malformed response from Taler backend', 'gnutaler' ) );
}
$refund_uri = $refund_response['taler_refund_uri'];
$h_contract = $refund_response['h_contract'];
if ( (! $refund_uri) ||
- (! $h_contract) )
- {
+ (! $h_contract) ) {
$this->error( __( 'Malformed 200 response from Taler backend: lacks taler_refund_uri', 'gnutaler' ) );
return new WP_Error( 'error', __( 'Malformed response from Taler backend', 'gnutaler' ) );
}
@@ -793,8 +761,7 @@ function gnutaler_init_gateway_class()
__('Refunds are disabled for this order. Check the refund_delay option for the Taler payment plugin.', 'gnutaler' ) );
case 404:
$refund_error = json_decode ($refund_body, $assoc=true);
- if (! $refund_error)
- {
+ if (! $refund_error) {
return new WP_Error( 'error',
sprintf( __( 'Unexpected failure %s without Taler error code from Taler backend', 'gnutaler' ),
$refund_http_status ) );
@@ -821,10 +788,12 @@ function gnutaler_init_gateway_class()
__('Wire transfer already happened. It is too late for a refund with Taler!', 'gnutaler' ) );
default:
$refund_error = json_decode ($refund_body, $assoc=true);
- if (! $refund_error)
+ if (! $refund_error) {
$ec = $refund_error['code'];
- else
+ }
+ else {
$ec = 0;
+ }
return new WP_Error( 'error',
sprintf( __('Unexpected failure %s/%s from Taler backend', 'gnutaler' ),
$refund_http_status,
@@ -837,55 +806,48 @@ function gnutaler_init_gateway_class()
/**
* Log $msg for debugging
*/
- function debug ($msg) : void
- {
+ function debug( $msg ) : void {
$this->log ("debug", $msg);
}
/**
* Log $msg as a informational
*/
- function info ($msg) : void
- {
+ function info( $msg ) : void {
$this->log ("info", $msg);
}
/**
* Log $msg as a notice
*/
- function notice ($msg) : void
- {
+ function notice( $msg ) : void {
$this->log ("notice", $msg);
}
/**
* Log $msg as a warning.
*/
- function warning ($msg) : void
- {
+ function warning( $msg ) : void {
$this->log ("warning", $msg);
}
/**
* Log $msg as an error
*/
- function error ($msg) : void
- {
+ function error( $msg ) : void {
$this->log ("error", $msg);
}
- function log ($level, $msg)
- {
+ function log( $level, $msg ) {
if (! self::$log_enabled )
return;
- if ( function_exists ('wp_get_current_user()') )
- {
+ if ( function_exists ('wp_get_current_user()') ) {
$user_id = wp_get_current_user();
- if (! isset( $user_id ))
+ if (! isset( $user_id )) {
$user_id = __( '<user ID not set>', 'gnutaler' );
+ }
}
- else
- {
+ else {
$user_id = 'Guest';
}
$order_id = $_GET['order_id'];
diff --git a/server-build/my-simple-cdd/profiles/reclaim.packages b/server-build/my-simple-cdd/profiles/reclaim.packages
new file mode 100644
index 0000000..34ea1e0
--- /dev/null
+++ b/server-build/my-simple-cdd/profiles/reclaim.packages
@@ -0,0 +1,24 @@
+screen
+gcc
+make
+autoconf
+automake
+libtool
+libmicrohttpd-dev
+libgcrypt-dev
+libsqlite3-dev
+gettext
+libgnutls28-dev
+libcurl4-gnutls-dev
+libunistring-dev
+libidn2-dev
+libjansson-dev
+openssl
+pkgconf
+libltdl-dev
+zlib1g-dev
+libsodium-dev
+python3.4
+texi2html
+texinfo
+gnunet //??? 0.13.1?