Pregunta

I am coding my website using Codeignitor and MySQL. Users need to create a new account to use my website. Every user has a unique ID along with other information saved in the database. I plan on using an online payment service such as PayPal or Google Wallet.

However, after a user makes a purchase, how do I match that purchase on the online payment service (ie. Paypal) to the user in my database, so I can render the appropriate service to that customer?

For example, if a user makes a purchase using the PayPal button, I'll see a record of that purchase on my PayPal account. But how do I know which user of mines in my database is the one who made that purchase listed on my PayPal merchant account? Do I just have to trust that user's information on PayPal (First name, last name, etc) is the same information he or she entered on my website?

¿Fue útil?

Solución

With paypal IPN, paypal will automatically run a specified script once payment is made. In this script you can add info into your database, such as which user made the payment, txnid(transaction ID), payment amount, payment status. All things that may be useful in the future. Here are some useful links:
IPN documentation.
IPN setup walkthrough

You will need to activate IPN in your paypal settings and input a script for paypal to run.
You can also setup this script to "render the appropriate service to that customer" as you mentioned above.
Once you have ipn and database insertion up and working you could add a php mail function to the script to inform yourself of which user has made a purchase:

<?PHP

//mail variables    
$emailAddress = "your@email.net";  

$subject = "User Purchase";    

$message = "$user has made a purchase of $product for $productPrice";  

$headers = "MIME-Version: 1.0" . "\r\n";    
$headers.= "Content-type:text/html;charset=iso-8859-1" . "\r\n";    
$headers.= 'From: noreply@yourdomain.com' . "\r\n" .      
        'Reply-To: noreply@yourdomain.com' . "\r\n" .        
        'X-Mailer: PHP/' . phpversion();

//mail function    
mail($emailAddress, $subject, $message, $headers);    

?>

This mail function can also be used for debugging purposes. Just add information/variables you need to debug into the $message variable and you will receive an email everytime the script runs.

Otros consejos

I beleive once users leave your site to pay with PayPal, PayPal will in fact post information back to your website letting you know that it was succesful or not.

Here is the API Docs:

https://developer.paypal.com/webapps/developer/docs/classic/adaptive-payments/gs_AdaptivePayments/

Towards the bottom of the page contains

Once the buyer authorizes the payment, the transaction is complete and they are redirected to the URL specified by the returnUrl input field in your Pay request.

Hope that helps!!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top