Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions assets/js/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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' );
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"require": {
"unzerdev/php-sdk": "^3.7.0",
"unzerdev/php-sdk": "^3.11.0",
"php": ">=7.1"
}
}
16 changes: 11 additions & 5 deletions includes/gateways/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function payment_fields() {
}
Util::getNonceField();
?>
<div class="unzer-checkout-field-row form-row">
<div class="unzer-checkout-field-row form-row" id="unzer-checkout-dob-row">
<label><?php echo esc_html__( 'Date of birth', 'unzer-payments' ); ?></label>
<input type="date" id="unzer-invoice-dob" name="unzer-invoice-dob" class="input-text" value="<?php echo esc_attr( $this->getUserBirthDate() ); ?>" max="<?php echo esc_attr( gmdate( 'Y-m-d' ) ); ?>"/>
</div>
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions includes/services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 ) {
Expand Down
13 changes: 11 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions unzer-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__ . '/' );
Expand Down