Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Thanked 0 Times in 0 Posts

    php database calls

    im trying to charge customers for a recurring service using a php script. The script must check many customer database fields to determine who to charge and how much. I'm just confused on the "best practices" that would be used in this scenario.
    Should i make one huge select statement to the SQL database for each client and store all their info temporarily in arrays while working on them, and then one huge update statement at the end? Im afraid if i start manipulating things one at a time i might have a problem with credit card acceptance (or anything else), and have to somehow go back and recreate the customer's previous state.
    Or am i using entirly the wrong approach?
    It hard enough to learn all these technologies let alone understand where to use which and when
    Any direction would be appreciated, let me know if you need more detail to answer.


  • #2
    Master Coder
    Join Date
    Jun 2003
    Cottage Grove, Minnesota
    Thanked 1,096 Times in 1,087 Posts
    I think it depends on what the criteria is for charging the customer.

    After you successfully charge them, what changes in their database row
    that satisfies them until the next time they're charged? Describe how you
    determine who to charge.

    I would create a "charge" script that executes automatically every hour.
    It finds the first row that needs to be charged, based on your criteria. It processes
    that charge and finishes. An hour later, it finds the next one ... and next ... etc.
    Most of the time, it may not find any charges to process.

    So, it will automatically charge up to 24 customers each day. Not sure how many
    customers you have, but it will just keep cycling through every hour every day.

    A PHP script can be automatically executed by using your webhosts CRON service.
    You set the time intervals, days, etc. Maybe you only want charges to be made
    Mon-Fri, but not on weekends.

    You can also create more columns in your database to handle the "pending" charge,
    to make sure the transaction is successful before "finalizing" the charge. When it is
    finalized, that customer will no longer meet the criteria for being charged. The next
    time the CRON runs, it will pick the next customer that meets the criteria.



    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts