Hi david and all.
Just wondering what is the best way to handle a payment system.
I am thinking using Paypal to use as the system to deposit and withdraw. But what I need to know is in the DB how should I handle which is a withdraw and which is a deposit.
The system allows advertisers to buy ads on radio stations, and when they are played the system sends the money to the radio station's account.
for e.g. Say the Advertisers ID was 3 and the Radio station id was 9
from | TO | Amount
3 | 9 | 5.00
Then in another table I was thinking I need to handle their balance so any advice?


Hi Russell, You're thinking
Hi Russell,
You're thinking along the correct lines.
What is essential is that the final authority for an account balance rests with the transaction table; not with an overall "account" table; however there is nothing wrong with storing a running balance in such a table for quick access to an account balance.
There's no need to handle withdrawals or credits differently - every transaction should just be a transfer of funds from one account to another - so all amounts will be held in your transaction table as positive values, in it's most simple form exactly as you describe - "from" account ID, "to" account ID and "amount".
To handle both payments in from advertisers and payments out to radio stations; create an "invoice" account within exactly the same system. Payments received from advertisers should be recorded as a transfer from the invoice account to an advertisers account; and payments out to radio stations recorded as a transfer from the radio station's account to the invoice account.
Somewhere along the line you might also want to record how you are taking your cut - perhaps with a separate "fee" account - so when an advertiser's ad is played; make 2 transfers, one from the advertiser's account to the radio station's account and one from the advertiser's account to the fee account.
This way, the balance of the "fee" account will always represent your profit in the system; and any negative balance of the "invoice" account will represent the balance of advertiser's funds that you are holding (less fees that you have taken) - so it is correct that is represented as a negative value as it is effectively a liability within the system.
Well it's good to know that
Well it's good to know that I am on the right track.
We where thinking of taking our 20% from when Radio stations withdraw. I don't know if this is the best option or if Radio stations will like this. I am still thinking if it should be the advertisers that get the fee taken from their account.
I am guessing to get the % of something I would need to do the following, during the processing of the payment
<?php
$percent = '30'; // without %
$total = '1300'; // initial value
/* Calculate $percent% from $total */
$discount_value = ($total / 100) * $percent;
$final_price = $total - $discount_value;
// Format numbers with number_format()
$total = number_format($total);
$discount_value = number_format($discount_value);
$final_price = number_format($final_price);
echo "Notebook's price: $".$total."<br />Our special discount: <strong>".
$percent."%</strong> (-$".$discount_value.")<br />Final price: $".$final_price;
?>
Hi Russell, Yes - that looks
Hi Russell,
Yes - that looks fine, other than that I would suggest letting PHP use native numeric types rather than strings, in other words just use:
$percent = 30; // without %$total = 1300; // initial value
Cheers,
David.
Alsome, time to start
Alsome, time to start coding, will let you know how it goes... Screen shoots have been finished, and now on the 3rd stage.
Hi David, is there away I
Hi David, is there away I can email you?
I need someone to look over the code for my login and registration script, for the ad network.
Thanks