Skip to content

Commit

Permalink
Release 2.1.12
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Apr 20, 2023
1 parent 8326608 commit a74d5c7
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 73 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This repository contains the PostFinance Checkout plugin that enables WooCommerc

## Documentation

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

## Support

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

## License

Please see the [license file](https://github.com/pfpayments/woocommerce/blob/2.1.11/LICENSE) for more information.
Please see the [license file](https://github.com/pfpayments/woocommerce/blob/2.1.12/LICENSE) for more information.
120 changes: 84 additions & 36 deletions assets/js/frontend/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,35 @@ jQuery(
form_data_timer : null,
checkout_form_identifier : 'form.checkout',
checkout_payment_area: '.woocommerce-checkout-payment, .woocommerce-checkout-review-order-table',
$order_review: $( '#order_review' ),
$checkout_form: $( 'form.checkout' ),
$order_button: $( '#place_order' ),

/**
* This function gets interesting info for testing
*/
info : function() {
var versions = window.postfinancecheckout_js_params.versions || {};
var info = [
{library: 'integration', version: window.postfinancecheckout_js_params.integration},
{library: 'jQuery', version: $().jquery},
{library: 'wordpress', version: versions.wordpress || null},
{library: 'woocommerce', version: versions.woocommerce || null},
{library: 'woo-postfinancecheckout', version: versions.postfinancecheckout || null},
];
console.table(info, []);
},

init : function() {
// Payment methods.
$( 'form.checkout' ).off( 'click.woo-postfinancecheckout' ).on(
this.$checkout_form.off( 'click.woo-postfinancecheckout' ).on(
'click.woo-postfinancecheckout',
'input[name="payment_method"]',
{ self : this },
this.payment_method_click
);

$( 'form.checkout' ).off( 'button#place_order' ).on(
this.$checkout_form.off( 'button#place_order' ).on(
'button#place_order',
{ self : this },
function (event) {
Expand All @@ -48,7 +66,8 @@ jQuery(

if ($( document.body ).hasClass( 'woocommerce-order-pay' )) {
this.checkout_form_identifier = '#order_review';
$( '#order_review' ).off( 'click.woo-postfinancecheckout' ).on(
this.$checkout_form = $( '#order_review' );
this.$order_review.off( 'click.woo-postfinancecheckout' ).on(
'click.woo-postfinancecheckout',
'input[name="payment_method"]',
{
Expand All @@ -58,13 +77,14 @@ jQuery(
);
}
this.register_ajax_prefilter();
this.register_window_fetch_prefilter();
this.form_data_timer = setInterval( this.check_form_data_change.bind( this ), 4000 );
$( this.checkout_form_identifier ).find( 'input[name="payment_method"]:checked' ).trigger( "click" );
this.$checkout_form.find( 'input[name="payment_method"]:checked' ).trigger( "click" );
window.wc_postfinancecheckout_checkout = this;
},

check_form_data_change : function() {
var $required_inputs = $( this.checkout_form_identifier ).find( '.address-field.validate-required' ).find( 'input, select' );
var $required_inputs = this.$checkout_form.find( '.address-field.validate-required' ).find( 'input, select' );
var current = '';
var complete = true;
if ( $required_inputs.length ) {
Expand All @@ -81,7 +101,7 @@ jQuery(
}
);
// no updates on invalid fields.
if ($( self.checkout_form_identifier + ' .woocommerce-invalid' ).length) {
if ($( this.checkout_form_identifier + ' .woocommerce-invalid' ).length) {
complete = false;
return false;
}
Expand Down Expand Up @@ -128,15 +148,16 @@ jQuery(
var description = configuration.data( "description-available" );

// Hide iFrame by moving it (display:none leads to issues).
var item = $( this.checkout_form_identifier )
var item = this.$checkout_form
.find( 'input[name="payment_method"]:checked' )
.closest( 'li.wc_payment_method' )
.find( 'div.payment_box' );

var form = item.find( '#payment-form-' + method_id );
form.css( 'display', '' );

var required_inputs = $( this.checkout_form_identifier ).find( '.address-field.validate-required:visible' );
var has_full_address = true;
var required_inputs = this.$checkout_form.find( '.address-field.validate-required:visible' );
var has_full_address = true;

if ( required_inputs.length ) {
required_inputs.each(
Expand Down Expand Up @@ -176,19 +197,18 @@ jQuery(
},

enable_place_order_button: function(){
var order_button = $( '#place_order' );
order_button.removeAttr( 'disabled' );
order_button.removeClass( 'postfinancecheckout-disabled' );
this.$order_button.removeAttr( 'disabled' );
this.$order_button.removeClass( 'postfinancecheckout-disabled' );
},

disable_place_order_button: function(){
var order_button = $( '#place_order' );
order_button.prop( 'disabled', true );
order_button.addClass( 'postfinancecheckout-disabled' );
this.$order_button.prop( 'disabled', true );
this.$order_button.addClass( 'postfinancecheckout-disabled' );
},

/**
* This function handle the success function of Place Order in WooCommerce
* @version <=7.4.1
*/
register_ajax_prefilter : function() {
var self = this;
Expand Down Expand Up @@ -236,15 +256,43 @@ jQuery(
}
}
);
},

/**
* This function handle the success function of Place Order in WooCommerce
* @version >=7.5.0
*/
register_window_fetch_prefilter : function() {
var {fetch: origFetch} = window;
var self = this;

window.fetch = async (url, options) => {
var response = await origFetch(url, options);

/* work with the cloned response in a separate promise chain -- could use the same chain with `await`. */
if (url === wc_checkout_params.checkout_url && self.is_supported_method( self.get_selected_payment_method() )) {
response
.clone()
.json()
.then(body => {
if (body.result !== undefined && 'success' === body.result){
self.process_order_created(body);
}
})
.catch(err => console.error(err));
}

/* the original response can be resolved unmodified: */
return response;
};
},

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

get_selected_payment_method : function() {
return $( this.checkout_form_identifier ).find( 'input[name="payment_method"]:checked' ).val();
return this.$checkout_form.find( 'input[name="payment_method"]:checked' ).val();
},

register_method : function(method_id, configuration_id, container_id) {
Expand All @@ -261,7 +309,7 @@ jQuery(
}
var self = this;

$( this.checkout_form_identifier ).block(
this.$checkout_form.block(
{
message : null,
overlayCSS : {
Expand Down Expand Up @@ -296,7 +344,7 @@ jQuery(

this.payment_methods[method_id].handler.setInitializeCallback(
function(){
$( self.checkout_form_identifier ).unblock();
self.$checkout_form.unblock();
}
);

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

if (this.checkout_form_identifier === '#order_review') {
$( this.checkout_form_identifier ).off( 'submit.postfinancecheckout' ).on(
this.$checkout_form.off( 'submit.postfinancecheckout' )
.on(
'submit.postfinancecheckout',
function(){
var method_id = self.get_selected_payment_method();
return self.process_submit( method_id );
}
);
} else {
var form = $( this.checkout_form_identifier );
form.off( 'checkout_place_order_' + method_id + '.postfinancecheckout' )
this.$checkout_form.off( 'checkout_place_order_' + method_id + '.postfinancecheckout' )
.on(
'checkout_place_order_' + method_id + '.postfinancecheckout',
function(){
Expand All @@ -346,8 +394,8 @@ jQuery(
return true;
}

var form = $( this.checkout_form_identifier );
var required_inputs = $( this.checkout_form_identifier ).find( '.address-field.validate-required:visible' );
var form = this.$checkout_form;
var required_inputs = this.$checkout_form.find( '.address-field.validate-required:visible' );
var has_full_address = true;

if ( required_inputs.length ) {
Expand All @@ -361,7 +409,7 @@ jQuery(
);
}
if ( ! has_full_address) {
$( this.checkout_form_identifier ).trigger( 'validate' );
this.$checkout_form.trigger( 'validate' );
this.submit_error( postfinancecheckout_js_params.i18n_not_complete );
return false;
}
Expand All @@ -382,12 +430,12 @@ jQuery(
} else {
if (this.checkout_form_identifier === '#order_review') {

self = this;
var self = this;
$.ajax(
{
type: 'POST',
url: window.location.href,
data: form.serialize(),
data: new URLSearchParams( form[0] ).toString(),
dataType: 'json',
success: function( result ) {
self.validated = false;
Expand All @@ -413,7 +461,7 @@ jQuery(
var self = this;
// handle lightbox integration.
if (postfinancecheckout_js_params.integration && postfinancecheckout_js_params.integration === self.integrations.LIGHTBOX ) {
var required_inputs = $( self.checkout_form_identifier ).find( '.validate-required:visible' );
var required_inputs = self.$checkout_form.find( '.validate-required:visible' );
var has_full_address = true;
if (required_inputs.length) {
required_inputs.each(
Expand All @@ -431,7 +479,7 @@ jQuery(
);
}
if ( ! has_full_address) {
$( self.checkout_form_identifier ).trigger( 'validate' );
self.$checkout_form.trigger( 'validate' );
self.submit_error( postfinancecheckout_js_params.i18n_not_complete );
return false;
}
Expand All @@ -457,11 +505,10 @@ jQuery(
process_validation : function(method_id, validation_result) {
if (validation_result.success) {
this.validated = true;
$( this.checkout_form_identifier ).submit();
this.$checkout_form.submit();
return true;
} else {
var form = $( this.checkout_form_identifier );
form.unblock();
this.$checkout_form.unblock();
this.form_data_timer = setInterval( this.check_form_data_change.bind( this ),3000 );
if (validation_result.errors) {
this.submit_error( validation_result.errors );
Expand All @@ -481,14 +528,15 @@ jQuery(

// We emulate the woocommerce submit_error function, as it is not callable from outside.
submit_error: function( error_message ) {
var self = this;
var formatted_message = '<div class="woocommerce-error">' + this.format_error_messages( error_message ) + '</div>';
$( '.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message' ).remove();
$( this.checkout_form_identifier ).prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">' + formatted_message + '</div>' );
$( this.checkout_form_identifier ).removeClass( 'processing' ).unblock();
$( this.checkout_form_identifier ).find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).blur();
$( '.woocommerce-NoticeGroup-checkout, .woocommerce-error, .woocommerce-message' ).remove();
this.$checkout_form.prepend( '<div class="woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout">' + formatted_message + '</div>' );
this.$checkout_form.removeClass( 'processing' ).unblock();
this.$checkout_form.find( '.input-text, select, input:checkbox' ).trigger( 'validate' ).blur();
$( 'html, body' ).animate(
{
scrollTop: ( $( this.checkout_form_identifier ).offset().top - 100 )
scrollTop: ( self.$checkout_form.offset().top - 100 )
},
1000
);
Expand Down
13 changes: 12 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Tested against:
- Woocommerce 7.4.1
- PHP SDK 3.2.0

= 2.1.11 - April 05, 2023 =
= 2.1.11 - April 13, 2023 =

## Bugfix
- Fix the Smart Coupon impact on renewal of Subscriptions
Expand All @@ -560,3 +560,14 @@ Tested against:
- Woocommerce 7.4.1
- PHP SDK 3.2.0

= 2.1.12 - April 20, 2023 =

* [Features] Provide a *Warning Message* in case the installed Woocommerce version is not supported
* [Features] Support of Woocommerce 7.5.0
* [Features] Support of Woocommerce 7.5.1

* [Tested Against] PHP 8.1
* [Tested Against] Wordpress 6.2.0
* [Tested Against] Woocommerce 7.5.1
* [Tested Against] PHP SDK 3.2.0

2 changes: 1 addition & 1 deletion docs/en/documentation.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h2>Documentation</h2> </div>
</a>
</li>
<li>
<a href="https://github.com/pfpayments/woocommerce/releases/tag/2.1.11/">
<a href="https://github.com/pfpayments/woocommerce/releases/tag/2.1.12/">
Source
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function get_settings() {
$settings = array(
array(
'links' => array(
'https://plugin-documentation.postfinance-checkout.ch/pfpayments/woocommerce/2.1.11/docs/en/documentation.html' => __( 'Documentation', 'woo-postfinancecheckout' ),
'https://plugin-documentation.postfinance-checkout.ch/pfpayments/woocommerce/2.1.12/docs/en/documentation.html' => __( 'Documentation', 'woo-postfinancecheckout' ),
'https://checkout.postfinance.ch/en-ch/user/signup' => __( 'Sign Up', 'woo-postfinancecheckout' ),
),
'type' => 'postfinancecheckout_links',
Expand Down
Loading

0 comments on commit a74d5c7

Please sign in to comment.