diff options
Diffstat (limited to 'src/GNU-taler-payment/class-wc-gnutaler-gateway.php')
-rw-r--r-- | src/GNU-taler-payment/class-wc-gnutaler-gateway.php | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/GNU-taler-payment/class-wc-gnutaler-gateway.php b/src/GNU-taler-payment/class-wc-gnutaler-gateway.php index 3160b46..04d394f 100644 --- a/src/GNU-taler-payment/class-wc-gnutaler-gateway.php +++ b/src/GNU-taler-payment/class-wc-gnutaler-gateway.php @@ -108,7 +108,6 @@ function gnutaler_init_gateway_class() $this->enabled = $this->get_option( 'enabled' ); $this->GNU_Taler_Backend_URL = $this->get_option( 'GNU_Taler_Backend_URL' ); $this->GNU_Taler_Backend_API_Key = $this->get_option( 'GNU_Taler_Backend_API_Key' ); - $this->Fulfillment_url = $this->get_option( 'Fulfillment_url' ); $this->Payment_url = $this->get_option( 'Payment_url' ); $this->Order_text = $this->get_option( 'Order_text' ); $this->merchant_information = $this->get_option( 'merchant_information' ); @@ -122,6 +121,8 @@ function gnutaler_init_gateway_class() wp_enqueue_script( 'WalletDetection', plugin_dir_url( __FILE__ ) . 'js/WalletDetection.js' ); } ); + add_action( 'woocommerce_api_'. strtolower( get_class($this) ), array( $this, 'callback_handler' ) ); + // This action hook saves the settings add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) ); } @@ -164,12 +165,6 @@ function gnutaler_init_gateway_class() 'description' => 'Set the API-key for the Authorization with the GNU Taler Backend.', 'default' => 'ApiKey sandbox', ), - 'Fulfillment_url' => array( - 'title' => 'GNU Taler Fulfillment URL', - 'type' => 'text', - 'description' => 'Set the URL where the customer should return after finishing the payment process.', - 'default' => get_home_url(), - ), 'Payment_url' => array( 'title' => 'GNU Taler Payment url', 'type' => 'text', @@ -198,6 +193,28 @@ function gnutaler_init_gateway_class() ); } + public function callback_handler(): void + { + + if ( isset( $_GET['order_id'] ) ) { + + $order_id_backend = $_GET['order_id']; + $order_id_array = explode('-', $order_id_backend); + $order_id_name = $order_id_array[0]; + $order_id = $order_id_array[1]; + $wc_order = wc_get_order($order_id_name); + + //Completes the order + $wc_order->payment_complete(); + + //Empties the shopping cart + WC()->cart->empty_cart(); + + wp_redirect(get_home_url() . '/checkout/order-received/' . $order_id . '/?key=' . $order_id_name); + exit; + } + } + /** * Sends a request to a url via HTTP. * @@ -478,13 +495,6 @@ function gnutaler_init_gateway_class() $order_request = $this->send_order_request( $backend_url, $order_json, $user_id, $order_id ); if ( $order_request['boolean'] ) { - //Completes the order - $wc_order->payment_complete(); - - //Empties the shopping cart - WC()->cart->empty_cart(); - - wc_add_notice($wc_order->get_currency()); //Returns that the payment process finished successfully and redirects the costumer to confirm the payment via GNU Taler $this->add_log_entry( 'transaction', 'Userid: ' . $user_id . ' - Orderid: ' . $order_id . ' - Customer is being redirected to the payment confirmation site' ); @@ -571,7 +581,7 @@ function gnutaler_init_gateway_class() $wc_order_total_amount = $wc_order->get_total(); $wc_order_currency = $wc_order->get_currency(); $wc_cart = WC()->cart->get_cart(); - $wc_order_id = $wc_order->get_order_key() . '_' . $wc_order->get_order_number(); + $wc_order_id = $wc_order->get_order_key() . '-' . $wc_order->get_order_number(); $merchant_option = $this->get_option( 'merchant_information' ); $wc_order_products_array = $this->mutate_products_to_json_format( $wc_cart, $wc_order_currency, $wc_order); @@ -582,7 +592,7 @@ function gnutaler_init_gateway_class() 'order' => array( 'amount' => $wc_order_currency . ':' . $wc_order_total_amount, 'summary' => 'Order from the merchant ' . $this->get_option('merchant_name') . ': ', - 'fulfillment_url' => $this->get_option( 'Fulfillment_url', get_home_url() ), + 'fulfillment_url' => get_home_url() . '/wc-api/wc_gnutaler_gateway', //'payment_url' => $this->get_option( 'Payment_url' ), 'order_id' => $wc_order_id, 'merchant' => $wc_order_merchant, @@ -818,7 +828,7 @@ function gnutaler_init_gateway_class() public function convert_refund_to_json( $order, $amount, $reason ): array { return array( - 'order_id' => $order->get_order_key() . '_' . $order->get_order_number(), + 'order_id' => $order->get_order_key() . '-' . $order->get_order_number(), 'refund' => $order->get_currency() . ':' . $amount, 'instance' => 'default', 'reason' => $reason, |