Skip to content

Commit

Permalink
Add logging in Ajax requests for ECE (#3533)
Browse files Browse the repository at this point in the history
* add logging in ajax requests for ECE

* add changelog
  • Loading branch information
Mayisha authored Oct 24, 2024
1 parent 493b739 commit 4bb5743
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Fix - Fix the display and usage of the Link payment method on the shortcode checkout page with the Stripe Express Checkout Element.
* Fix - Prevent marking orders on-hold with order note "Process order to take payment" when the payment has failed.
* Fix - Fix payment methods count on settings page.
* Tweak - Add error logging in ECE critical Ajax requests.

= 8.8.0 - 2024-10-17 =
* Fix - Update URL and path constants to support use of symlinked plugin.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public function ajax_get_selected_product_data() {

wp_send_json( $data );
} catch ( Exception $e ) {
WC_Stripe_Logger::log( 'Product data error in express checkout: ' . $e->getMessage() );
wp_send_json( [ 'error' => wp_strip_all_tags( $e->getMessage() ) ] );
}
}
Expand All @@ -302,23 +303,33 @@ public function ajax_get_selected_product_data() {
* Create order. Security is handled by WC.
*/
public function ajax_create_order() {
if ( WC()->cart->is_empty() ) {
wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
}
try {
if ( WC()->cart->is_empty() ) {
wp_send_json_error( __( 'Empty cart', 'woocommerce-gateway-stripe' ) );
}

if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
define( 'WOOCOMMERCE_CHECKOUT', true );
}
if ( ! defined( 'WOOCOMMERCE_CHECKOUT' ) ) {
define( 'WOOCOMMERCE_CHECKOUT', true );
}

$this->express_checkout_helper->fix_address_fields_mapping();

$this->express_checkout_helper->fix_address_fields_mapping();
// Normalizes billing and shipping state values.
$this->express_checkout_helper->normalize_state();

// Normalizes billing and shipping state values.
$this->express_checkout_helper->normalize_state();
// In case the state is required, but is missing, add a more descriptive error notice.
$this->express_checkout_helper->validate_state();

// In case the state is required, but is missing, add a more descriptive error notice.
$this->express_checkout_helper->validate_state();
WC()->checkout()->process_checkout();
} catch ( Exception $e ) {
WC_Stripe_Logger::log( 'Failed to create order for express checkout payment: ' . $e );

WC()->checkout()->process_checkout();
$response = [
'result' => 'error',
'messages' => $e->getMessage(),
];
wp_send_json( $response, 400 );
}

die( 0 );
}
Expand Down Expand Up @@ -356,14 +367,14 @@ public function ajax_pay_for_order() {
return;
}

$order_id = intval( $_POST['order'] );
try {
// Set up an environment, similar to core checkout.
wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true );
wc_set_time_limit( 0 );

// Load the order.
$order_id = intval( $_POST['order'] );
$order = wc_get_order( $order_id );
$order = wc_get_order( $order_id );

if ( ! is_a( $order, WC_Order::class ) ) {
throw new Exception( __( 'Invalid order!', 'woocommerce-gateway-stripe' ) );
Expand All @@ -386,6 +397,8 @@ public function ajax_pay_for_order() {

$result = apply_filters( 'woocommerce_payment_successful_result', $result, $order_id );
} catch ( Exception $e ) {
WC_Stripe_Logger::log( 'Pay for order failed for order ' . $order_id . ' with express checkout: ' . $e );

$result = [
'result' => 'error',
'messages' => $e->getMessage(),
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
* Fix - Fix the display and usage of the Link payment method on the shortcode checkout page with the Stripe Express Checkout Element.
* Fix - Prevent marking orders on-hold with order note "Process order to take payment" when the payment has failed.
* Fix - Fix payment methods count on settings page.
* Tweak - Add error logging in ECE critical Ajax requests.

[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

0 comments on commit 4bb5743

Please sign in to comment.