Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Apr 2024
    Posts
    8
    Plugin Contributions
    0

    help question Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Hello Zen Cart Community,

    I'm working with a custom payment module on my Zen Cart site that relies on an iframe for processing payments. The flow is as follows:

    The customer completes their order and confirms it.
    An iframe is generated for payment processing.
    Upon payment completion, a success page is displayed.
    Simultaneously, a webhook is triggered to handle post-payment actions.
    The challenge I'm encountering is related to the externalUserId parameter in the webhook. The externalUserId should contain the most recent order ID generated by Zen Cart upon order confirmation. However, attempts to retrieve this ID have been unsuccessful – I either get an outdated order number (the previous order) or no result at all.

    The expected behavior is to capture the latest order ID in time to include it in the webhook payload. However, there seems to be a timing issue or a session management problem that prevents the accurate retrieval of the order ID after the order confirmation and before the webhook is sent.

    Here's what I have tried so far:

    Using session variables to pass the order ID, which has resulted in incorrect or empty values.
    Directly querying the database for the latest order ID, which also doesn't seem to capture the correct ID in time.
    This has been a persistent issue affecting the payment confirmation process, and I'm looking for insights or suggestions on how to reliably capture the latest order ID in the webhook after the customer has confirmed their order.

    I have spent over a month on this pulling my hair out. I now am hoping that someone else that has been through this, could possibly direct me in the right direction.

    Thank you in advance.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,472
    Plugin Contributions
    88

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    The actual orders_id isn't generated and available to the payment module until the module's after_order_create method is called with that just-created order-id.

  3. #3
    Join Date
    Apr 2024
    Posts
    8
    Plugin Contributions
    0

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Quote Originally Posted by lat9 View Post
    The actual orders_id isn't generated and available to the payment module until the module's after_order_create method is called with that just-created order-id.
    Thank you for your reply. Is there a way to take the cartID and match that up with an order id? I'm trying to figure out how to match up with an order. I am still having problems trying to get the order number.

  4. #4
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,684
    Plugin Contributions
    9

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Quote Originally Posted by buttons View Post
    Thank you for your reply. Is there a way to take the cartID and match that up with an order id? I'm trying to figure out how to match up with an order. I am still having problems trying to get the order number.
    get the next order number from the orders table, use that, and move on.

    i like the method in this post.

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  5. #5
    Join Date
    Apr 2024
    Posts
    8
    Plugin Contributions
    0

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Quote Originally Posted by carlwhat View Post
    get the next order number from the orders table, use that, and move on.

    i like the method in this post.

    best.
    When I try to grab the orders_id, it is empty.

    Here's the sequence I have implemented so far:

    In the before_process method, I generate an iframe for the payment interface.
    I've attempted to capture the order ID in the after_order_create method, which seems to be the logical place to get the latest order ID. This is the code snippet I've used:

    Code:
    public function after_order_create($insert_id) {
        global $db;
    
        // Logging the order ID for debugging
        file_log("after_order_create called. Order ID: {$insert_id}");
    
        // Prepare the webhook data with the order ID
        $webhookData = [
            'amount' => $amount,
            'currency' => $currency,
            'externalUserId' => $insert_id,
        ];
    
        // Send the webhook with the prepared data
        $this->send_webhook($webhookData);
    }
    I've also tried fetching the order ID directly in the webhook.php file.

    I am aware that guessing the next order number is not feasible due to the risk of duplication. My concern is ensuring the after_order_create method is triggered at the correct time so I can send the order ID via the webhook without issues.

    Could you advise on the proper sequence to handle this process, especially concerning the placement of the after_order_create in relation to the iframe generation in the before_process method? Is there an established best practice for this scenario that I might be overlooking?

    Any insights or suggestions would be greatly appreciated, as I might be missing something obvious due to my close involvement with the project.

  6. #6
    Join Date
    Apr 2024
    Posts
    8
    Plugin Contributions
    0

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Quote Originally Posted by carlwhat View Post
    get the next order number from the orders table, use that, and move on.

    i like the method in this post.

    best.
    Quote Originally Posted by carlwhat View Post
    get the next order number from the orders table, use that, and move on.

    i like the method in this post.

    best.
    When I try to grab the orders_id, it is empty.

    Here's the sequence I have implemented so far:

    In the before_process method, I generate an iframe for the payment interface.
    I've attempted to capture the order ID in the after_order_create method, which seems to be the logical place to get the latest order ID. This is the code snippet I've used:

    public function after_order_create($insert_id) {
    global $db;

    // Logging the order ID for debugging
    file_log("after_order_create called. Order ID: {$insert_id}");

    // Prepare the webhook data with the order ID
    $webhookData = [
    'amount' => $amount,
    'currency' => $currency,
    'externalUserId' => $insert_id,
    ];

    // Send the webhook with the prepared data
    $this->send_webhook($webhookData);
    }

    I've also tried fetching the order ID directly in the webhook.php file.

    I am aware that guessing the next order number is not feasible due to the risk of duplication. My concern is ensuring the after_order_create method is triggered at the correct time so I can send the order ID via the webhook without issues.

    Could you advise on the proper sequence to handle this process, especially concerning the placement of the after_order_create in relation to the iframe generation in the before_process method? Is there an established best practice for this scenario that I might be overlooking?

    Any insights or suggestions would be greatly appreciated, as I might be missing something obvious.

  7. #7
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,684
    Plugin Contributions
    9

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    i have never used the after_order_create method.

    does your log have the proper order number?

    i would use the trigger_error method so that the log goes to the standard apache log and then zen would order override it.

    your code looks fine to me. but the question is whether your webhook is run at the right time.

    have you tried in the after_process method?



    PHP Code:
            public function after_process()
            {
                global 
    $insert_id;

    // one would need the code to get the currency and amount

    // Prepare the webhook data with the order ID
    $webhookData = [
    'amount' => $amount,
    'currency' => $currency,
    'externalUserId' => $insert_id,
    ];

    // Send the webhook with the prepared data
    $this->send_webhook($webhookData);

    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  8. #8
    Join Date
    Apr 2024
    Posts
    8
    Plugin Contributions
    0

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Thank you for your reply.

    I sometimes get the correct order number. in a log file. I can also get an old order number sometimes. I can always get the CartID, but there isn't much I can do with that, I cannot tie to an order. The post above yours said the order ID comes with the after_order_create. I am trying to use this to grab the order_id. Timing is very much the issue and it's finding that right timing.

  9. #9
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,684
    Plugin Contributions
    9

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Quote Originally Posted by buttons View Post
    Thank you for your reply.

    I sometimes get the correct order number. in a log file. I can also get an old order number sometimes. I can always get the CartID, but there isn't much I can do with that, I cannot tie to an order. The post above yours said the order ID comes with the after_order_create. I am trying to use this to grab the order_id. Timing is very much the issue and it's finding that right timing.
    my friend, do you want my help? if not, please let me know, and i will stop.

    i look at all posts prior to posting on a thread.... well at least on short threads...

    i saw the post referenced above written by my friend lat9, who i have tremendous respect for and who does so much for this community. when it comes to payment modules, i'm pretty confident she would say the same about me.... maybe not...

    the after_order_create should work. but you are saying it does not. i am offering a different solution that i use in the multiple payment modules that i have created for zen-cart. in fact, it is the same methodology used in payment modules that come with the base package.

    see this module.

    so you can either try it that way and let the community know if it works or if does not. and if it does not, i would argue that something else is going on in your code.

    best.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  10. #10
    Join Date
    Apr 2024
    Posts
    8
    Plugin Contributions
    0

    Default Re: Issues with Custom Payment Module Retrieving Latest Order ID for Webhook

    Quote Originally Posted by carlwhat View Post
    my friend, do you want my help? if not, please let me know, and i will stop.

    i look at all posts prior to posting on a thread.... well at least on short threads...

    i saw the post referenced above written by my friend lat9, who i have tremendous respect for and who does so much for this community. when it comes to payment modules, i'm pretty confident she would say the same about me.... maybe not...

    the after_order_create should work. but you are saying it does not. i am offering a different solution that i use in the multiple payment modules that i have created for zen-cart. in fact, it is the same methodology used in payment modules that come with the base package.

    see this module.

    so you can either try it that way and let the community know if it works or if does not. and if it does not, i would argue that something else is going on in your code.

    best.
    Absolutely I welcome your input and help :) I will take a look at the file you have provided and try to implement. I will update once done.

    Thank you so much.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Low order fee in trouble with custom payment module
    By ellivir in forum Addon Payment Modules
    Replies: 3
    Last Post: 27 Feb 2014, 03:32 PM
  2. v151 losing some data of order in my custom payment module
    By dial in forum Addon Payment Modules
    Replies: 0
    Last Post: 20 Jul 2013, 11:44 AM
  3. Multiple Payment Types Per Order With Custom Module?
    By user2037 in forum Addon Payment Modules
    Replies: 0
    Last Post: 25 Jul 2011, 04:45 PM
  4. custom payment module help with coupons
    By jouba in forum Addon Payment Modules
    Replies: 2
    Last Post: 20 May 2011, 04:37 PM
  5. Help needed with custom payment module
    By etrader in forum General Questions
    Replies: 1
    Last Post: 2 Dec 2008, 03:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR