Skip to content

Commit 50c80f8

Browse files
rudrakshi-guptaRudrakshi Gupta
andauthored
Fix: order pay (#394)
* Add fixes for payment gateways on order-pay page * Change version to v4.9.1 --------- Co-authored-by: Rudrakshi Gupta <rudrakshigupta@Rudrakshis-MacBook-Air.local>
1 parent 2449cf5 commit 50c80f8

7 files changed

+150
-39
lines changed

assets/js/cko-paypal-integration.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,38 @@ jQuery( function ( $ ) {
5656
.addClass( 'woocommerce-NoticeGroup woocommerce-NoticeGroup-checkout' )
5757
.append( ulWrapper );
5858

59-
jQuery('form.checkout .woocommerce-NoticeGroup').remove();
60-
jQuery('form.checkout').prepend(wcNoticeDiv);
61-
jQuery('.woocommerce, .form.checkout').removeClass('processing').unblock();
62-
63-
jQuery('html, body').animate({
64-
scrollTop: (jQuery('form.checkout').offset().top - 100 )
65-
}, 1000 );
59+
let scrollTarget;
60+
61+
if ( jQuery('form.checkout').length ) {
62+
jQuery('form.checkout .woocommerce-NoticeGroup').remove();
63+
jQuery('form.checkout').prepend(wcNoticeDiv);
64+
jQuery('.woocommerce, .form.checkout').removeClass('processing').unblock();
65+
scrollTarget = jQuery('form.checkout');
66+
} else if ( jQuery('.woocommerce-order-pay').length ) {
67+
jQuery('.woocommerce-order-pay .woocommerce-NoticeGroup').remove();
68+
jQuery('.woocommerce-order-pay').prepend(wcNoticeDiv);
69+
jQuery('.woocommerce, .woocommerce-order-pay').removeClass('processing').unblock();
70+
scrollTarget = jQuery('.woocommerce-order-pay');
71+
}
72+
73+
if ( scrollTarget ) {
74+
jQuery('html, body').animate({
75+
scrollTop: (scrollTarget.offset().top - 100)
76+
}, 1000);
77+
}
6678
};
6779

6880
let cko_create_order_id = function () {
6981
let data = jQuery( cko_paypal_vars.paypal_button_selector ).closest('form').serialize();
7082

71-
return fetch( cko_paypal_vars.create_order_url, {
83+
var cko_url = cko_paypal_vars.create_order_url;
84+
85+
var isOrderPayPage = jQuery(document.body).hasClass('woocommerce-order-pay');
86+
if (isOrderPayPage){
87+
cko_url = cko_paypal_vars.order_pay_url;
88+
}
89+
90+
return fetch( cko_url, {
7291
method: 'POST',
7392
headers: {
7493
'Content-Type': 'application/x-www-form-urlencoded'
@@ -96,7 +115,13 @@ jQuery( function ( $ ) {
96115
jQuery( '#payment #paypal-button-container' ).remove();
97116

98117
if ( ! jQuery( '#payment' ).find( '#paypal-button-container' ).length ) {
99-
jQuery( '#payment .place-order' ).append( '<div id="paypal-button-container" style="margin-top:15px; display:none;"></div>' );
118+
var isOrderPayPage = jQuery(document.body).hasClass('woocommerce-order-pay');
119+
if( isOrderPayPage ) {
120+
jQuery( '#payment > .form-row' ).append( '<div id="paypal-button-container" style="margin-top:15px; display:none;"></div>' );
121+
}
122+
else {
123+
jQuery( '#payment .place-order' ).append( '<div id="paypal-button-container" style="margin-top:15px; display:none;"></div>' );
124+
}
100125
}
101126

102127
// Initialize paypal button.

includes/class-wc-gateway-checkout-com-apple-pay.php

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,14 @@ public function payment_fields() {
159159
jQuery( document ).off( 'click', '#' + applePayButtonId );
160160

161161
jQuery( document ).on( 'click', '#' + applePayButtonId, function () {
162-
var checkoutFields = '<?php echo $checkout_fields; ?>';
163-
var result = isValidFormField(checkoutFields);
164-
165-
if(result){
162+
var isOrderPayPage = jQuery(document.body).hasClass('woocommerce-order-pay');
163+
164+
if( !isOrderPayPage ) {
165+
var checkoutFields = '<?php echo $checkout_fields; ?>';
166+
var result = isValidFormField(checkoutFields);
167+
}
168+
169+
if(result || isOrderPayPage){
166170
var applePaySession = new ApplePaySession(3, getApplePayConfig());
167171
handleApplePayEvents(applePaySession);
168172
applePaySession.begin();
@@ -179,14 +183,44 @@ function getApplePayConfig() {
179183
var networksSupported = <?php echo wp_json_encode( $supported_networks ); ?>;
180184
var merchantCapabilities = <?php echo wp_json_encode( $merchant_capabilities ); ?>;
181185

186+
<?php
187+
188+
// Logic for order-pay page.
189+
190+
$total_price = $woocommerce->cart->total;
191+
$subtotal_price = $woocommerce->cart->subtotal;
192+
193+
// If on order-pay page, try fetching order total from the last order.
194+
if ( is_wc_endpoint_url( 'order-pay' ) ) {
195+
196+
global $wp;
197+
198+
// Get order ID from URL if available.
199+
$order_id = absint( $wp->query_vars['order-pay'] );
200+
201+
if ( ! $order_id && isset( $_GET['key'] ) ) {
202+
$pay_order = wc_get_order( wc_get_order_id_by_order_key( sanitize_text_field( $_GET['key'] ) ) );
203+
} else {
204+
$pay_order = wc_get_order( $order_id );
205+
}
206+
207+
if ( $pay_order ) {
208+
$total_price = $pay_order->get_total();
209+
$subtotal_price = $pay_order->get_subtotal();
210+
$shipping_amount = $pay_order->get_shipping_total();
211+
}
212+
}
213+
214+
?>
215+
182216
return {
183217
currencyCode: "<?php echo esc_js( get_woocommerce_currency() ); ?>",
184218
countryCode: "<?php echo esc_js( $country_code ); ?>",
185219
merchantCapabilities: merchantCapabilities,
186220
supportedNetworks: networksSupported,
187221
total: {
188222
label: window.location.host,
189-
amount: "<?php echo esc_js( $woocommerce->cart->total ); ?>",
223+
amount: "<?php echo esc_js( $total_price ); ?>",
190224
type: 'final'
191225
}
192226
}
@@ -219,14 +253,14 @@ function handleApplePayEvents(session) {
219253
var newTotal = {
220254
type: 'final',
221255
label: window.location.host,
222-
amount: "<?php echo esc_js( $woocommerce->cart->total ); ?>",
256+
amount: "<?php echo esc_js( $total_price ); ?>",
223257
};
224258

225259
var newLineItems = [
226260
{
227261
type: 'final',
228262
label: 'Subtotal',
229-
amount: "<?php echo esc_js( $woocommerce->cart->subtotal ); ?>"
263+
amount: "<?php echo esc_js( $subtotal_price ); ?>"
230264
},
231265
{
232266
type: 'final',

includes/class-wc-gateway-checkout-com-google-pay.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ public function payment_scripts() {
7070
$currency_code = get_woocommerce_currency();
7171
$total_price = WC()->cart->total;
7272

73+
// Logic for order-pay page.
74+
// If on order-pay page, try fetching order total from the last order.
75+
if ( is_wc_endpoint_url( 'order-pay' ) ) {
76+
77+
global $wp;
78+
79+
// Get order ID from URL if available.
80+
$order_id = absint( $wp->query_vars['order-pay'] );
81+
82+
if ( ! $order_id && isset( $_GET['key'] ) ) {
83+
$pay_order = wc_get_order( wc_get_order_id_by_order_key( sanitize_text_field( $_GET['key'] ) ) );
84+
} else {
85+
$pay_order = wc_get_order( $order_id );
86+
}
87+
88+
if ( $pay_order ) {
89+
$total_price = $pay_order->get_total();
90+
}
91+
}
92+
7393
$vars = [
7494
'environment' => $environment ? 'TEST' : 'PRODUCTION',
7595
'public_key' => $core_settings['ckocom_pk'],

includes/class-wc-gateway-checkout-com-paypal.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public function handle_wc_api() {
107107
WC_Checkoutcom_Utility::cko_set_session( 'cko_paypal_order_id', wc_clean( $_GET['paypal_order_id'] ) );
108108
$this->cko_express_paypal_order_session();
109109
break;
110+
111+
case 'order_pay':
112+
$this->cko_create_order_request();
113+
break;
110114
}
111115
}
112116

@@ -254,6 +258,30 @@ public function cko_create_order_request( $is_express = false ) {
254258
}
255259

256260
$total_amount = WC()->cart->total;
261+
262+
// Logic for order-pay page.
263+
264+
$is_order_pay = get_option( 'woocommerce_checkout_pay_endpoint', 'order-pay' );
265+
266+
$nonce = isset( $_POST['woocommerce-pay-nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['woocommerce-pay-nonce'] ) ) : '';
267+
268+
if ( ! empty( $nonce ) && wp_verify_nonce( $nonce, 'woocommerce-pay' ) ) {
269+
270+
$referer_url = isset( $_POST['_wp_http_referer'] ) ? esc_url_raw( wp_unslash( $_POST['_wp_http_referer'] ) ) : '';
271+
272+
if ( strpos( $referer_url, "/{$is_order_pay}/" ) !== false ) {
273+
$parts = explode( '/', trim( $referer_url, '/' ) );
274+
275+
$order_pay_id = isset( $parts[2] ) ? absint( $parts[2] ) : 0;
276+
277+
$pay_order = wc_get_order( $order_pay_id );
278+
279+
if ( $pay_order ) {
280+
$total_amount = $pay_order->get_total();
281+
}
282+
}
283+
}
284+
257285
$amount_cents = WC_Checkoutcom_Utility::value_to_decimal( $total_amount, get_woocommerce_currency() );
258286

259287
$paymentContextsRequest->amount = $amount_cents;
@@ -541,6 +569,7 @@ public function payment_scripts() {
541569
'create_order_url' => add_query_arg( [ 'cko_paypal_action' => 'create_order' ], WC()->api_request_url( 'CKO_Paypal_Woocommerce' ) ),
542570
'clear_session_url' => add_query_arg( [ 'cko_paypal_action' => 'empty_session' ], WC()->api_request_url( 'CKO_Paypal_Woocommerce' ) ),
543571
'cc_capture' => add_query_arg( [ 'cko_paypal_action' => 'cc_capture' ], WC()->api_request_url( 'CKO_Paypal_Woocommerce' ) ),
572+
'order_pay_url' => add_query_arg( [ 'cko_paypal_action' => 'order_pay' ], WC()->api_request_url( 'CKO_Paypal_Woocommerce' ) ),
544573
'woocommerce_process_checkout' => wp_create_nonce( 'woocommerce-process_checkout' ),
545574
'is_cart_contains_subscription' => WC_Checkoutcom_Utility::is_cart_contains_subscription(),
546575
'paypal_button_selector' => '#paypal-button-container',

languages/checkout-com-unified-payments-api.pot

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Copyright (C) 2024 Checkout.com
1+
# Copyright (C) 2025 Checkout.com
22
# This file is distributed under the same license as the Checkout.com Payment Gateway plugin.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: Checkout.com Payment Gateway 4.9.0\n"
5+
"Project-Id-Version: Checkout.com Payment Gateway 4.9.1\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/woocommerce-gateway-checkout-com\n"
77
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
88
"Language-Team: LANGUAGE <LL@li.org>\n"
99
"MIME-Version: 1.0\n"
1010
"Content-Type: text/plain; charset=UTF-8\n"
1111
"Content-Transfer-Encoding: 8bit\n"
12-
"POT-Creation-Date: 2024-11-19T08:15:04+00:00\n"
12+
"POT-Creation-Date: 2025-03-18T12:22:31+00:00\n"
1313
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1414
"X-Generator: WP-CLI 2.9.0\n"
1515
"X-Domain: checkout-com-unified-payments-api\n"
@@ -345,21 +345,21 @@ msgstr ""
345345
#: includes/class-wc-gateway-checkout-com-alternative-payments.php:67
346346
#: includes/class-wc-gateway-checkout-com-apple-pay.php:66
347347
#: includes/class-wc-gateway-checkout-com-cards.php:178
348-
#: includes/class-wc-gateway-checkout-com-google-pay.php:101
349-
#: includes/class-wc-gateway-checkout-com-paypal.php:458
348+
#: includes/class-wc-gateway-checkout-com-google-pay.php:121
349+
#: includes/class-wc-gateway-checkout-com-paypal.php:486
350350
msgid "Other Settings"
351351
msgstr ""
352352

353353
#. translators: %s: Action ID.
354354
#: includes/class-wc-gateway-checkout-com-alternative-payments.php:123
355-
#: includes/class-wc-gateway-checkout-com-apple-pay.php:642
355+
#: includes/class-wc-gateway-checkout-com-apple-pay.php:676
356356
#: includes/class-wc-gateway-checkout-com-cards.php:948
357357
msgid "Checkout.com Payment Partially refunded from Admin - Action ID : %s"
358358
msgstr ""
359359

360360
#. translators: %s: Action ID.
361361
#: includes/class-wc-gateway-checkout-com-alternative-payments.php:132
362-
#: includes/class-wc-gateway-checkout-com-apple-pay.php:651
362+
#: includes/class-wc-gateway-checkout-com-apple-pay.php:685
363363
#: includes/class-wc-gateway-checkout-com-cards.php:943
364364
msgid "Checkout.com Payment refunded from Admin - Action ID : %s"
365365
msgstr ""
@@ -369,25 +369,25 @@ msgstr ""
369369
msgid "Apple Pay"
370370
msgstr ""
371371

372-
#: includes/class-wc-gateway-checkout-com-apple-pay.php:557
372+
#: includes/class-wc-gateway-checkout-com-apple-pay.php:591
373373
#: includes/class-wc-gateway-checkout-com-cards.php:467
374-
#: includes/class-wc-gateway-checkout-com-google-pay.php:152
374+
#: includes/class-wc-gateway-checkout-com-google-pay.php:172
375375
msgid "There was an issue completing the payment."
376376
msgstr ""
377377

378378
#. translators: %s: Action ID.
379-
#: includes/class-wc-gateway-checkout-com-apple-pay.php:585
379+
#: includes/class-wc-gateway-checkout-com-apple-pay.php:619
380380
#: includes/class-wc-gateway-checkout-com-cards.php:551
381381
#: includes/class-wc-gateway-checkout-com-cards.php:660
382-
#: includes/class-wc-gateway-checkout-com-google-pay.php:195
382+
#: includes/class-wc-gateway-checkout-com-google-pay.php:215
383383
msgid "Checkout.com Payment Authorised - Action ID : %s"
384384
msgstr ""
385385

386386
#. translators: %s: Action ID.
387-
#: includes/class-wc-gateway-checkout-com-apple-pay.php:593
387+
#: includes/class-wc-gateway-checkout-com-apple-pay.php:627
388388
#: includes/class-wc-gateway-checkout-com-cards.php:559
389389
#: includes/class-wc-gateway-checkout-com-cards.php:668
390-
#: includes/class-wc-gateway-checkout-com-google-pay.php:203
390+
#: includes/class-wc-gateway-checkout-com-google-pay.php:223
391391
msgid "Checkout.com Payment Flagged - Action ID : %s"
392392
msgstr ""
393393

@@ -459,7 +459,7 @@ msgstr ""
459459

460460
#. translators: %s: URL
461461
#: includes/class-wc-gateway-checkout-com-cards.php:513
462-
#: includes/class-wc-gateway-checkout-com-google-pay.php:165
462+
#: includes/class-wc-gateway-checkout-com-google-pay.php:185
463463
msgid "Checkout.com 3d Redirect waiting. URL : %s"
464464
msgstr ""
465465

@@ -492,14 +492,14 @@ msgid "Google Pay"
492492
msgstr ""
493493

494494
#. translators: %s: Action ID.
495-
#: includes/class-wc-gateway-checkout-com-google-pay.php:250
496-
#: includes/class-wc-gateway-checkout-com-paypal.php:600
495+
#: includes/class-wc-gateway-checkout-com-google-pay.php:270
496+
#: includes/class-wc-gateway-checkout-com-paypal.php:629
497497
msgid "Checkout.com Payment refunded - Action ID : %s"
498498
msgstr ""
499499

500500
#. translators: %s: Action ID.
501-
#: includes/class-wc-gateway-checkout-com-google-pay.php:255
502-
#: includes/class-wc-gateway-checkout-com-paypal.php:605
501+
#: includes/class-wc-gateway-checkout-com-google-pay.php:275
502+
#: includes/class-wc-gateway-checkout-com-paypal.php:634
503503
msgid "Checkout.com Payment Partially refunded - Action ID : %s"
504504
msgstr ""
505505

@@ -509,8 +509,8 @@ msgstr ""
509509
msgid "PayPal"
510510
msgstr ""
511511

512-
#: includes/class-wc-gateway-checkout-com-paypal.php:390
513-
#: includes/class-wc-gateway-checkout-com-paypal.php:432
512+
#: includes/class-wc-gateway-checkout-com-paypal.php:418
513+
#: includes/class-wc-gateway-checkout-com-paypal.php:460
514514
msgid "An error has occurred while PayPal payment request. "
515515
msgstr ""
516516

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ http://example.com/?wc-api=wc_checkoutcom_webhook
171171
After the plugin has been configured, customers will be able to choose Checkout.com as a valid payment method.
172172

173173
== Changelog ==
174+
v4.9.1 18th March 2024
175+
- **[fix]** Payment gateways on `order-pay` page
176+
174177
v4.9.0 19th Novemeber 2024
175178
- **[fix]** 422 error on Paypal Payment Gateway
176179

woocommerce-gateway-checkout-com.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* Description: Extends WooCommerce by Adding the Checkout.com Gateway.
66
* Author: Checkout.com
77
* Author URI: https://www.checkout.com/
8-
* Version: 4.9.0
8+
* Version: 4.9.1
99
* Requires Plugins: woocommerce
1010
* Requires at least: 5.0
11-
* Stable tag: 4.9.0
11+
* Stable tag: 4.9.1
1212
* Tested up to: 6.7.0
1313
* WC tested up to: 8.3.1
1414
* Requires PHP: 7.3
@@ -25,7 +25,7 @@
2525
/**
2626
* Constants.
2727
*/
28-
define( 'WC_CHECKOUTCOM_PLUGIN_VERSION', '4.9.0' );
28+
define( 'WC_CHECKOUTCOM_PLUGIN_VERSION', '4.9.1' );
2929
define( 'WC_CHECKOUTCOM_PLUGIN_URL', untrailingslashit( plugins_url( basename( plugin_dir_path( __FILE__ ) ), basename( __FILE__ ) ) ) );
3030
define( 'WC_CHECKOUTCOM_PLUGIN_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
3131

0 commit comments

Comments
 (0)