Skip to content

Commit a74d5c7

Browse files
author
root
committed
Release 2.1.12
1 parent 8326608 commit a74d5c7

12 files changed

+155
-73
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This repository contains the PostFinance Checkout plugin that enables WooCommerc
1515

1616
## Documentation
1717

18-
* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/woocommerce/2.1.11/docs/en/documentation.html)
18+
* [Documentation](https://plugin-documentation.postfinance-checkout.ch/pfpayments/woocommerce/2.1.12/docs/en/documentation.html)
1919

2020
## Support
2121

@@ -24,4 +24,4 @@ Support queries can be issued on the [PostFinance Checkout support site](https:/
2424

2525
## License
2626

27-
Please see the [license file](https://github.com/pfpayments/woocommerce/blob/2.1.11/LICENSE) for more information.
27+
Please see the [license file](https://github.com/pfpayments/woocommerce/blob/2.1.12/LICENSE) for more information.

assets/js/frontend/checkout.js

Lines changed: 84 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,35 @@ jQuery(
2626
form_data_timer : null,
2727
checkout_form_identifier : 'form.checkout',
2828
checkout_payment_area: '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table',
29+
$order_review: $( '#order_review' ),
30+
$checkout_form: $( 'form.checkout' ),
31+
$order_button: $( '#place_order' ),
32+
33+
/**
34+
* This function gets interesting info for testing
35+
*/
36+
info : function() {
37+
var versions = window.postfinancecheckout_js_params.versions || {};
38+
var info = [
39+
{library: 'integration', version: window.postfinancecheckout_js_params.integration},
40+
{library: 'jQuery', version: $().jquery},
41+
{library: 'wordpress', version: versions.wordpress || null},
42+
{library: 'woocommerce', version: versions.woocommerce || null},
43+
{library: 'woo-postfinancecheckout', version: versions.postfinancecheckout || null},
44+
];
45+
console.table(info, []);
46+
},
2947

3048
init : function() {
3149
// Payment methods.
32-
$( 'form.checkout' ).off( 'click.woo-postfinancecheckout' ).on(
50+
this.$checkout_form.off( 'click.woo-postfinancecheckout' ).on(
3351
'click.woo-postfinancecheckout',
3452
'input[name="payment_method"]',
3553
{ self : this },
3654
this.payment_method_click
3755
);
3856

39-
$( 'form.checkout' ).off( 'button#place_order' ).on(
57+
this.$checkout_form.off( 'button#place_order' ).on(
4058
'button#place_order',
4159
{ self : this },
4260
function (event) {
@@ -48,7 +66,8 @@ jQuery(
4866

4967
if ($( document.body ).hasClass( 'woocommerce-order-pay' )) {
5068
this.checkout_form_identifier = '#order_review';
51-
$( '#order_review' ).off( 'click.woo-postfinancecheckout' ).on(
69+
this.$checkout_form = $( '#order_review' );
70+
this.$order_review.off( 'click.woo-postfinancecheckout' ).on(
5271
'click.woo-postfinancecheckout',
5372
'input[name="payment_method"]',
5473
{
@@ -58,13 +77,14 @@ jQuery(
5877
);
5978
}
6079
this.register_ajax_prefilter();
80+
this.register_window_fetch_prefilter();
6181
this.form_data_timer = setInterval( this.check_form_data_change.bind( this ), 4000 );
62-
$( this.checkout_form_identifier ).find( 'input[name="payment_method"]:checked' ).trigger( "click" );
82+
this.$checkout_form.find( 'input[name="payment_method"]:checked' ).trigger( "click" );
6383
window.wc_postfinancecheckout_checkout = this;
6484
},
6585

6686
check_form_data_change : function() {
67-
var $required_inputs = $( this.checkout_form_identifier ).find( '.address-field.validate-required' ).find( 'input, select' );
87+
var $required_inputs = this.$checkout_form.find( '.address-field.validate-required' ).find( 'input, select' );
6888
var current = '';
6989
var complete = true;
7090
if ( $required_inputs.length ) {
@@ -81,7 +101,7 @@ jQuery(
81101
}
82102
);
83103
// no updates on invalid fields.
84-
if ($( self.checkout_form_identifier + ' .woocommerce-invalid' ).length) {
104+
if ($( this.checkout_form_identifier + ' .woocommerce-invalid' ).length) {
85105
complete = false;
86106
return false;
87107
}
@@ -128,15 +148,16 @@ jQuery(
128148
var description = configuration.data( "description-available" );
129149

130150
// Hide iFrame by moving it (display:none leads to issues).
131-
var item = $( this.checkout_form_identifier )
151+
var item = this.$checkout_form
132152
.find( 'input[name="payment_method"]:checked' )
133153
.closest( 'li.wc_payment_method' )
134154
.find( 'div.payment_box' );
155+
135156
var form = item.find( '#payment-form-' + method_id );
136157
form.css( 'display', '' );
137158

138-
var required_inputs = $( this.checkout_form_identifier ).find( '.address-field.validate-required:visible' );
139-
var has_full_address = true;
159+
var required_inputs = this.$checkout_form.find( '.address-field.validate-required:visible' );
160+
var has_full_address = true;
140161

141162
if ( required_inputs.length ) {
142163
required_inputs.each(
@@ -176,19 +197,18 @@ jQuery(
176197
},
177198

178199
enable_place_order_button: function(){
179-
var order_button = $( '#place_order' );
180-
order_button.removeAttr( 'disabled' );
181-
order_button.removeClass( 'postfinancecheckout-disabled' );
200+
this.$order_button.removeAttr( 'disabled' );
201+
this.$order_button.removeClass( 'postfinancecheckout-disabled' );
182202
},
183203

184204
disable_place_order_button: function(){
185-
var order_button = $( '#place_order' );
186-
order_button.prop( 'disabled', true );
187-
order_button.addClass( 'postfinancecheckout-disabled' );
205+
this.$order_button.prop( 'disabled', true );
206+
this.$order_button.addClass( 'postfinancecheckout-disabled' );
188207
},
189208

190209
/**
191210
* This function handle the success function of Place Order in WooCommerce
211+
* @version <=7.4.1
192212
*/
193213
register_ajax_prefilter : function() {
194214
var self = this;
@@ -236,15 +256,43 @@ jQuery(
236256
}
237257
}
238258
);
259+
},
260+
261+
/**
262+
* This function handle the success function of Place Order in WooCommerce
263+
* @version >=7.5.0
264+
*/
265+
register_window_fetch_prefilter : function() {
266+
var {fetch: origFetch} = window;
267+
var self = this;
239268

269+
window.fetch = async (url, options) => {
270+
var response = await origFetch(url, options);
271+
272+
/* work with the cloned response in a separate promise chain -- could use the same chain with `await`. */
273+
if (url === wc_checkout_params.checkout_url && self.is_supported_method( self.get_selected_payment_method() )) {
274+
response
275+
.clone()
276+
.json()
277+
.then(body => {
278+
if (body.result !== undefined && 'success' === body.result){
279+
self.process_order_created(body);
280+
}
281+
})
282+
.catch(err => console.error(err));
283+
}
284+
285+
/* the original response can be resolved unmodified: */
286+
return response;
287+
};
240288
},
241289

242290
is_supported_method : function(method_id) {
243291
return method_id && (method_id.indexOf( 'postfinancecheckout_' ) === 0);
244292
},
245293

246294
get_selected_payment_method : function() {
247-
return $( this.checkout_form_identifier ).find( 'input[name="payment_method"]:checked' ).val();
295+
return this.$checkout_form.find( 'input[name="payment_method"]:checked' ).val();
248296
},
249297

250298
register_method : function(method_id, configuration_id, container_id) {
@@ -261,7 +309,7 @@ jQuery(
261309
}
262310
var self = this;
263311

264-
$( this.checkout_form_identifier ).block(
312+
this.$checkout_form.block(
265313
{
266314
message : null,
267315
overlayCSS : {
@@ -296,7 +344,7 @@ jQuery(
296344

297345
this.payment_methods[method_id].handler.setInitializeCallback(
298346
function(){
299-
$( self.checkout_form_identifier ).unblock();
347+
self.$checkout_form.unblock();
300348
}
301349
);
302350

@@ -322,16 +370,16 @@ jQuery(
322370
this.payment_methods[method_id].container_id = container_id;
323371

324372
if (this.checkout_form_identifier === '#order_review') {
325-
$( this.checkout_form_identifier ).off( 'submit.postfinancecheckout' ).on(
373+
this.$checkout_form.off( 'submit.postfinancecheckout' )
374+
.on(
326375
'submit.postfinancecheckout',
327376
function(){
328377
var method_id = self.get_selected_payment_method();
329378
return self.process_submit( method_id );
330379
}
331380
);
332381
} else {
333-
var form = $( this.checkout_form_identifier );
334-
form.off( 'checkout_place_order_' + method_id + '.postfinancecheckout' )
382+
this.$checkout_form.off( 'checkout_place_order_' + method_id + '.postfinancecheckout' )
335383
.on(
336384
'checkout_place_order_' + method_id + '.postfinancecheckout',
337385
function(){
@@ -346,8 +394,8 @@ jQuery(
346394
return true;
347395
}
348396

349-
var form = $( this.checkout_form_identifier );
350-
var required_inputs = $( this.checkout_form_identifier ).find( '.address-field.validate-required:visible' );
397+
var form = this.$checkout_form;
398+
var required_inputs = this.$checkout_form.find( '.address-field.validate-required:visible' );
351399
var has_full_address = true;
352400

353401
if ( required_inputs.length ) {
@@ -361,7 +409,7 @@ jQuery(
361409
);
362410
}
363411
if ( ! has_full_address) {
364-
$( this.checkout_form_identifier ).trigger( 'validate' );
412+
this.$checkout_form.trigger( 'validate' );
365413
this.submit_error( postfinancecheckout_js_params.i18n_not_complete );
366414
return false;
367415
}
@@ -382,12 +430,12 @@ jQuery(
382430
} else {
383431
if (this.checkout_form_identifier === '#order_review') {
384432

385-
self = this;
433+
var self = this;
386434
$.ajax(
387435
{
388436
type: 'POST',
389437
url: window.location.href,
390-
data: form.serialize(),
438+
data: new URLSearchParams( form[0] ).toString(),
391439
dataType: 'json',
392440
success: function( result ) {
393441
self.validated = false;
@@ -413,7 +461,7 @@ jQuery(
413461
var self = this;
414462
// handle lightbox integration.
415463
if (postfinancecheckout_js_params.integration && postfinancecheckout_js_params.integration === self.integrations.LIGHTBOX ) {
416-
var required_inputs = $( self.checkout_form_identifier ).find( '.validate-required:visible' );
464+
var required_inputs = self.$checkout_form.find( '.validate-required:visible' );
417465
var has_full_address = true;
418466
if (required_inputs.length) {
419467
required_inputs.each(
@@ -431,7 +479,7 @@ jQuery(
431479
);
432480
}
433481
if ( ! has_full_address) {
434-
$( self.checkout_form_identifier ).trigger( 'validate' );
482+
self.$checkout_form.trigger( 'validate' );
435483
self.submit_error( postfinancecheckout_js_params.i18n_not_complete );
436484
return false;
437485
}
@@ -457,11 +505,10 @@ jQuery(
457505
process_validation : function(method_id, validation_result) {
458506
if (validation_result.success) {
459507
this.validated = true;
460-
$( this.checkout_form_identifier ).submit();
508+
this.$checkout_form.submit();
461509
return true;
462510
} else {
463-
var form = $( this.checkout_form_identifier );
464-
form.unblock();
511+
this.$checkout_form.unblock();
465512
this.form_data_timer = setInterval( this.check_form_data_change.bind( this ),3000 );
466513
if (validation_result.errors) {
467514
this.submit_error( validation_result.errors );
@@ -481,14 +528,15 @@ jQuery(
481528

482529
// We emulate the woocommerce submit_error function, as it is not callable from outside.
483530
submit_error: function( error_message ) {
531+
var self = this;
484532
var formatted_message = '<div class="woocommerce-error">' + this.format_error_messages( error_message ) + '</div>';
485-
$( '.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message' ).remove();
486-
$( this.checkout_form_identifier ).prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">' + formatted_message + '</div>' );
487-
$( this.checkout_form_identifier ).removeClass( 'processing' ).unblock();
488-
$( this.checkout_form_identifier ).find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).blur();
533+
$( '.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message' ).remove();
534+
this.$checkout_form.prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">' + formatted_message + '</div>' );
535+
this.$checkout_form.removeClass( 'processing' ).unblock();
536+
this.$checkout_form.find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).blur();
489537
$( 'html, body' ).animate(
490538
{
491-
scrollTop: ( $( this.checkout_form_identifier ).offset().top - 100 )
539+
scrollTop: ( self.$checkout_form.offset().top - 100 )
492540
},
493541
1000
494542
);

changelog.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Tested against:
549549
- Woocommerce 7.4.1
550550
- PHP SDK 3.2.0
551551

552-
= 2.1.11 - April 05, 2023 =
552+
= 2.1.11 - April 13, 2023 =
553553

554554
## Bugfix
555555
- Fix the Smart Coupon impact on renewal of Subscriptions
@@ -560,3 +560,14 @@ Tested against:
560560
- Woocommerce 7.4.1
561561
- PHP SDK 3.2.0
562562

563+
= 2.1.12 - April 20, 2023 =
564+
565+
* [Features] Provide a *Warning Message* in case the installed Woocommerce version is not supported
566+
* [Features] Support of Woocommerce 7.5.0
567+
* [Features] Support of Woocommerce 7.5.1
568+
569+
* [Tested Against] PHP 8.1
570+
* [Tested Against] Wordpress 6.2.0
571+
* [Tested Against] Woocommerce 7.5.1
572+
* [Tested Against] PHP SDK 3.2.0
573+

docs/en/documentation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h2>Documentation</h2> </div>
2222
</a>
2323
</li>
2424
<li>
25-
<a href="https://github.com/pfpayments/woocommerce/releases/tag/2.1.11/">
25+
<a href="https://github.com/pfpayments/woocommerce/releases/tag/2.1.12/">
2626
Source
2727
</a>
2828
</li>

includes/admin/class-wc-postfinancecheckout-admin-settings-page.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function get_settings() {
187187
$settings = array(
188188
array(
189189
'links' => array(
190-
'https://plugin-documentation.postfinance-checkout.ch/pfpayments/woocommerce/2.1.11/docs/en/documentation.html' => __( 'Documentation', 'woo-postfinancecheckout' ),
190+
'https://plugin-documentation.postfinance-checkout.ch/pfpayments/woocommerce/2.1.12/docs/en/documentation.html' => __( 'Documentation', 'woo-postfinancecheckout' ),
191191
'https://checkout.postfinance.ch/en-ch/user/signup' => __( 'Sign Up', 'woo-postfinancecheckout' ),
192192
),
193193
'type' => 'postfinancecheckout_links',

0 commit comments

Comments
 (0)