Skip to content

Commit 1f91448

Browse files
Release 3.0.2
1 parent 42f9ef2 commit 1f91448

9 files changed

+106
-87
lines changed

changelog.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,3 +727,18 @@ Tested against:
727727
- [Tested Against] Woocommerce 8.5.2
728728
- [Tested Against] PHP SDK 4.0.2
729729

730+
= 3.0.1 - April 3 2024 =
731+
- [Feature] Added support to High Performance Order Storage (HPOS).
732+
- [Tested Against] PHP 8.2
733+
- [Tested Against] Wordpress 6.5
734+
- [Tested Against] Woocommerce 8.7.0
735+
- [Tested Against] PHP SDK 4.0.2
736+
737+
= 3.0.2 - April 22 2024 =
738+
- [Hotfix] Fixed completion in the backend with coupon.
739+
- [Hotfix] Fixed tax amount not sent correctly to the portal.
740+
- [Tested Against] PHP 8.2
741+
- [Tested Against] Wordpress 6.5
742+
- [Tested Against] Woocommerce 8.7.0
743+
- [Tested Against] PHP SDK 4.0.2
744+

includes/admin/class-wc-postfinancecheckout-admin-document.php

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -113,50 +113,35 @@ public static function add_buttons_to_overview( WC_Order $order ) {
113113

114114
/**
115115
* Add WC Meta boxes.
116+
* @see: https://woo.com/document/high-performance-order-storage/#section-8
116117
*/
117118
public static function add_meta_box() {
118-
global $post;
119-
if ( 'shop_order' !== $post->post_type ) {
120-
return;
121-
}
122-
$order = WC_Order_Factory::get_order( $post->ID );
123-
$method = wc_get_payment_gateway_by_order( $order );
124-
if ( ! ( $method instanceof WC_PostFinanceCheckout_Gateway ) ) {
125-
return;
126-
}
127-
$transaction_info = WC_PostFinanceCheckout_Entity_Transaction_Info::load_by_order_id( $order->get_id() );
128-
if ( $transaction_info->get_id() !== null && in_array(
129-
$transaction_info->get_state(),
119+
$screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' )
120+
&& wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
121+
? wc_get_page_screen_id( 'shop-order' )
122+
: 'shop_order';
123+
add_meta_box(
124+
'woocommerce-order-postfinancecheckout-documents',
125+
__( 'PostFinance Checkout Documents', 'woo-postfinancecheckout' ),
130126
array(
131-
\PostFinanceCheckout\Sdk\Model\TransactionState::COMPLETED,
132-
\PostFinanceCheckout\Sdk\Model\TransactionState::FULFILL,
133-
\PostFinanceCheckout\Sdk\Model\TransactionState::DECLINE,
127+
__CLASS__,
128+
'output',
134129
),
135-
true
136-
) ) {
137-
add_meta_box(
138-
'woocommerce-order-postfinancecheckout-documents',
139-
__( 'PostFinance Checkout Documents', 'woo-postfinancecheckout' ),
140-
array(
141-
__CLASS__,
142-
'output',
143-
),
144-
'shop_order',
145-
'side',
146-
'default'
147-
);
148-
}
130+
$screen,
131+
'side',
132+
'default'
133+
);
149134
}
150135

151136
/**
152137
* Output the metabox.
153138
*
154-
* @param WP_Post $post Post.
139+
* @param WP_Post|WP_Order $post_or_order_object
140+
* This object is provided by woocommerce when using its screen.
155141
*/
156-
public static function output( $post ) {
157-
global $post;
142+
public static function output( $post_or_order_object ) {
143+
$order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object;
158144

159-
$order = WC_Order_Factory::get_order( $post->ID );
160145
$method = wc_get_payment_gateway_by_order( $order );
161146
if ( ! ( $method instanceof WC_PostFinanceCheckout_Gateway ) ) {
162147
return;

includes/admin/class-wc-postfinancecheckout-admin-order-completion.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ public static function execute_completion() {
213213
}
214214

215215
try {
216+
//the order id is saved for later use
217+
//e.g. use the order id to check if the order has a discount applied to it
218+
WC()->session->set( 'postfinancecheckout_order_id', $order_id );
216219
self::update_line_items( $current_completion_id );
217220
self::send_completion( $current_completion_id );
218221

includes/admin/class-wc-postfinancecheckout-admin-transaction.php

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,45 +41,35 @@ public static function init() {
4141

4242
/**
4343
* Add WC Meta boxes.
44+
* @see: https://woo.com/document/high-performance-order-storage/#section-8
4445
*/
4546
public static function add_meta_box() {
46-
global $post;
47-
if ( 'shop_order' != $post->post_type ) {
48-
return;
49-
}
50-
$order = WC_Order_Factory::get_order( $post->ID );
51-
$method = wc_get_payment_gateway_by_order( $order );
52-
if ( ! ( $method instanceof WC_PostFinanceCheckout_Gateway ) ) {
53-
return;
54-
}
55-
$transaction_info = WC_PostFinanceCheckout_Entity_Transaction_Info::load_by_order_id( $order->get_id() );
56-
if ( $transaction_info->get_id() == null ) {
57-
$transaction_info = WC_PostFinanceCheckout_Entity_Transaction_Info::load_newest_by_mapped_order_id( $order->get_id() );
58-
}
59-
if ( $transaction_info->get_id() != null ) {
60-
add_meta_box(
61-
'woocommerce-order-postfinancecheckout-transaction',
62-
__( 'PostFinance Checkout Transaction', 'woocommerc-postfinancecheckout' ),
63-
array(
64-
__CLASS__,
65-
'output',
66-
),
67-
'shop_order',
68-
'normal',
69-
'default'
70-
);
71-
}
47+
$screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' )
48+
&& wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
49+
? wc_get_page_screen_id( 'shop-order' )
50+
: 'shop_order';
51+
add_meta_box(
52+
'woocommerce-order-postfinancecheckout-transaction',
53+
__( 'PostFinance Checkout Transaction', 'woocommerce-postfinancecheckout' ),
54+
array(
55+
__CLASS__,
56+
'output',
57+
),
58+
$screen,
59+
'normal',
60+
'default'
61+
);
7262
}
7363

7464
/**
7565
* Output the metabox.
7666
*
77-
* @param WP_Post $post post data.
67+
* @param WP_Post|WP_Order $post_or_order_object
68+
* This object is provided by woocommerce when using its screen.
7869
*/
79-
public static function output( $post ) {
80-
global $post;
70+
public static function output( $post_or_order_object ) {
71+
$order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object;
8172

82-
$order = WC_Order_Factory::get_order( $post->ID );
8373
$method = wc_get_payment_gateway_by_order( $order );
8474
if ( ! ( $method instanceof WC_PostFinanceCheckout_Gateway ) ) {
8575
return;
@@ -129,7 +119,7 @@ public static function output( $post ) {
129119
<td class="value"><strong><?php esc_html_e( $transaction_info->get_order_id() ); ?></strong></td>
130120
</tr>
131121
<?php endif; ?>
132-
122+
133123
<?php if ( $transaction_info->get_failure_reason() != null ) : ?>
134124
<tr>
135125
<td class="label"><label><?php esc_html_e( 'Failure Reason', 'woo-postfinancecheckout' ); ?></label></td>
@@ -155,7 +145,7 @@ public static function output( $post ) {
155145
</tbody>
156146
</table>
157147
</div>
158-
148+
159149

160150
<?php if ( ! empty( $labels_by_group ) ) : ?>
161151
<?php foreach ( $labels_by_group as $group ) : ?>
@@ -177,7 +167,7 @@ public static function output( $post ) {
177167
</table>
178168
</div>
179169
</div>
180-
170+
181171
<?php endforeach; ?>
182172
<?php endif; ?>
183173
</div>

includes/class-wc-postfinancecheckout-helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public function get_total_amount_including_tax( array $line_items, bool $exclude
218218
//convert negative values to positive in order to be able to subtract it
219219
$sum -= abs( $line_item->getAmountIncludingTax() );
220220
} else {
221-
$sum += $line_item->getAmountIncludingTax();
221+
$sum += abs( $line_item->getAmountIncludingTax() );
222222
}
223223
}
224224
return $sum;
@@ -235,7 +235,7 @@ public function get_total_amount_including_tax( array $line_items, bool $exclude
235235
*/
236236
public function cleanup_line_items( array $line_items, $expected_sum, $currency ) {
237237
//ensure that the effective sum coincides with the total discounted by the coupons
238-
$has_coupons = apply_filters( 'wc_postfinancecheckout_packages_coupon_cart_has_coupon_discounts_applied', $currency );
238+
$has_coupons = apply_filters( 'wc_postfinancecheckout_packages_coupon_has_coupon_discounts_applied', $currency );
239239
$effective_sum = $this->round_amount( $this->get_total_amount_including_tax( $line_items, $has_coupons ), $currency );
240240
$rounded_expected_sum = $this->round_amount( $expected_sum, $currency );
241241

includes/packages/coupon/class-wc-postfinancecheckout-packages-coupon-discount.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public static function init() {
4848
1
4949
);
5050
add_filter(
51-
'wc_postfinancecheckout_packages_coupon_cart_has_coupon_discounts_applied',
51+
'wc_postfinancecheckout_packages_coupon_has_coupon_discounts_applied',
5252
array(
5353
__CLASS__,
54-
'has_cart_coupon_discounts_applied',
54+
'has_coupon_discounts_applied',
5555
),
5656
10,
5757
1
@@ -111,8 +111,17 @@ public static function copy_total_coupon_discount_meta_data_to_order_item( WC_Or
111111
public static function get_coupons_discount_totals_including_tax( $currency ) {
112112
$coupons_discount_total = 0;
113113

114+
//guard clause if the order doesn't exists, nothing to do here.
115+
$order_id = WC()->session->get( 'postfinancecheckout_order_id' );
116+
if ( WC()->cart->get_cart_contents_count() == 0 && !is_null( $order_id ) ) {
117+
118+
if ( $order = wc_get_order( $order_id ) ) {
119+
$coupons_discount_total += $order->get_total_discount();
120+
}
121+
}
122+
114123
//guard clause if the cart is empty, nothing to do here. This applies to subscription renewals
115-
if ( empty( WC()->cart ) ) {
124+
if ( empty( WC()->cart->get_cart_contents_count() ) ) {
116125
return $coupons_discount_total;
117126
}
118127

@@ -129,7 +138,7 @@ public static function get_coupons_discount_totals_including_tax( $currency ) {
129138
* @param $currency
130139
* @return bool
131140
*/
132-
public static function has_cart_coupon_discounts_applied( $currency ) {
141+
public static function has_coupon_discounts_applied( $currency ) {
133142
$discount = apply_filters( 'wc_postfinancecheckout_packages_coupon_discount_totals_including_tax', $currency );
134143
return $discount > 0;
135144
}
@@ -184,6 +193,7 @@ public static function get_coupon_percentage_discount_by_item( string $item_key
184193
* @return array<mixed>
185194
*/
186195
public static function process_line_items_with_coupons( array $line_items, float $expected_sum, string $currency ) {
196+
$line_item_coupons = [];
187197
$exclude_discounts = true;
188198
$amount = WC_PostFinanceCheckout_Helper::instance()->get_total_amount_including_tax( $line_items, $exclude_discounts);
189199
$effective_sum = WC_PostFinanceCheckout_Helper::instance()->round_amount( $amount , $currency );
@@ -195,6 +205,7 @@ public static function process_line_items_with_coupons( array $line_items, float
195205
foreach ( $line_items as $line_item ) {
196206
if ( $line_item->getType() == \PostFinanceCheckout\Sdk\Model\LineItemType::DISCOUNT ) {
197207
//if there is a difference, a penny, then the coupon is readjust
208+
$line_item_coupons[] = clone $line_item;
198209
$item_amount = $line_item->getAmountIncludingTax() + $result_amount;
199210
$line_item->setAmountIncludingTax( WC_PostFinanceCheckout_Helper::instance()->round_amount( $item_amount, $currency ) );
200211
}
@@ -223,6 +234,7 @@ public static function process_line_items_with_coupons( array $line_items, float
223234
//format number with two decimal places
224235
'effective_sum' => sprintf("%.2f", $amount_rounded ),
225236
'line_items_cleaned' => $line_items,
237+
'line_item_coupons' => $line_item_coupons,
226238
];
227239
}
228240

includes/service/class-wc-postfinancecheckout-service-line-item.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,12 +561,22 @@ protected function create_product_line_items_from_backend( array $backend_items,
561561

562562
$line_item = new \PostFinanceCheckout\Sdk\Model\LineItemCreate();
563563

564-
$tax = 0;
564+
$tax = $discounts = 0;
565565
if ( isset( $backend_items[ $item_id ]['completion_tax'] ) ) {
566566
$tax = array_sum( $backend_items[ $item_id ]['completion_tax'] );
567567
}
568568

569-
$amount_including_tax = $backend_items[ $item_id ]['completion_total'] + $tax;
569+
//At this point, if there is a discount applied by coupon, the price already has the discount applied,
570+
//and to be able to send the discount to the portal, it is necessary to restore the discounted amount,
571+
//the original price must be restored before being applied, otherwise it would be discounting twice in the portal.
572+
$item_data_coupon = $item->get_meta( '_postfinancecheckout_coupon_discount_line_item_discounts' );
573+
if ( !empty ( $item_data_coupon ) ) {
574+
$discount_tax = $item->get_subtotal_tax() - $item->get_total_tax();
575+
$discount_amount = $item->get_subtotal() - $item->get_total();
576+
$discounts = $discount_tax + $discount_amount;
577+
}
578+
579+
$amount_including_tax = $backend_items[ $item_id ]['completion_total'] + $tax + $discounts;
570580

571581
$line_item->setAmountIncludingTax( $this->round_amount( $amount_including_tax, $currency ) );
572582
$quantity = empty( $backend_items[ $item_id ]['qty'] ) ? 1 : $backend_items[ $item_id ]['qty'];

readme.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: postfinancecheckout AG
33
Tags: woocommerce PostFinance Checkout, woocommerce, PostFinance Checkout, payment, e-commerce, webshop, psp, invoice, packing slips, pdf, customer invoice, processing
44
Requires at least: 4.7
55
Tested up to: 6.2
6-
Stable tag: 3.0.0
6+
Stable tag: 3.0.2
77
License: Apache 2
88
License URI: http://www.apache.org/licenses/LICENSE-2.0
99

@@ -56,9 +56,10 @@ Support queries can be issued on the [PostFinance Checkout support site](https:/
5656
== Changelog ==
5757

5858

59-
= 3.0.0 - February 20 2024 =
60-
- [Feature] Full version release
61-
- [Tested Against] PHP 8.0
62-
- [Tested Against] Wordpress 6.4.3
63-
- [Tested Against] Woocommerce 8.5.2
59+
= 3.0.2 - April 22 2024 =
60+
- [Hotfix] Fixed completion in the backend with coupon.
61+
- [Hotfix] Fixed tax amount not sent correctly to the portal.
62+
- [Tested Against] PHP 8.2
63+
- [Tested Against] Wordpress 6.5
64+
- [Tested Against] Woocommerce 8.7.0
6465
- [Tested Against] PHP SDK 4.0.2

woocommerce-postfinancecheckout.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,10 @@
33
* Plugin Name: PostFinance Checkout
44
* Plugin URI: https://wordpress.org/plugins/woo-postfinancecheckout
55
* Description: Process WooCommerce payments with PostFinance Checkout.
6-
* Version: 3.0.0
76
* License: Apache2
87
* License URI: http://www.apache.org/licenses/LICENSE-2.0
98
* Author: postfinancecheckout AG
109
* Author URI: https://postfinance.ch/en/business/products/e-commerce/postfinance-checkout-all-in-one.html
11-
* Requires at least: 4.7
12-
* Tested up to: 6.3
13-
* WC requires at least: 3.0.0
14-
* WC tested up to: 7.8.2
1510
*
1611
* Text Domain: postfinancecheckout
1712
* Domain Path: /languages/
@@ -39,14 +34,14 @@ final class WooCommerce_PostFinanceCheckout {
3934
const CK_INTEGRATION = 'wc_postfinancecheckout_integration';
4035
const CK_ORDER_REFERENCE = 'wc_postfinancecheckout_order_reference';
4136
const CK_ENFORCE_CONSISTENCY = 'wc_postfinancecheckout_enforce_consistency';
42-
const WC_MAXIMUM_VERSION = '8.5.2';
37+
const WC_MAXIMUM_VERSION = '8.7.0';
4338

4439
/**
4540
* WooCommerce PostFinanceCheckout version.
4641
*
4742
* @var string
4843
*/
49-
private $version = '3.0.0';
44+
private $version = '3.0.2';
5045

5146
/**
5247
* The single instance of the class.
@@ -447,6 +442,14 @@ public function loaded() {
447442
10,
448443
2
449444
);
445+
446+
447+
add_action( 'before_woocommerce_init', function() {
448+
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
449+
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
450+
}
451+
} );
452+
450453
}
451454

452455
/**

0 commit comments

Comments
 (0)