From 2226fc9cfcd8f61c1eccf1ebd106c45b1f37ebe4 Mon Sep 17 00:00:00 2001 From: Jacqueline Rinnhofer Date: Tue, 10 Apr 2018 16:00:38 +0200 Subject: [PATCH 1/5] #63 Force sending basket and consumerdata for ratepay --- .../classes/class-wirecard-config.php | 48 ++++++++++++++++++- .../classes/class-wirecard-gateway.php | 3 +- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php index b3b6338..3ed1420 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php @@ -240,11 +240,11 @@ public function get_consumer_data( $order, $gateway, $checkout_data ) { $user_data = get_userdata( $order->get_user_id() ); $consumerData->setEmail( isset( $user_data->user_email ) ? $user_data->user_email : '' ); - if ( $gateway->get_option( 'woo_wcs_forwardconsumerbillingdata' ) ) { + if ( $gateway->get_option( 'woo_wcs_forwardconsumerbillingdata' ) || $this->force_consumer_data( $checkout_data['wcs_payment_method'] ) ) { $billing_address = $this->get_address_data( $order, 'billing' ); $consumerData->addAddressInformation( $billing_address ); } - if ( $gateway->get_option( 'woo_wcs_forwardconsumershippingdata' ) ) { + if ( $gateway->get_option( 'woo_wcs_forwardconsumershippingdata' ) || $this->force_consumer_data( $checkout_data['wcs_payment_method'] ) ) { $shipping_address = $this->get_address_data( $order, 'shipping' ); $consumerData->addAddressInformation( $shipping_address ); } @@ -257,6 +257,50 @@ public function get_consumer_data( $order, $gateway, $checkout_data ) { return $consumerData; } + /** + * Force sending data for invoice and installment + * + * @param $payment_method + * + * @since 1.0.15 + * @return bool + */ + public function force_consumer_data( $payment_method ) { + switch ( $payment_method ) { + case WirecardCEE_Stdlib_PaymentTypeAbstract::INVOICE: + case WirecardCEE_Stdlib_PaymentTypeAbstract::INSTALLMENT: + return true; + default: + return false; + } + } + + /** + * Force sending basket data for invoice and installment via ratepay + * + * @param $payment_method + * @param $gateway + * + * @since 1.0.15 + * @return bool + */ + public function force_basket_data( $payment_method, $gateway ) { + switch ( $payment_method ) { + case WirecardCEE_Stdlib_PaymentTypeAbstract::INVOICE: + if ( 'payolution' != $gateway->get_option('woo_wcs_invoiceprovider') ) { + return true; + } + return false; + case WirecardCEE_Stdlib_PaymentTypeAbstract::INSTALLMENT: + if ( 'payolution' != $gateway->get_option('woo_wcs_installmentprovider') ) { + return true; + } + return false; + default: + return false; + } + } + /** * Generate address data (shipping or billing) * diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php index 2a4e738..ff30e8b 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php @@ -560,7 +560,8 @@ public function initiate_payment( $order ) { $client->setConfirmMail( get_bloginfo( 'admin_email' ) ); } - if ( $this->get_option( 'woo_wcs_forwardbasketdata' ) ) { + if ( $this->get_option( 'woo_wcs_forwardbasketdata' ) + || ( $this->_config->force_basket_data( $checkout_data['wcs_payment_method'], $this ) ) ) { $client->setBasket( $this->_config->get_shopping_basket() ); } From c190850c029fa064b531db33618bfc419b1edd7b Mon Sep 17 00:00:00 2001 From: Jacqueline Rinnhofer Date: Thu, 12 Apr 2018 13:20:29 +0200 Subject: [PATCH 2/5] #63 Update refund validation for ratepay --- .../classes/class-wirecard-admin.php | 2 +- .../classes/class-wirecard-backend-operations.php | 15 ++++++--------- .../classes/class-wirecard-gateway.php | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-admin.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-admin.php index bdc48c4..af98123 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-admin.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-admin.php @@ -406,7 +406,7 @@ public function print_transaction_details( $data ) { echo "
"; if ( $brand == 'Invoice' ) { - echo ""; + echo ""; } elseif ( $operation == 'DEPOSIT' or $operation == 'REFUND' ) { echo ""; } diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php index 108f072..96a5c38 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php @@ -86,12 +86,11 @@ public function __construct( $settings ) { * * @return bool|WP_Error */ - public function refund() { + public function refund( $order_id = 0, $amount = 0, $reason = '' ) { global $wpdb; $order_id = $_POST['order_id']; $refund_amount = $_POST['refund_amount']; - if ( $refund_amount <= 0 ) { $this->_logger->error( __( 'Refund amount must be greater than zero.', 'woocommerce-wirecard-checkout-seamless' ) ); @@ -132,24 +131,21 @@ public function refund() { $basket = null; - if ( in_array( 'REFUND', $order->getOperationsAllowed() ) ) { - - if ( ( - $tx_data->payment_method == WirecardCEE_QMore_PaymentType::INSTALLMENT + $tx_data->payment_method == WirecardCEE_Stdlib_PaymentTypeAbstract::INVOICE && $this->_settings['woo_wcs_invoiceprovider'] != 'payolution' ) or ( $tx_data->payment_method == WirecardCEE_QMore_PaymentType::INSTALLMENT - && $this->_settings['woo_wcs_invoiceprovider'] != 'payolution' + && $this->_settings['woo_wcs_installmentprovider'] != 'payolution' ) ) { if ( $total_items == 0 ) { // invoice / installment provider is set to ratepay / wirecard and basket items were not sent - $this->_logger->error( __METHOD__ . ': basket needs to be defined for ' . $this->_settings['woo_wcs_invoiceprovider'] . ' during refund.' ); + $this->_logger->error( __METHOD__ . ': basket needs to be defined for ratepay during refund.' ); return false; } else { @@ -167,8 +163,9 @@ public function refund() { $price->tax_amount = $price->gross - $price->net; $price->tax_rate = $price->tax_amount / $price->net; + $description = strlen( $wc_product->get_short_description() ) != 0 ? $wc_product->get_short_description() : $wc_product->get_name(); $basket_item->setName( $wc_product->get_name() ) - ->setDescription( $wc_product->get_short_description() ) + ->setDescription( $description ) ->setImageUrl( wp_get_attachment_image_url( $wc_product->get_image_id() ) ) ->setUnitNetAmount( wc_format_decimal( $price->net, wc_get_price_decimals() ) ) ->setUnitGrossAmount( wc_format_decimal( $price->gross, wc_get_price_decimals() ) ) diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php index ff30e8b..b7a9fa5 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-gateway.php @@ -403,7 +403,7 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) { $backend_operations = new WC_Gateway_Wirecard_Checkout_Seamless_Backend_Operations( $this->settings ); - return $backend_operations->refund(); + return $backend_operations->refund( $order_id, $amount, $reason ); } /** From 14081068f4971f27be902445f51988395c9b0798 Mon Sep 17 00:00:00 2001 From: Jacqueline Rinnhofer Date: Mon, 16 Apr 2018 08:06:45 +0200 Subject: [PATCH 3/5] #63 Add partial refund basket and update default refund basket for full refund --- .../class-wirecard-backend-operations.php | 135 +++++++++++++----- .../classes/class-wirecard-config.php | 2 +- ...woocommerce-wirecard-checkout-seamless.php | 2 +- 3 files changed, 101 insertions(+), 38 deletions(-) diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php index 96a5c38..a799f13 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php @@ -144,44 +144,25 @@ public function refund( $order_id = 0, $amount = 0, $reason = '' ) { ) ) { if ( $total_items == 0 ) { - // invoice / installment provider is set to ratepay / wirecard and basket items were not sent - $this->_logger->error( __METHOD__ . ': basket needs to be defined for ratepay during refund.' ); + $basket = $this->create_basket_without_items( $refund_amount, $wc_order ); + $order_data = $wc_order->get_data(); + $response_with_basket = $this->get_client()->refund( $wcs_order_number, $order_data['total'], $order->getCurrency(), $basket ); + if ( $response_with_basket->hasFailed() ) { + $this->logResponseErrors( __METHOD__, $response_with_basket->getErrors() ); + + return false; + } else { + return true; + } + } + $basket = $this->create_basket( $refund_items, $wc_order); + $response_with_basket = $this->get_client()->refund( $wcs_order_number, $refund_amount, $order->getCurrency(), $basket ); + if ( $response_with_basket->hasFailed() ) { + $this->logResponseErrors( __METHOD__, $response_with_basket->getErrors() ); - return false; + return false; } else { - $basket = new WirecardCEE_Stdlib_Basket(); - foreach ( $refund_items as $item_id => $item ) { - if ( $item['refund_qty'] < 1 ) {// $wc_order_items[ $item_id ] == null ) { - continue; - } - $wc_product = new WC_Product( $wc_order_items[ $item_id ]->get_product_id() ); - $basket_item = new WirecardCEE_Stdlib_Basket_Item( $wc_product->get_id(), $item['refund_qty'] ); - - $price = new stdClass(); - $price->net = wc_get_price_excluding_tax( $wc_product ); - $price->gross = wc_get_price_including_tax( $wc_product ); - $price->tax_amount = $price->gross - $price->net; - $price->tax_rate = $price->tax_amount / $price->net; - - $description = strlen( $wc_product->get_short_description() ) != 0 ? $wc_product->get_short_description() : $wc_product->get_name(); - $basket_item->setName( $wc_product->get_name() ) - ->setDescription( $description ) - ->setImageUrl( wp_get_attachment_image_url( $wc_product->get_image_id() ) ) - ->setUnitNetAmount( wc_format_decimal( $price->net, wc_get_price_decimals() ) ) - ->setUnitGrossAmount( wc_format_decimal( $price->gross, wc_get_price_decimals() ) ) - ->setUnitTaxAmount( wc_format_decimal( $price->tax_amount, wc_get_price_decimals() ) ) - ->setUnitTaxRate( wc_format_decimal( $price->tax_rate, 3 ) ); - - $basket->addItem( $basket_item ); - } - $response_with_basket = $this->get_client()->refund( $wcs_order_number, $refund_amount, $order->getCurrency(), $basket ); - if ( $response_with_basket->hasFailed() ) { - $this->logResponseErrors( __METHOD__, $response_with_basket->getErrors() ); - - return false; - } else { - return true; - } + return true; } } else { @@ -213,6 +194,88 @@ public function refund( $order_id = 0, $amount = 0, $reason = '' ) { return false; } + /** + * Create basket with items + * + * @since 1.0.15 + * + * @param $refund_items + * @param $wc_order + * @return WirecardCEE_Stdlib_Basket + */ + public function create_basket( $refund_items, $wc_order ) { + $wc_order_items = $wc_order->get_items(); + $basket = new WirecardCEE_Stdlib_Basket(); + $sum = 0; + foreach ( $wc_order_items as $item_id => $item ) { + if ( $refund_items[$item_id]['refund_qty'] < 1 ) { + continue; + } + $wc_product = new WC_Product( $wc_order_items[ $item_id ]->get_product_id() ); + $sum += number_format( wc_get_price_including_tax( $wc_product ), wc_get_price_decimals() ); + $basket_item = new WirecardCEE_Stdlib_Basket_Item( $wc_product->get_id(), $refund_items[$item_id]['refund_qty'] ); + + + $tax = wc_get_price_including_tax($wc_product) - wc_get_price_excluding_tax($wc_product); + $item_tax_rate = $tax / wc_get_price_excluding_tax( $wc_product ); + + $description = $wc_product->get_short_description(); + $tax_rate = 0; + if ( $wc_product->is_taxable() ) { + $tax_rate = floatval(number_format( $item_tax_rate, 3 )); + } + + $basket_item->setName( $wc_product->get_name() ) + ->setDescription( $description ) + ->setImageUrl( wp_get_attachment_image_url( $wc_product->get_image_id() ) ) + ->setUnitNetAmount( wc_format_decimal( wc_get_price_excluding_tax( $wc_product ), wc_get_price_decimals() ) ) + ->setUnitGrossAmount( wc_format_decimal( wc_get_price_including_tax( $wc_product ), wc_get_price_decimals() ) ) + ->setUnitTaxAmount( wc_format_decimal( $tax, wc_get_price_decimals() ) ) + ->setUnitTaxRate( $tax_rate ); + + $basket->addItem( $basket_item ); + } + return $basket; + } + + /** + * Create basket with items + * + * @since 1.0.15 + * + * @param $refund_items + * @param $wc_order + * @return WirecardCEE_Stdlib_Basket + */ + public function create_basket_without_items( $refund_amount, $wc_order ) { + $order_data = $wc_order->get_data(); + + $basket = new WirecardCEE_Stdlib_Basket(); + $basket_item = new WirecardCEE_Stdlib_Basket_Item( 'Total refund ratepay' , 1); + + $tax = $order_data['total_tax']; + $net = $order_data['total'] - $order_data['total_tax']; + $item_unit_gross_amount = $order_data['total']; + $item_tax_rate = $tax / $net; + + $description = 'Refund full amount of order'; + $tax_rate = 0; + if ($tax > 0) { + $tax_rate = floatval(number_format($item_tax_rate, 3)); + } + + $basket_item->setName('Full Refund Order') + ->setDescription($description) + ->setImageUrl() + ->setUnitNetAmount(wc_format_decimal($net, wc_get_price_decimals())) + ->setUnitGrossAmount(wc_format_decimal($item_unit_gross_amount, wc_get_price_decimals())) + ->setUnitTaxAmount(wc_format_decimal($tax, wc_get_price_decimals())) + ->setUnitTaxRate($tax_rate); + $basket->addItem($basket_item); + + return $basket; + } + /** * get the wirecard order details * diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php index 3ed1420..1805b97 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php @@ -31,7 +31,7 @@ */ define( 'WOOCOMMERCE_GATEWAY_WCS_NAME', 'WirecardCheckoutSeamless' ); -define( 'WOOCOMMERCE_GATEWAY_WCS_VERSION', '1.0.14' ); +define( 'WOOCOMMERCE_GATEWAY_WCS_VERSION', '1.0.15' ); /** * Config class diff --git a/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php b/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php index 9c363fa..a1a565e 100644 --- a/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php +++ b/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php @@ -3,7 +3,7 @@ * Plugin Name: Wirecard Checkout Seamless * Plugin URI: https://github.com/wirecard/woocommerce-wcs * Description: Wirecard Checkout Seamless plugin for WooCommerce - * Version: 1.0.13 + * Version: 1.0.15 * Author: Wirecard * Author URI: https://www.wirecard.at/ * License: GPL2 From cb0fb1687fb295248b84f6d18777c6febbecef2b Mon Sep 17 00:00:00 2001 From: Jacqueline Rinnhofer Date: Mon, 23 Apr 2018 17:16:34 +0200 Subject: [PATCH 4/5] #63 Update article number if sku --- .../classes/class-wirecard-backend-operations.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php index a799f13..f466d15 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php @@ -212,8 +212,14 @@ public function create_basket( $refund_items, $wc_order ) { continue; } $wc_product = new WC_Product( $wc_order_items[ $item_id ]->get_product_id() ); + + $article_nr = $wc_product->get_id(); + if ( $wc_product->get_sku() != '' ) { + $article_nr = $wc_product->get_sku(); + } + $sum += number_format( wc_get_price_including_tax( $wc_product ), wc_get_price_decimals() ); - $basket_item = new WirecardCEE_Stdlib_Basket_Item( $wc_product->get_id(), $refund_items[$item_id]['refund_qty'] ); + $basket_item = new WirecardCEE_Stdlib_Basket_Item( $article_nr, $refund_items[$item_id]['refund_qty'] ); $tax = wc_get_price_including_tax($wc_product) - wc_get_price_excluding_tax($wc_product); @@ -231,7 +237,7 @@ public function create_basket( $refund_items, $wc_order ) { ->setUnitNetAmount( wc_format_decimal( wc_get_price_excluding_tax( $wc_product ), wc_get_price_decimals() ) ) ->setUnitGrossAmount( wc_format_decimal( wc_get_price_including_tax( $wc_product ), wc_get_price_decimals() ) ) ->setUnitTaxAmount( wc_format_decimal( $tax, wc_get_price_decimals() ) ) - ->setUnitTaxRate( $tax_rate ); + ->setUnitTaxRate( $tax_rate * 100 ); $basket->addItem( $basket_item ); } From dacbf9d22d028d29a0f01c6118403009f5081023 Mon Sep 17 00:00:00 2001 From: Jacqueline Rinnhofer Date: Tue, 24 Apr 2018 08:16:32 +0200 Subject: [PATCH 5/5] #66 Update version --- .../classes/class-wirecard-backend-operations.php | 4 ++-- .../classes/class-wirecard-config.php | 6 +++--- .../woocommerce-wirecard-checkout-seamless.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php index f466d15..f9e672c 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-backend-operations.php @@ -197,7 +197,7 @@ public function refund( $order_id = 0, $amount = 0, $reason = '' ) { /** * Create basket with items * - * @since 1.0.15 + * @since 1.0.16 * * @param $refund_items * @param $wc_order @@ -247,7 +247,7 @@ public function create_basket( $refund_items, $wc_order ) { /** * Create basket with items * - * @since 1.0.15 + * @since 1.0.16 * * @param $refund_items * @param $wc_order diff --git a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php index 1805b97..ca47a8f 100644 --- a/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php +++ b/woocommerce-wirecard-checkout-seamless/classes/class-wirecard-config.php @@ -31,7 +31,7 @@ */ define( 'WOOCOMMERCE_GATEWAY_WCS_NAME', 'WirecardCheckoutSeamless' ); -define( 'WOOCOMMERCE_GATEWAY_WCS_VERSION', '1.0.15' ); +define( 'WOOCOMMERCE_GATEWAY_WCS_VERSION', '1.0.16' ); /** * Config class @@ -262,7 +262,7 @@ public function get_consumer_data( $order, $gateway, $checkout_data ) { * * @param $payment_method * - * @since 1.0.15 + * @since 1.0.16 * @return bool */ public function force_consumer_data( $payment_method ) { @@ -281,7 +281,7 @@ public function force_consumer_data( $payment_method ) { * @param $payment_method * @param $gateway * - * @since 1.0.15 + * @since 1.0.16 * @return bool */ public function force_basket_data( $payment_method, $gateway ) { diff --git a/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php b/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php index a1a565e..baeb31c 100644 --- a/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php +++ b/woocommerce-wirecard-checkout-seamless/woocommerce-wirecard-checkout-seamless.php @@ -3,7 +3,7 @@ * Plugin Name: Wirecard Checkout Seamless * Plugin URI: https://github.com/wirecard/woocommerce-wcs * Description: Wirecard Checkout Seamless plugin for WooCommerce - * Version: 1.0.15 + * Version: 1.0.16 * Author: Wirecard * Author URI: https://www.wirecard.at/ * License: GPL2