diff options
-rw-r--r-- | plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php | 96 | ||||
-rw-r--r-- | plugin/GNU-Taler-Payment-Gateway/readme.txt | 59 | ||||
-rw-r--r-- | plugin/README.md | 14 | ||||
-rwxr-xr-x | server-build/QEMU-autobuild/buildWebstore.sh | 29 |
4 files changed, 64 insertions, 134 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 7e146cf..2e86b01 100644 --- a/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php +++ b/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php @@ -4,12 +4,11 @@ */ /** * Plugin Name: GNU Taler Payment for WooCommerce - * Plugin URI: https://github.com/Sakaeo/GNU-Taler-Plugin - * //Or Wordpress pluin URI + * Plugin URI: https://git.taler.net/woocommerce-taler * Description: This plugin enables payments via the GNU Taler payment system * Version: 1.0 - * Author: Hofmann Dominique & StrĂ¼bin Jan - * Author URI: + * Author: Hofmann Dominique & StrĂ¼bin Jan, Adaptations by Christian Grothoff + * Author URI: https://taler.net/ * * License: GNU General Public License v3.0 * License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -114,12 +113,13 @@ function gnutaler_init_gateway_class() $this->merchant_name = $this->get_option( 'merchant_name' ); //Here we add the Javascript files to the webserver - add_action( 'woocommerce_before_checkout_form', static function () { - wp_enqueue_script( 'taler-wallet-lib', plugin_dir_url( __FILE__ ) . 'js/taler-wallet-lib.js' ); - } ); - add_action( 'woocommerce_before_checkout_form', static function () { - wp_enqueue_script( 'WalletDetection', plugin_dir_url( __FILE__ ) . 'js/WalletDetection.js' ); - } ); + //NOTE: commented out for v0.8 as this is no longer needed/useful + //add_action( 'woocommerce_before_checkout_form', static function () { + // wp_enqueue_script( 'taler-wallet-lib', plugin_dir_url( __FILE__ ) . 'js/taler-wallet-lib.js' ); + //} ); + //add_action( 'woocommerce_before_checkout_form', static function () { + // wp_enqueue_script( 'WalletDetection', plugin_dir_url( __FILE__ ) . 'js/WalletDetection.js' ); + //} ); add_action( 'woocommerce_api_'. strtolower( get_class($this) ), array( $this, 'callback_handler' ) ); @@ -245,18 +245,14 @@ function gnutaler_init_gateway_class() * The request can be sent as POST, GET, PUT or another method. * * @param $method - POST, GET, PUT or another method. - * @param $backend_url - URL to the GNU Taler Backend. - * @param $body - The content of the request. - * @param $purpose - What return value is to be expected. + * @param $url - URL for the request to make to the GNU Taler Backend. + * @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. * @since 0.6.0 * */ - public function call_api( $method, $backend_url, $body, $purpose ): array + public function call_api( $method, $url, $body): array { - //create_url - $url = $this->create_api_url( $backend_url, $purpose, $body ); - //Initialize curl request $curl = $this->curl_init( $method, $body, $url ); @@ -308,7 +304,7 @@ function gnutaler_init_gateway_class() return array( 'result' => false, 'http_code' => $http_code, - 'message' => 'request', + 'message' => 'Bad request', ); break; case 401: @@ -374,7 +370,7 @@ function gnutaler_init_gateway_class() return array( 'result' => false, 'http_code' => $http_code, - 'message' => '5xx Client Error', + 'message' => '5xx Server Error', ); break; } @@ -417,6 +413,12 @@ function gnutaler_init_gateway_class() curl_setopt( $curl, CURLOPT_POSTFIELDS, $body ); } break; + case 'PATCH': + curl_setopt( $curl, CURLOPT_CUSTOMREQUEST, 'PATCH' ); + if ( $body ) { + curl_setopt( $curl, CURLOPT_POSTFIELDS, $body ); + } + break; case 'GET': curl_setopt( $curl, CURLOPT_VERBOSE, 1 ); break; @@ -438,39 +440,35 @@ function gnutaler_init_gateway_class() } /** - * Creates the final url depending on the purpose. - * - * @param $url - URL where the request will be send. - * @param $purpose - What will be added to the url. - * @param $body - Content of the request. - * @return string - return the final url. - * @since 0.6.0 - */ - public function create_api_url ($url, $purpose, $body ): string - { - if ( $purpose === 'create_order' ) { - return $url . '/order'; - } - if ( $purpose === 'confirm_payment' ) { - return $url . '/check-payment?order_id=' . $body; - } - if ( $purpose === 'create_refund' ) { - return $url . '/refund'; - } - return $url; - } - - /** * Verifying if the url to the backend given in the plugin options is valid or not. * * @param $url - URL to the backend + * @param $ecurrency - expected currency of the order * @return bool - Returns if valid or not. * @since 0.6.0 */ - public function verify_backend_url( $url ): bool + public function verify_backend_url( $url, $ecurrency ): bool { - $result = $this->call_api( 'GET', $url, '', '' ); - if ( $result['result'] ){ + $config = $this->call_api( 'GET', $url . '/config', false); + if ( $config['version'] ){ + $version = $config['version']; + // FIXME: add support for proper protocol version + // compatibility check here later! + if (0 != strcmp ($version, "1:0:0")) { + $this->add_log_entry ("ERROR", + "Backend protocol version " . + $version . + "unsupported"); + return false; + } + $currency = $config['currency']; + if (0 != strcasecmp ($currency, $ecurrency)) { + $this->add_log_entry ("ERROR", + "Backend currency " . + $currency . + " does not match order currency " . $ecurrency); + return false; + } return true; } return false; @@ -507,7 +505,7 @@ function gnutaler_init_gateway_class() //Log entry that the customer started the payment process $this->add_log_entry( 'transaction', 'Userid: ' . $user_id . ' - Orderid: ' . $order_id . ' - User started the payment process.' ); - if ( ! $this->verify_backend_url( $backend_url ) ) { + if ( ! $this->verify_backend_url( $backend_url, $wc_order->get_currency()) ) { wc_add_notice( 'Something went wrong please contact the system administrator of the webshop and send the following error: GNU Taler backend url invalid', 'error' ); $this->add_log_entry( 'error', 'Userid: ' . $user_id . ' - Orderid: ' . $order_id . ' - Checkout process failed - Invalid backend url.' ); return; @@ -549,7 +547,7 @@ function gnutaler_init_gateway_class() public function send_order_request( $backend_url, $json, $user_id, $order_id ): array { // Send the POST-Request via CURL to the GNU Taler Backend - $order_confirmation = $this->call_api( 'POST', $backend_url, json_encode($json, JSON_UNESCAPED_SLASHES), 'create_order' ); + $order_confirmation = $this->call_api( 'POST', $backend_url . '/order', json_encode($json, JSON_UNESCAPED_SLASHES)); $order_message = $order_confirmation['message']; $order_boolean = $order_confirmation['result']; @@ -558,7 +556,7 @@ function gnutaler_init_gateway_class() $order_confirmation_id = explode( '"', $order_message )[3]; // Send the final confirmation to execute the payment transaction to the GNU Taler Backend - $payment_confirmation = $this->call_api( 'GET', $backend_url, $order_confirmation_id, 'confirm_payment' ); + $payment_confirmation = $this->call_api( 'GET', $backend_url . '/check-payment?order_id=' . $order_confirmation_id, false); $payment_message = $payment_confirmation['message']; $payment_boolean = $order_confirmation['result']; @@ -808,7 +806,7 @@ function gnutaler_init_gateway_class() public function send_refund_request( $backend_url, $json ): array { $refund_url = ''; - $refund_confirmation = $this->call_api( 'POST', $backend_url, json_encode($json, JSON_UNESCAPED_SLASHES), 'create_refund' ); + $refund_confirmation = $this->call_api( 'POST', $backend_url . '/refund', json_encode($json, JSON_UNESCAPED_SLASHES) ); $message = $refund_confirmation['message']; $refund_boolean = $refund_confirmation['result']; diff --git a/plugin/GNU-Taler-Payment-Gateway/readme.txt b/plugin/GNU-Taler-Payment-Gateway/readme.txt deleted file mode 100644 index e298a0e..0000000 --- a/plugin/GNU-Taler-Payment-Gateway/readme.txt +++ /dev/null @@ -1,59 +0,0 @@ -=== GNU Taler Payment Gateway for Woocommerce === -Contributors: hofmd2, sakaeo -Donate link: https://donations.demo.taler.net/ -Tags: woocommerce, e-commerce, GNU Taler, Taler, Payment Gateway -Requires at least: 5.1 -Tested up to: 5.2.1 -Stable tag: 5.2 -Requires PHP: 7.2 -License: GNU General Public License v3.0 -License URI: http://www.gnu.org/licenses/gpl-3.0.html - -Online payment plugin for Woocommerce powered by GNU Taler - -== Description == - -This plugin provides a safe and secure way to pay via the GNU Taler system. The plugin sends a request to and receives a respones from the GNU Taler Backend. -After that the plugin confirms the transaction again and redirect the customer to his own wallet to confirm the transaction. -The plugin provides the possibilitiy for the admininstrator to send the costumer a refund. -For that the plugin sends a refund request to the GNU Taler backend and receives a refund-url, which will be forwarded to the customer via an email to confirm the refund. - -The GNU Taler payment system has some certificate and includes latest fraud and risk management. - -== Installation == - -1. Ensure you have latest version of WooCommerce plugin installed -2. Upload the plugin files to the `/wp-content/plugins/plugin-name` directory, or install the plugin through the WordPress plugins screen directly. -3. Activate the GNU Taler Payment for Woocommerce plugin through the 'Plugins' screen in WordPress. -4. Use WooCommerce settings-> payment tab -> GNU Taler Payment for Woocommerce Settings to configure the plugin. - -== Frequently Asked Questions == - -= Do I have to have a GNU Taler account to use the plugin? = - -Yes, you need to have an account. -You can join the GNU Taler family on: https://bank.demo.taler.net/ - -= Does the customer need to have the GNU Taler Wallet installed to pay with GNU Taler? = - -Yes, the customer needs the GNU Taler Wallet. -The customer can download it here: https://bank.demo.taler.net/ - - -= Can the plugin work without Woocommerce = - -For the plugin to work perfectly you need to have the Woocommerce plugin installed - -== Screenshots == - -1. No screenshots - -== Changelog == - -= 0.6.0 = -* First Public Release - -== Upgrade Notice == - -= 0.6.0 = - diff --git a/plugin/README.md b/plugin/README.md index c8fbcd3..f7fa636 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -3,7 +3,7 @@ GNU Taler plugin for WordPress with WooCommerce. === GNU Taler Payment Gateway for WooCommerce === -Contributors: hofmd2, sakaeo +Contributors: hofmd2, sakaeo, grothoff Donate link: https://donations.demo.taler.net/ Tags: WooCommerce, e-commerce, GNU Taler, Taler, Payment Gateway Requires at least: 5.1 @@ -23,7 +23,7 @@ Next, the plugin confirms the transaction again and redirects the customer to hi The plugin also provides the possibility for the administrator to send the custumer a refund. -For refunds, the plugin sends a refund request to the GNU Taler back-end and receives a refund- URL. This URL is forwarded to the customer via an e-mail to confirm the refund. +For refunds, the plugin sends a refund request to the GNU Taler back-end and receives a refund-URI. This URI is forwarded to the customer via an e-mail to confirm the refund. ### Security @@ -40,13 +40,13 @@ Will add later: The GNU Taler payment system has some certificate and includes l *Q: Do I have to have a GNU Taler account to use the plugin?* -A: Yes, you need to have an account. You can join the GNU Taler family on: https://bank.demo.taler.net/ +A: Yes, you need to have a "bank" account to withdraw cash. You can setup one easily at: https://bank.demo.taler.net/ *Q: Does the customer need to have the GNU Taler Wallet installed to pay with GNU Taler?* -A: Yes, the customer needs the GNU Taler Wallet. The customer can get a wallet here: https://bank.demo.taler.net/ +A: Yes, the customer needs the GNU Taler Wallet. The customer can get a wallet here: https://wallet.taler.net/ - *Q: Can the plugin work without WooCommerce* +*Q: Can the plugin work without WooCommerce* A: For the plugin to work correctly you need to have the WooCommerce plugin installed on a WordPress site @@ -58,4 +58,6 @@ A: For the plugin to work correctly you need to have the WooCommerce plugin inst == Upgrade Notice == -= 0.6.0 = += 0.8.0 = + +* Adaptations to GNU Taler Merchant API 1:0:0 diff --git a/server-build/QEMU-autobuild/buildWebstore.sh b/server-build/QEMU-autobuild/buildWebstore.sh index 56858b1..1c8c933 100755 --- a/server-build/QEMU-autobuild/buildWebstore.sh +++ b/server-build/QEMU-autobuild/buildWebstore.sh @@ -164,17 +164,9 @@ sudo -u www-data wp media import https://live.staticflickr.com/780/20907853650_0 sudo -u www-data wp media import https://live.staticflickr.com/2514/3806410714_90df3f5865_b.jpg sudo -u www-data wp media import https://live.staticflickr.com/7199/6929220523_1300f7e95b_b.jpg -echo -echo 'Okay, the shop is almost ready. But you have to set a few things up in the browser.' -echo -echo '1. You must configure the store to accept KUDOS. To do this:' -echo ' a. Log into the WooTaler site in your host system at 127.0.0.1:9999/wp-admin, using the admin username and password you set during this installation.' -echo ' b. Navigate the left menu to Snippets > Add New.' -echo ' c. Add "KUDOS Support" using the code in git://git.taler.net/woocommerce-taler.git/server-build/QEMU-autobuild/KUDOS-WooCommerce-Support.php.txt' -echo ' d. Click the radio buton for "Run snippet everywhere" and click "Save Changes and Activate"' -echo - - +# Add Snippet to enable KUDOS currency in WooCommerce +# Note: this will break the shop badly if run twice, +# recovery by deleting the duplicate entries! SNIPPET=`cat ${ORIGIN}/woocommerce-taler/server-build/QEMU-autobuild/KUDOS-WooCommerce-Support.php.txt` cat | mysql wordpress <<EOF @@ -186,18 +178,15 @@ EXECUTE stmt USING @name, @description, @code, "global", 10, 1, NOW(); EOF -echo -echo '2. You must set up WooCommerce defaults. To do this:' - echo ' a. Log into the WooTaler site in your host system at 127.0.0.1:9999/wp-admin/.' -echo ' b. Click on WooCommerce > Settings' -echo ' c. Under the "Payments" tab, enable and then "Set up" "GNU Taler Gatway"' - -sudo -u www-data wp wc --user=admin payment_gateway update gnutaler --enabled=true --settings='{"title":"GNU Taler","GNU_Taler_Backend_URL":"https:\/\/backend.demo.taler.net\/","GNU_Taler_Backend_API_Key":"Sandbox","Payment_url":"payto:\/\/x-taler-bank\/bank.demo.taler.net\/Merchant","merchant_name":"GNU Taler WooCommerce Demonstrator"}' +sudo -u www-data wp wc --user=admin payment_gateway update gnutaler --enabled=true --settings='{"title":"GNU Taler","GNU_Taler_Backend_URL":"http:\/\/backend.demo.taler.net\/","GNU_Taler_Backend_API_Key":"Sandbox","Payment_url":"payto:\/\/x-taler-bank\/bank.demo.taler.net\/Merchant","merchant_name":"GNU Taler WooCommerce Demonstrator"}' -echo ' d. Navigate to 127.0.0.1:9999/wp-admin/admin.php?page=wc-setup and go through the annoying WooCommerce setup wizard (Note that many options are enabled by default, and you have to turn them off.)' echo +echo '1. You must set up WooCommerce defaults. To do this:' +echo ' a. Log into the WooTaler site in your host system at 127.0.0.1:9999/wp-admin/. as "admin" with passphrase "admin-pass"' +echo ' b. Navigate to 127.0.0.1:9999/wp-admin/admin.php?page=wc-setup and go through the annoying WooCommerce setup wizard (Note that many options are enabled by default, and you have to turn them off.)' +echo ' c. Change the currency to KUDOS to make it work with the demo backend (or change the backend)' echo -echo '3. You might also want to add some images to the Product. There are some nice photos of a "kitten" in the Media Library.' +echo '2. You might also want to add some images to the Product. There are some nice photos of a "kitten" in the Media Library.' echo echo |