• Hi,

    thank you for the plugin.
    I’m facing a little problem.

    I’m selling products with different prices. For example:

    Product 1 – 1.5 credits
    Product 2 – 0.9 credits
    Product 3 – 7.6 credits

    When my credit balance is 10 and I buy product 1 the order is succesfully completed and the new balance is 8.5

    When my credit balance is 8 and I buy product 3 the order is not succesfully completed and I’m getting the error: “There was an error procesing the payment. Please try again.”. While my balance is reduced and turns in to 0.4.

    When my credit balance is 9 and I buy product 3 the order is succesfully completed and the new balance is 1.4

    When my credit balance is 1.4 and I buy product 2 the order is succesfully completed and the new balance is 0.5

    So it turns out, buying products which ends under 1 (0.9, 0.8, 0.7, 0.6, 0.4, 0.3, 0.2, 0.1) the order failes and the credit balance gets reduced) And it is only working when it ends with 0.5 or 0.

    Any idea how to solve this?

Viewing 1 replies (of 1 total)
  • Thread Starter webvd

    (@webvd)

    This is stupid:

                    $order = wc_get_order($order_id);
                    $user_id = ( WC()->version < '2.7.0' ) ? $order->user_id : $order->get_user_id();
                    $items = $order->get_items();
                    
                    $total_credits_amount = 0;
                    
                    foreach ($items as $item) {
                        $product = $order->get_product_from_item($item);
                        $prod_id = ( WC()->version < '2.7.0' ) ? $product->id : $product->get_id();
                        $credits_amount = get_post_meta($prod_id, '_credits_amount', true);
                        if ($credits_amount) {
                            $credits_amount = $credits_amount * $item['qty'];
                            $total_credits_amount += $credits_amount;
                        } else {
                            wc_add_notice(__('<strong>Payment error:</strong>', 'woo-credits') . ' You can not purchase product without credits set. Please choose another payment method.', 'error');
                            return;
                        }
                    }
                    
                    $download_credits = floatval(get_user_meta($user_id, "_download_credits", true));
                    $cart_total = floatval(WC()->cart->total);
                    
                    if ($total_credits_amount > $download_credits) {
                        wc_add_notice(__('<strong>Payment error:</strong>', 'woo-credits') . ' Insufficient Credits. Please purchase more credits or use a different payment method.', 'error');
                        return;
                    }
                    
                    $new_user_download_credits = $download_credits - $total_credits_amount;
                    update_user_meta($user_id, '_download_credits', $new_user_download_credits);
                    
                    if (get_user_meta($user_id, '_download_credits', true) != $new_user_download_credits) {
                        wc_add_notice(__('<strong>System error:</strong>', 'woo-credits') . ' There was an error procesing the payment. Please try another payment method.', 'error');
                        return;
    
                    }
                    
                    $order->update_status('completed', __('Payment completed use Credits price', 'woo-credits'));

    Why would you add the system error notice for processing the payment after the credit balance of the user is reduced and succesfull? And then run the status update to complete the order? Your forcing the error.

    Above you check for the user to have engough balance, and if they don’t have they are not able to process the order. Or when they try to buy credits with credits.

Viewing 1 replies (of 1 total)
  • The topic ‘Error with credit balance under 1 credit’ is closed to new replies.