• Resolved dakotaq

    (@dakotaq)


    We are looking for a way to prevent manual payments if a customer has already submitted a payment for the same order. Our use case: customer service creates the order and sends the invoice to the customer. Customer receives the payment link and typically pays via Stripe. When they don’t pay in a timely manner, the customer service rep calls the customer and requests payment over the phone with a credit card. In this scenario the customer had two different contacts at the location and they got charged twice. It would be nice to be able to popup a box that says “There is already a payment on this order, would you like to proceed?”

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author bfl

    (@bfl)

    You can use the following snippet:

    add_action( 'admin_enqueue_scripts', function ( $hook ) {
    if ( $hook === 'woocommerce_page_wc-orders' ) {
    ?>
    <script>
    function confirmManualPayment( event ) {
    event.preventDefault();

    if (
    ( event.type === 'keypress' && event.keyCode === 13 && event.target?.matches( '#charge *' ) ) ||
    ( event.type === 'click' && event.target?.id === 'charge-btn' )
    ) {
    if ( jQuery( '#_transaction_id' ).val() ) {
    if ( ! confirm( 'There is already a payment on this order. Would you like to proceed?' ) ) {
    event.stopPropagation();
    }
    }
    }
    }

    document.addEventListener( 'keypress', confirmManualPayment, true );
    document.addEventListener( 'click', confirmManualPayment, true );
    </script>
    <?php
    }
    } );

    This will only work if the customer paid using a payment method that fills out the WooCommerce Transaction ID field (which you can see when editing Billing fields on the order screen). It determines whether a payment has been made by checking if that field is filled out. If you use other payment methods that don’t use that field, you’ll need to determine whether the order has been paid by some other check. Gateways like Stripe use that field.

    Also, this snippet depends on some internal implementation details of WooCommerce and Woo MP, so it may need to be updated if either plugin changes something relevant.

    Thread Starter dakotaq

    (@dakotaq)

    Thanks for the reply @bfl , in looking at the code, if they have been on that page and the payment came through while they were sitting on the page, will this retrieve the transaction id from the database or are you expecting it to be in the current page? My concern is that we might have a race condition if they don’t refresh the page and the data in the current order on the page isn’t loaded.

    Let me know what you think or if you think this covers that scenario.

    Plugin Author bfl

    (@bfl)

    That snippet does not cover that scenario. It would be more complicated to cover that.

    Thread Starter dakotaq

    (@dakotaq)

    Ok, thank you.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Prevent Duplicate Payments’ is closed to new replies.