Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconsider the logic to reuse the rzp order id if cart is unchanged #577

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions includes/api/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function createWcOrder(WP_REST_Request $request)
$expKey = explode('wp_woocommerce_session_', $key);
$sessionResult = $expKey[1];
}

//Abandoment cart plugin decode the coupon code from token
$couponCode = null;
if (isset($params['token'])) {
Expand Down Expand Up @@ -57,7 +57,11 @@ function createWcOrder(WP_REST_Request $request)

$cartHash = WC()->cart->get_cart_hash();
$hash = $sessionResult."_".$cartHash;
$orderIdFromHash = get_transient(RZP_1CC_CART_HASH . $hash);

//Setting the $orderIdFromHash to null, to create a fresh RZP order for each checkout initialisation.
//In future if we need to revert back to earlier flow then consider it from transient as mentioned below.
//$orderIdFromHash = get_transient(RZP_1CC_CART_HASH . $hash);
$orderIdFromHash = null;

if (isHposEnabled()) {
$updateOrderStatus = 'checkout-draft';
Expand Down Expand Up @@ -97,7 +101,7 @@ function createWcOrder(WP_REST_Request $request)
}

$order = wc_get_order($orderId);

if($order){

$disableCouponFlag = false;
Expand All @@ -109,7 +113,7 @@ function createWcOrder(WP_REST_Request $request)
$dynamicRules = $item->get_meta('_ywdpd_discounts');

if(empty($dynamicRules) == false){

foreach ($dynamicRules['applied_discounts'] as $appliedDiscount) {
if (isset( $appliedDiscount['set_id'])){
$ruleId = $appliedDiscount['set_id'];
Expand Down Expand Up @@ -175,8 +179,6 @@ function createWcOrder(WP_REST_Request $request)

$status = 400;
$logObj['response'] = $response;
$logObj['rzp_order_id'] = $rzp_order_id;
$logObj['rzp_response'] = $rzp_response;
rzpLogError(json_encode($logObj));

return new WP_REST_Response($response, $status);
Expand Down Expand Up @@ -270,7 +272,7 @@ function updateOrderStatus($orderId, $orderStatus)
'post_status' => $orderStatus,
));
}

}

function wooSaveCheckoutUTMFields($order, $params)
Expand Down Expand Up @@ -299,5 +301,5 @@ function wooSaveCheckoutUTMFields($order, $params)
}else{
update_post_meta($order->get_id(), "pys_enrich_data", $pysData);
}

}
Loading