Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1
    Join Date
    Oct 2007
    Location
    France & Luxembourg
    Posts
    37
    Plugin Contributions
    0

    help question Which Method should the module use to launch payment

    Hello Zenners
    I have a custom payment module, which i did not program.
    The problem is, i feel there should be a change to the module.

    -Problem-
    The module makes zen-cart send out the order confirmation mail
    right after clicking confirm, before sending the customer to a payment server.

    -Consequence-
    When the payment fails, the customer is sent back to the confirm page,
    but the order number increments (because the processing script deletes the order in case of a failure)
    and the customer can click confirm again, where again the mail is again sent.
    This quickly gets messy, because one customer might make two tries or even doesn't convert,
    but we remain with confirmation emails that are not valid anymore. (as well as the customer)
    This doesn't seem to happen when i use the paypal IPN, where there's no mail
    being sent, at least NOT RIGHT AFTER the customer clicks confirm.


    How is the module designed:
    The module uses a table to associate "order id" to "transaction id".
    The module redirects to a payment server, passing along variables formated in the module's runtime.
    During the interaction between server and payment server,
    processing happens through external files (not in the module) which
    verify the infos,
    exchange response (and update order status, delete orders that failed) and
    redirect to checkout pages.
    success (with session_cart reset, _sess_destroy variables) or
    failure )


    My actions so far :
    --I've read through the wiki subject about payment modules,
    http://www.zen-cart.com/wiki/index.p...ayment_Classes
    --Compared the module code to these payment modules , COD, CC.
    --Took a close look onto the processing scripts / functions.

    My Questions:
    • Which Method should the module use to launch payment procedure decribed ontop.
    • Is it necessary to remove an order when the payment fails or can the order id be used again ? So that when the user clicks confirm again no new order is created.
    • I cannot find out where the heck the email confirmation is triggered,
      possibly using one of the methods.


    I would really appreciate getting help on this one,
    it's way over my capabilities.

  2. #2
    Join Date
    May 2005
    Location
    Bath, Somerset
    Posts
    1,053
    Plugin Contributions
    3

    Default Re: Which Method should the module use to launch payment

    1 - Payment modules make use of 2 main methods. The process_button and before_process. The process_button function is the one which should handle sending the data to your gateway, if using POST data transfer, or the before_process if you are using CURL data transfer. The before_process then checks your data response from the gateway, and acts accordingly. If it detects a failure, then it should redirect to the payment page with a waring. If all is good, then it just carries on to place the order.

    2 - as the order is never placed, until the payment is confirmed, you do not have to remove any order data from the database if the order payment fails. This means that to get an order_id for a payment transaction, you need to be a little clever, and grab the highest order_id currently in the order table, and tehn increment it by 1 to get the probable next order id.

    3 - The email trigger is in the order.php class, and is triggered automatically after the payment before_process function has run. If your payment class is allowing the routine t get this far, then the order is placed automatically.

    Hope this helps,

    Absolute

  3. #3
    Join Date
    Oct 2007
    Location
    France & Luxembourg
    Posts
    37
    Plugin Contributions
    0

    Default Now i could need a little help with Objects/classes and "invoking" methods

    All your anwers really helped out to move on into the problem,
    and i already improved the module because of gained confidence.
    It was also quite helpful to explain that the order is not placed unless the order
    is confirmed, you proposed to get the probable next order id.
    Many Many thanks for helping out so quickly


    The script is still working, until some point.
    Now i could need a little help with Objects/classes
    and "invoking" methods. At the moment, other functions are in external files.
    I guess i could add some of those functions inside the module.

    My actions:
    - I added check for the current zone to show/hide the module.
    - I moved the "checkpayment-launching"-process into the before_process method.
    This already fixed the problem with the email that was sent too early, but now no email comes at all, because i moved it entirely
    (In fact it was all in one piece in the after_process method)
    Also it turned out to make the confirm button to disappear when inserted into
    the "process_button" method, that's why it is now in the before_process.
    Also even tough the payment succeeds, zen cart redirects to the confirm page.
    this might be because the order doesn't exist.

    During a payment events happen this order :
    The Payment Module
    before_process method (should be process_button)
    1 - generates a reference and attaches order infos.
    2 - redirects to payment page sending variables using GET

    The external files for processing do this:
    verify.php
    sends back to payment server values from the transaction table && they must match those sent over redirect's GET.

    response.php
    gets the response from the payment server
    updates TABLE_ORDERS, TABLE_ORDERS_STATUS_HISTORY
    adds message to the messageStack
    and updates transactions table
    in case of a failure, it deletes the order
    (can be dropped, since order doesn't exist yet.)

    success
    updates transactions
    destroys session variables
    and redirects to checkout success

    failure
    updates transactions
    destroys session variables
    and redirects to checkout _confirmation


    i can imagine they can be included into the module itself,
    but i don't know
    -- in which method the different parts belong
    and the most unobvious to me
    -- how to call the corresponding method from the payment server,
    who is supposed to get echoed string with the details (verify) and how to handle his "response". Maybe there a way to include the content of the external files
    into the paymentmodule's correct methods and have them triggered by the external files if not possible to have the payment server trigger them.
    Also note that calls to the method will be protected by checking the IP of the originating server.

    Many thanks in advance.

  4. #4
    Join Date
    Oct 2007
    Location
    France & Luxembourg
    Posts
    37
    Plugin Contributions
    0

    Default Re: Which Method should the module use to launch payment

    I have a small but crucial question.
    I can see how i could place / distribute the code inside the "payment class"
    but i am stuck with the fact that i don't know
    how to call it from an external server,
    since it's inside the class, inside a method.

    maybe it's much easier than i expect ? Any help welcome
    Last edited by mypashop; 28 Jan 2008 at 05:01 PM. Reason: typo

  5. #5
    Join Date
    May 2005
    Location
    Bath, Somerset
    Posts
    1,053
    Plugin Contributions
    3

    Default Re: Which Method should the module use to launch payment

    If you send ALL responses from your payment gateway to http://www.yourstore.com/index.php?m...eckout_process, then the order process will trigger automatically. When the order process resumes, a full cart is created, and then the payment class before_process is fired again.

    At this point, you need to include some code to test if this there are any posted response variables available. If there are, you know that this function is called as a response to the order being processed. Now you can test these responses with the appropriate MD5/security checks to ensure that it is definately a post from your gateway, and obviously to test that the transaction was a success. If anything goes wrong with your checks at this stage, you need to add a session message alert, and then forcefully redirect the user to the payment page. This will stop the order process immediately, and no order will be placed.

    If your checks are successful, then its just a case of returning true from this function and the order will proceed successfully.

    Good luck,

    Absolute

  6. #6
    Join Date
    Oct 2007
    Location
    France & Luxembourg
    Posts
    37
    Plugin Contributions
    0

    Default i'm stuck with retrieving the last order id

    Anyway, i am progressing good in consolidating the module in one file,
    calling the before_process() method is automatic, as you said by going to payment_process.
    the switches for talking to the payment gateway already work fine.

    Quote Originally Posted by Absolute View Post
    2 - as the order is never placed, until the payment is confirmed, you do not have to remove any order data from the database if the order payment fails. This means that to get an order_id for a payment transaction, you need to be a little clever, and grab the highest order_id currently in the order table, and tehn increment it by 1 to get the probable next order id.
    Maybe this is basic, but how SHOULD THIS BE DONE?

    ALSO I encountered trouble with passing variables from a method to another,
    but for $order 'total' i simply redefined it like in the previous method.
    Is it possible to pass variables from a method to another ?

  7. #7
    Join Date
    Oct 2007
    Location
    France & Luxembourg
    Posts
    37
    Plugin Contributions
    0

    Default Re: Which Method should the module use to launch payment

    PHP Code:
    $lastidlist =     mysql_query('SELECT orders_id FROM orders ORDER BY orders_id DESC LIMIT 0, 1');
    $lastid mysql_fetch_row($lastidlist);
    $nextid = ++$lastid[0];
    echo (
    '<br>$nextid='.$nextid); 
    i guess it's not perfect but this works for getting the last order_id.
    but can i pass variables from a method to another ?
    how does it work?

  8. #8
    Join Date
    May 2005
    Location
    Bath, Somerset
    Posts
    1,053
    Plugin Contributions
    3

    Default Re: Which Method should the module use to launch payment

    Firstly, you should use the built in Zen db class for ALL your db queries. It's there for a reason.

    Code:
    $lastidlist =     $db->Execute('SELECT orders_id FROM orders ORDER BY orders_id DESC LIMIT 0, 1');
    $nextid = $lastidlist->fields['orders_id'] + 1;
    echo ('<br>$nextid='.$nextid);
    Secondly, why do you want to pass this from one function to another? You should include this just before you create your transaction post for the gateway. Update the database with the transaction details, and send the data to the gateway in the same function. Then on return, you jsut use the transaction id to pull the data back out of the database if you need it.

    You should only ever need to get the next possible order_id once, and after that the order either goes through, and creates its own order_id, or it fails in which case you just ignore any further code, and go back to the previosu page with the error message.

    Absolute

  9. #9
    Join Date
    Oct 2007
    Location
    France & Luxembourg
    Posts
    37
    Plugin Contributions
    0

    Default Re: Which Method should the module use to launch payment

    tanks for correcting the syntax. In fact i am not used to the zencart core functions, but it seems important to stick to using them.
    I have an issue with another core function

    the zen_redirect() function makes the process button disappear,
    although the "URL" is correctly formatted with all the query params.
    (displays correctly with echo)

    PHP Code:
    // Build the data and actions to process
    // when the "Submit" button is pressed on the order-confirmation screen.
    //PROCESS BUTTON **********************************************************
    Some LINES are SKIPPED for UNCLUTTERED OVERVIEW
    ***********
        function 
    process_button() {
            if(
    $amount) {
                if(
    $transactions_id $db->Insert_ID()) { // Generates reference
                    
    if(fields){    // Verifies parameters in form
                        
    $redirect_params = array();
                    } 
    // endif (Verifies parameters in form)
                
    //endif (transactions_id = $db->Insert_ID)
            
    // end if amount     
        // Redirect to payment page
            
    echo $redirectit $url.'?'.implode('&'$redirect_params);
            
    zen_redirect($redirectit);
         return 
    false;
        
    // exit();

        
    // end function(processbutton); 
    Also, i am a bit confused by the fact that the echo (zen_redirect) happens,
    without having displayed the button nor clicked it.
    i tried, but i can't find the
    my next try ... include application_top if the redirect function is declared within that one.

  10. #10
    Join Date
    Oct 2007
    Location
    France & Luxembourg
    Posts
    37
    Plugin Contributions
    0

    Default Re: Which Method should the module use to launch payment

    same trouble as ZEN_REDIRECT FUNCTION

    with

    PHP Code:
    $messageStack->add_session(SUCCESS_ORDER_UPDATED'success'
    doesn't execute and stops PHP

    OK, the order isn't yet created, but it's just about to be.
    Maybe Update order makes no sense, but i mentionned this
    error because i feel it might be the same isssue as for the redirect core function that doens't work
    Last edited by mypashop; 30 Jan 2008 at 01:22 PM. Reason: removed signature // added detail

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Which shipping or payment module I should use?
    By futurist71 in forum Addon Shipping Modules
    Replies: 1
    Last Post: 16 Jul 2011, 11:03 AM
  2. Which Paypal method should I use?
    By atmosx in forum General Questions
    Replies: 4
    Last Post: 14 Dec 2009, 12:49 PM
  3. No Payment Options - This is currently the only payment method available to use on ..
    By keeno79 in forum Built-in Shipping and Payment Modules
    Replies: 1
    Last Post: 11 May 2009, 02:58 PM
  4. Need input on which payment module to use.
    By jodib in forum Addon Payment Modules
    Replies: 0
    Last Post: 15 Aug 2007, 01:24 AM
  5. Which payment method should I offer?
    By yellow1912 in forum Built-in Shipping and Payment Modules
    Replies: 8
    Last Post: 3 Aug 2007, 10:57 PM

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