diff --git a/assets/js/checkout.js b/assets/js/checkout.js index ed88947..46d8c7a 100755 --- a/assets/js/checkout.js +++ b/assets/js/checkout.js @@ -510,14 +510,16 @@ const UnzerManager = { if (document.getElementById( 'unzer-invoice-id' ).value) { return true; } - if ( ! document.getElementById( 'unzer-invoice-dob' ).value) { - UnzerManager.error( unzer_i18n.errorDob || 'Please enter your date fo birth' ); - return false; - } if (UnzerManager.isB2B() && ! document.getElementById( 'unzer-invoice-company-type' ).value) { UnzerManager.error( unzer_i18n.errorCompanyType || 'Please enter your company type' ); return false; } + if (!UnzerManager.isB2B() || (UnzerManager.isB2B() && document.getElementById( 'unzer-invoice-company-type' ).value === 'sole')) { + if ( ! document.getElementById( 'unzer-invoice-dob' ).value) { + UnzerManager.error( unzer_i18n.errorDob || 'Please enter your date of birth' ); + return false; + } + } invoiceInstance.createResource() .then( function (result) { @@ -989,8 +991,29 @@ jQuery( UnzerManager.checkCountry(); const companyTypeInputContainer = document.getElementById( 'unzer-invoice-company-type-container' ); + const birthdate_form = document.getElementById('unzer-checkout-dob-row'); + const birthdate = document.getElementById('unzer-invoice-dob'); if (companyTypeInputContainer) { companyTypeInputContainer.style.display = UnzerManager.isB2B() ? 'block' : 'none'; + if (UnzerManager.isB2B()) { + if (document.getElementById('unzer-invoice-company-type').value === "sole") { + birthdate_form.style.display = "block"; + birthdate.setAttribute("required", "required"); + birthdate.name = "unzer-invoice-dob"; + } else { + birthdate_form.style.display = "none"; + birthdate.removeAttribute("required"); + birthdate.name = ""; + } + } else { + birthdate_form.style.display = "block"; + birthdate.setAttribute("required", "required"); + birthdate.name = "unzer-invoice-dob"; + } + } else { + birthdate_form.style.display = "block"; + birthdate.setAttribute("required", "required"); + birthdate.name = "unzer-invoice-dob"; } const placeOrderButton = document.querySelector( '#place_order' ); diff --git a/composer.json b/composer.json index 0b47ca3..7f94826 100755 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require": { - "unzerdev/php-sdk": "^3.7.0", + "unzerdev/php-sdk": "^3.11.0", "php": ">=7.1" } } diff --git a/includes/gateways/Invoice.php b/includes/gateways/Invoice.php index f14b29f..18f2af8 100755 --- a/includes/gateways/Invoice.php +++ b/includes/gateways/Invoice.php @@ -153,7 +153,7 @@ public function payment_fields() { } Util::getNonceField(); ?> -
+
@@ -194,15 +194,21 @@ public function process_payment( $order_id ) { 'result' => 'success', ); $order = wc_get_order( $order_id ); - $dob = Util::getNonceCheckedPostValue( 'unzer-invoice-dob' ); - $this->handleDateOfBirth( $order, $dob ); - $_POST['unzer-dob'] = $dob; // for unified handling in CustomerService and OrderService - if ( $order->get_billing_company() ) { + if ( !$order->get_billing_company() ) { + $dob = Util::getNonceCheckedPostValue('unzer-invoice-dob'); + $this->handleDateOfBirth($order, $dob); + $_POST['unzer-dob'] = $dob; // for unified handling in CustomerService and OrderService + } elseif ( $order->get_billing_company() ) { $companyType = (string) Util::getNonceCheckedPostValue( 'unzer-invoice-company-type' ); if ( empty( $companyType ) ) { throw new Exception( esc_html__( 'Please enter your company type', 'unzer-payments' ) ); } + if ($companyType === 'sole') { + $dob = Util::getNonceCheckedPostValue('unzer-invoice-dob'); + $this->handleDateOfBirth($order, $dob); + $_POST['unzer-dob'] = $dob; // for unified handling in CustomerService and OrderService + } $order->update_meta_data( Main::ORDER_META_KEY_COMPANY_TYPE, $companyType ); } $order->save_meta_data(); diff --git a/includes/services/PaymentService.php b/includes/services/PaymentService.php index 8a1e2cb..84095b6 100755 --- a/includes/services/PaymentService.php +++ b/includes/services/PaymentService.php @@ -32,7 +32,9 @@ public function __construct() { * @return Unzer */ public function getUnzerManager( AbstractGateway $paymentGateway = null ): Unzer { - return new Unzer( $paymentGateway ? $paymentGateway->get_private_key() : get_option( 'unzer_private_key' ) ); + $unzer = new Unzer( $paymentGateway ? $paymentGateway->get_private_key() : get_option( 'unzer_private_key' ) ); + $unzer->setClientIp($_SERVER['REMOTE_ADDR'] ?? null); + return $unzer; } /** @@ -67,7 +69,9 @@ public function getUnzerManagerForOrder( WC_Order $order = null ): Unzer { $privateKey = $specialPrivateKey; } } - return new Unzer( $privateKey ); + $unzer = new Unzer( $privateKey ); + $unzer->setClientIp($_SERVER['REMOTE_ADDR'] ?? null); + return $unzer; } public function performChargeOnAuthorization( $orderId, $amount = null ) { diff --git a/readme.txt b/readme.txt index 94e4a73..b1c2679 100755 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: Unzer Tags: payments, woocommerce Requires at least: 4.5 -Tested up to: 6.7 -Stable tag: 1.8.1 +Tested up to: 6.8 +Stable tag: 1.8.3 License: Apache-2.0 License URI: http://www.apache.org/licenses/LICENSE-2.0 Author URI: https://unzer.com @@ -61,6 +61,15 @@ Unzer is one of the leading payment companies in Europe. Over 70,000 retailers t ## Changelog ## +# 1.8.3 # +* Adaption Invoice as commerical customer + +# 1.8.2 # +* Compatibility update WP6.8 + +# 1.8.1 # +* Compatibility update + # 1.8.0 # * Added Direkt Bank Transfer as new payment method * Update PHP SDK diff --git a/unzer-payments.php b/unzer-payments.php index 0e5a7fa..7ea7fbd 100755 --- a/unzer-payments.php +++ b/unzer-payments.php @@ -5,10 +5,10 @@ * Description: Official Unzer Plugin * Author: Unzer * Author URI: https://www.unzer.com - * Version: 1.8.1 + * Version: 1.8.3 * License: Apache-2.0 * Requires at least: 4.5 - * Tested up to: 6.7 + * Tested up to: 6.8 * WC requires at least: 6.0 * WC tested up to: 9.7 * Text Domain: unzer-payments @@ -21,7 +21,7 @@ /** * Required minimums and constants */ -define( 'UNZER_VERSION', '1.8.1' ); +define( 'UNZER_VERSION', '1.8.3' ); define( 'UNZER_PLUGIN_TYPE_STRING', 'Unzer Payments' ); define( 'UNZER_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) ); define( 'UNZER_PLUGIN_PATH', __DIR__ . '/' );