summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-08-20 11:31:32 +0200
committerChristian Grothoff <christian@grothoff.org>2020-08-20 11:31:32 +0200
commite51f9a6b84ecfa5ac5038cf98b697178d294168b (patch)
tree4bfeffcfaea0700726b3c92d6b0edea472f81fec
parent7edfc90ad029ac6d1c26893e7ec6536885ff5b06 (diff)
downloadwoocommerce-taler-e51f9a6b84ecfa5ac5038cf98b697178d294168b.tar.gz
woocommerce-taler-e51f9a6b84ecfa5ac5038cf98b697178d294168b.tar.bz2
woocommerce-taler-e51f9a6b84ecfa5ac5038cf98b697178d294168b.zip
logo
-rw-r--r--plugin/GNU-Taler-Payment-Gateway/assets/images/taler.pngbin0 -> 377176 bytes
-rw-r--r--plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php116
2 files changed, 64 insertions, 52 deletions
diff --git a/plugin/GNU-Taler-Payment-Gateway/assets/images/taler.png b/plugin/GNU-Taler-Payment-Gateway/assets/images/taler.png
new file mode 100644
index 0000000..bdffc3c
--- /dev/null
+++ b/plugin/GNU-Taler-Payment-Gateway/assets/images/taler.png
Binary files differ
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 1355a08..8d20638 100644
--- a/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php
+++ b/plugin/GNU-Taler-Payment-Gateway/class-wc-gnutaler-gateway.php
@@ -91,14 +91,6 @@ add_filter( 'woocommerce_payment_gateways', 'gnutaler_add_gateway_class' );
add_action( 'plugins_loaded', 'gnutaler_init_gateway_class' );
-add_filter( 'woocommerce_email_heading_customer_refunded_order', 'test_filter');
-
-function test_filter( $heading, $order_object)
-{
- return "FUNKY" . $heading;
-}
-
-
function gnutaler_init_gateway_class()
{
//Check if WooCommerce is active, if not then deactivate and show error message
@@ -581,9 +573,6 @@ function gnutaler_init_gateway_class()
/**
* Converts the order into a JSON format that can be send to the GNU Taler Backend.
*
- * The amount of the refund request can, at the moment, only be refunded in the currency 'KUDOS', which is the currency that the GNU Taler Payment system uses.
- * This will change in the future.
- *
* @param $order_id - To get the order from the WooCommerce Webshop
* @return array - return the JSON Format.
*/
@@ -599,13 +588,12 @@ function gnutaler_init_gateway_class()
$order_json = array(
'order' => array(
'amount' => $wc_order_currency . ':' . $wc_order_total_amount,
- 'summary' => 'Order from the merchant ' . $this->get_option('merchant_name') . ': ',
- // NOTE/FIXME/CLEANUP: This seems to interact with the
+ 'summary' => sprintf( 'Order %s from %s.',
+ $wc_order->get_order_number,
+ $this->get_option('merchant_name')),
+ // NOTE: This interacts with the
// 'add_action' call to invoke the 'callback_handler'
- // when the user goes to that URL!
- // Note that the classname must match (funky code,
- // especially given that above we use
- // 'strtolower(get_class($this))'!
+ // when the user goes to this URL!
'fulfillment_url' => get_home_url()
. '/?wc-api='
. strtolower(get_class($this))
@@ -717,7 +705,7 @@ function gnutaler_init_gateway_class()
$wc_order_status === 'completed' ) )
{
$this->error('The status of the order does not allow a refund' );
- return new WP_Error( 'error', 'The status of the order does not allow for a refund.' );
+ return new WP_Error( 'error', __('The status of the order does not allow for a refund.' ));
}
$refund_request = array(
@@ -725,7 +713,9 @@ function gnutaler_init_gateway_class()
'reason' => $reason,
);
$wc_order_id = $wc_order->get_order_key() . '-' . $wc_order->get_order_number();
- $refund_result = $this->call_api( 'POST', $backend_url . '/private/orders/' . $wc_order_id . '/refund', $refund_request);
+ $refund_result = $this->call_api( 'POST',
+ $backend_url . '/private/orders/' . $wc_order_id . '/refund',
+ $refund_request);
$refund_http_status = $refund_result['http_code'];
$refund_body = $refund_result['message'];
@@ -735,67 +725,89 @@ function gnutaler_init_gateway_class()
$refund_response = json_decode ($refund_body, $assoc=true);
if (! $refund_response)
{
- $this->error('Malformed 200 response from Taler backend: not even in JSON');
- return new WP_Error( 'error', 'Malformed response from Taler backend: not even in JSON');
+ $this->error( 'Malformed 200 response from Taler backend: not even in JSON' );
+ return new WP_Error( 'error', __( 'Malformed response from Taler backend' ));
}
$refund_uri = $refund_response['taler_refund_uri'];
$refund_url = $backend_url . '/orders/' . $wc_order_id;
if (! $refund_uri)
{
- $this->error('Malformed 200 response from Taler backend: lacks taler_refund_uri');
- return new WP_Error( 'error', 'Malformed response from Taler backend: lacks taler_refund_uri');
+ $this->error('Malformed 200 response from Taler backend: lacks taler_refund_uri');
+ return new WP_Error( 'error', __( 'Malformed response from Taler backend' ));
}
$wc_order->update_status( 'refunded' );
- $wc_order->add_order_note( 'Refund granted. Please ensure the customer clicks on '
- . $refund_url
- . ' to obtain the refund.' );
- $this->info('Successfully received refund redirect URI '
+ $this->debug('Successfully received refund redirect URI '
. $refund_uri
. ' from GNU Taler backend.' );
- // We MUST notfiy the customer about the link somehow. We
- // SHOULD hook the regular 'refund' notification of WooCommerce
- // as well, and *IF* that e-mail is enabled, we could skip this
- // block. (Alas, first let's hook the refund notification, and
- // then we still have to find out the setting on that.)
- global $woocommerce;
- $mailer = $woocommerce->mailer();
- $message_body = sprintf (__( 'Please open the page <a href="%s">%s</a> to receive a refund for your order %s.'),
- $refund_url,
+ // Notify the customer about the refund.
+ $email = $wc_order->get_billing_email ('view');
+ if (isset ($email))
+ {
+ global $woocommerce;
+
+ $mailer = $woocommerce->mailer();
+ $message_body = sprintf (__( 'Please open the page <a href="%s">%s</a> to obtain the refund.'),
$refund_url,
- $wc_order->get_order_number() );
- $message = $mailer->wrap_message(
- sprintf( __( 'You were refunded %s on your order %s.' ),
- $amount,
+ $refund_url);
+ $message = $mailer->wrap_message(
+ sprintf( __( 'You are eligible for a refund of %s on your order %s.' ),
+ wc_price ($amount, array('currency' => $wc_order->get_currency())),
$wc_order->get_order_number() ),
- $message_body );
- $mailer->send( $wc_order->get_billing_email ('view'),
- sprintf( __( 'Order %s refunded' ),
- $wc_order->get_order_number() ),
- $message );
+ $message_body );
+ if ($mailer->send( $email,
+ sprintf( __( 'Refund for your order %s' ),
+ $wc_order->get_order_number() ),
+ $message ) )
+ {
+ $wc_order->add_order_note( __('Refund notification sent to customer via email.'));
+ }
+ else
+ {
+ $wc_order->add_order_note( sprintf ( __('Refund granted, but failed to send customer e-mail notification! Please contact <a href="mailto:%s">%s</a> and ensure the customer clicks on %s to obtain the refund.'),
+ $email,
+ $email,
+ $refund_url);
+ }
+ }
+ else
+ {
+ $wc_order->add_order_note( sprintf( __( 'Refund granted, but customer e-mail unknown! Ensure the customer clicks on %s to obtain the refund!' ),
+ $refund_url);
+ }
return true;
case 404:
$refund_error = json_decode ($refund_body, $assoc=true);
if (! $refund_error)
{
- return new WP_Error( 'error', 'Unexpected failure ' . $refund_http_status . ' without Taler error code from Taler backend');
+ return new WP_Error( 'error',
+ sprintf( __( 'Unexpected failure %s without Taler error code from Taler backend'),
+ $refund_http_status ) );
}
$ec = $refund_error['code'];
switch ($ec)
{
case 2000: // TALER_EC_INSTANCE_UNKNOWN
- return new WP_Error( 'error', 'Instance unknown reported by Taler backend');
+ return new WP_Error( 'error',
+ __('Instance unknown reported by Taler backend'));
case 2601: // TALER_EC_REFUND_ORDER_ID_UNKNOWN
- return new WP_Error( 'error', 'Order unknown reported by Taler backend');
+ return new WP_Error( 'error',
+ __('Order unknown reported by Taler backend'));
default:
- return new WP_Error( 'error', 'Unexpected error ' . $ec . ' reported by Taler backend');
+ return new WP_Error( 'error',
+ sprintf( __('Unexpected error %s reported by Taler backend'),
+ $ec ) );
}
case 409:
- return new WP_Error( 'error', 'Requested refund amount exceeds original payment. This is not allowed!');
+ return new WP_Error( 'error',
+ __('Requested refund amount exceeds original payment. This is not allowed!') );
case 410:
- return new WP_Error( 'error', 'Wire transfer already happened. It is too late for a refund with Taler!');
+ return new WP_Error( 'error',
+ __('Wire transfer already happened. It is too late for a refund with Taler!') );
default:
- return new WP_Error( 'error', 'Unexpected failure ' . $refund_http_status . ' from Taler backend');
+ return new WP_Error( 'error',
+ sprintf( __('Unexpected failure %s from Taler backend'),
+ $refund_http_status) );
}
}