An application I've developed does online event registration. Many events have a fee that can be paid by credit card. The system works very well most of the time, but users do sometimes manage to make multiple payments (by clicking refresh) or to have their credit cards charged without us having any record of the transaction. The process I'm using to enter registrations is as follows (pseudo-code):
INSERT INTO registrations (to reserve spot for the registration) Generate unique key for payment that is included in all subsequent com +munication from browser Collect information for registration Check that payment with unique key hasn't been entered Get credit authorization UPDATE registration record with collected information including a fina +lized flag INSERT INTO payments (information from credit processor with transacti +on code, unqiue key from previous step, etc)

There are several spots where things can go wrong. Sometimes a user will click refresh in the moment between submitting the transaction for approval and inserting the payment information in the payments table. This prevents the unique key check from stopping the second payment. Sometimes a database error after transaction approval prevents the information being stored properly.
Is there a good way to make this process atomic?
Thanks!

In reply to Making credit processing atomic by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.