I just recently set up my calling card software the following way:
Rather than using a2billing and MySQL database, I am using Berkeley on-disk database, because it is much more fast and reliable. Then, in order to avoid possible issues with locks I am using IPC semaphores.
However if you prefer a2billing and MySQL or PostgreSQL I will implemet according to your preferences. Each customer has a pin-code and balance all recorded in the database. As the customer places the call, billing daemon constantly (like once in every 5 seconds) updates the database as the call lasts. When balance gets exhausted the billing daemon signals to asterisk manager first to warn (1min advance), then to disconnect the caller. The only thing I didn't connect my software to PayPal as I am using prepaid Calling cards. However, I would be glad to implement it in your project.
Thank you, will be looking forward to hear from you