Firs of all excuse me for my English, is not my native language.
Disclaimer: I don't recommend anyone to use the files i give in this tutorial in a production server, I'm no responsible of any lost, hack, liability or any other thing that happen for the use of this files.
The purpose of this tutorial is to guide people in the payment process integration with Paypal, but you need to study a little to make great things happen.
Requirements:
- Paypal account (you at least must know how to use it)
- Web Server with PHP (no free host, unless you find a great free PHP host with cURL built in, try to find at least a shared host. Note that is for testing purposes, i recommend you for real environment your own VPS, AWS and so on)
Where going to use the Instant Payment Notification (IPN) service from paypal.
Short description: Instant Payment Notification (IPN) is a message service that notifies you of events related to PayPal transactions. You can use it to automate back-office and administrative functions, such as fulfilling orders, tracking customers, and providing status and other information related to a transaction.
For use this service we're going to need 4 files:
- The listener (ipn.php)
- A certify (cacert.pem)
- A pay form (payform.php)
- The check items file (itemcheck.php)
The listener will receive the Paypal transactions and if the transaction is ok it will create a file in your server inside a folder called "pays" with the id of the player.
The certify as always, you need a key for transactions.
The pay form is where you copy your html from your paypay account.
The check items file is the one that finds if the user already pay for the weapon and if so, show to the player. You can find a capx file with an ajax query to this file.
You can download all those files here:
http://www.xerira.com/paypal/paypal.zip
Put all the files in your server for example:
example.com/paypal/ipn.php
example.com/paypal/cacert.php
example.com/paypal/payform.php
example.com/paypal/itemcheck.php
You can put where you want but remember that path because we need for the next step.
Now we need to enable the service in our account so you need to log in to your Paypal account, then you land in My Account tab, under the same tab we need to go on the Profile link:
Then go on the link Instant Payment Notification Preferences:
Set the settings for our IPN:
Now we must fill the Notification URL field with the URL where we place the listener (ipn.php), then select the Receive IPN messages (Enabled) option to get the notifications when someone makes a payment and Save.
Now you should see you current settings, in my case I use one of my testing domains xerira.com/paypal so this is how my settings looks like:
Now that all is up, every payment we receive will be listened by our listener (ipn.php), currently supported payments are eCheck, Express Checkout, Cart Checkout, Web Accept, Refunds, eBay Checkout and Reversal.
So lets create a payment button under the merchant services tab:
When you finish your button copy the code that paypal generates:
And paste into the payform (payform.php)
Now every pay VERIFIED will create a file with the name of the player inside a folder called pays on your server (this is a really lazy validation way, just to omit databases and all the complex things).
You can find a paypal sandbox here: http://www.xerira.com/paypal/
to test the entire project.
Notice that this is not the only way to make an integration with a payment processing service, is just a way or approach to do that.
Remember that in a real production server you will need a lot of things, I always recomend to get a robust framework that speed up the development and help with the intrusion protection, xss/sql injections, active records, ORM's and all those nice things and keep in mind that payments are not straight forward, you will need a solid coding like sessions for the users or at least a token, databases to track the payment and login, your listener must be able to handle bad request, pending request, refunds, frauds, bad connections, lost transactions and keep a record of your customers payments just in case things going wrong, taxes, tickets and all the heavy back-end that a game needs.
Hope this guide gives you a light on the road.