Page 1 of 1

Account Credits

Posted: Thu Feb 03, 2011 2:20 am
by Last Known Hero
Hey all.. been working on my website and had some ideas, but need help. BIG TIME. Hopefully I can get a few replies on this one....

I am looking to make it so a member can buy credits/tokens (through paypal) and then they will be added to their account (and not lost after they log out or any other glitches) preferably javascript. Does anyone have any idea on how to do this? it would help me A LOT.. I tried google but it just came up with other websites wanting me to add credits to their sites :P

Help? :P

Re: Account Credits

Posted: Thu Feb 03, 2011 2:28 am
by Jackolantern
You would need to do it with PHP, not Javascript, since Javascript is not secure and is largely isolated from external resources (such as Paypal).

Re: Account Credits

Posted: Thu Feb 03, 2011 2:33 am
by Last Known Hero
Ah ok, thanks Jack.. anyone know how to do it with php?

Re: Account Credits

Posted: Thu Feb 03, 2011 3:30 am
by Jackolantern
I have never actually messed around with the Paypal API, but I have heard it is pretty easy to use and well-documented.

EDIT: I could probably help you with some of the logic outside of the Paypal implementation, just not with the actual Paypal part.

Re: Account Credits

Posted: Thu Feb 03, 2011 4:48 am
by Last Known Hero
That would be incredible! That would be such a big help :D if you do decide to help, don't feel like your on a time crunch, take your time! :P

Re: Account Credits

Posted: Thu Feb 03, 2011 5:28 am
by Ravinos
When I looked into this way back when one of the proposed ideas was to enter a code into your database when the user click the buy link. This code would be unique and also send the amount of credits they are buying. When the user completes the purchase the redirect link at the end of the paypal purchase confirmation screen would check for the matching code in the database and activate the credits.

That was the jist of it. As far as actually putting it into practice I have no clue.

Re: Account Credits

Posted: Thu Feb 03, 2011 5:52 pm
by Jackolantern
Last Known Hero wrote:That would be incredible! That would be such a big help :D if you do decide to help, don't feel like your on a time crunch, take your time! :P
Ooo...well, I meant I could help to debug scripts possibly. I have actually never made a e-commerce solution before, and would not be comfortable doing so until after I have really studied up on it. I know Paypal takes a lot of the danger out of it, but I am not quite familiar enough with security to bank someone else's money on my skills, if you know what I mean.

Re: Account Credits

Posted: Thu Feb 03, 2011 8:14 pm
by Last Known Hero
Ah ok, no problem :) Thanks Jack :)

Re: Account Credits

Posted: Fri Feb 04, 2011 3:06 am
by Last Known Hero
Jackolantern wrote:
Last Known Hero wrote:That would be incredible! That would be such a big help :D if you do decide to help, don't feel like your on a time crunch, take your time! :P
Ooo...well, I meant I could help to debug scripts possibly. I have actually never made a e-commerce solution before, and would not be comfortable doing so until after I have really studied up on it. I know Paypal takes a lot of the danger out of it, but I am not quite familiar enough with security to bank someone else's money on my skills, if you know what I mean.
I forgot to mention, paypal has a 'pay now' button that is made to always make a fake transaction go through, to allow for testing and solutions :)

Re: Account Credits

Posted: Sat Feb 05, 2011 8:41 am
by Gate
Paypal is pretty easy, the system works as follows:

1) Your Website takes payment amount and item that the user is buying and post's these to paypal (usually using cURL)

2) Paypal takes details and process's orders

3) Paypal sends $_POST data back to a url script of your choice (Example: Send: Userid, ProductId, Amount to http://www.somesite.com/finalise_payment.php)

4) You update everything and process the data in the url script you provided (in this example that would be finalise_payment.php

Other notes:

Make SURE you verify that the url requesting the script (finalise_payment.php) is from Paypal, a simple way to test this is to find the url that paypal uses to post the request to your script and then to use:

Please note i have not tested this code so it may not work and may need debugging :D

Code: Select all

$host = $_HTTP['REMOTE_HOST'];
if ($host != "http://www.paypal.com") {
    header( 'Location: 'http://www.somesite.com/error.php';
}
To verify that it's Paypal that is sending you payment information and not just some random person :shock:

Paypal, as you will find, is a breeze once you've done it once, like riding a bike :)