The documentation is very vague everywhere on this issue, and so are the questions online (including this site):
I have a form that the user must fill out with a few fields. For example, a username and password. Then, they have to purchase something through PayPal. I've created a business account. When the user submits my form it simply queries and adds them to a local database through the PHP at the present. I want to first verify payment through PayPal and then add them to the database. I've also tried adding them to the database with a "paid=0" by default and then trying to get PayPal to send me a success token or something that I can then flip the value to 1, but I'm at a loss for where to start.
First of all i advice you to use PHP Paypal offical SDK with offical subscription's example.
It is be a good idea to store transaction before any Paypal Request, because you can track errors.
Use a "status" field to store transaction status. after that you can do Paypal Payment.
After, you change the status depending on Paypal response.
Hope this helps.
Related
On my website, I want to set up a "pay to remove ads" feature, and I want to collect payments for it through PayPal. The setup that I want for this is quite simple:
User pays
Payment is verified
The entry in the MySQL database containing the user's information is updated to disable ads on the site for that user
To do this, I want to use PayPal's IPN service. I understand the basics of it, but I am not quite sure how to implement it, nor do I understand how I can trigger the script to update the database for the correct user. I would imagine that to do this, I need to include some means of user identification whenever they begin the payment process, but I am not sure how to do that either. I am trying to implement this in PHP.
The process would be:
The user has an ID
When he pays, you attach this ID as the custom parameter in the PayPal request
You also define what url you want to call for the IPN
Once the payment is complete, PayPal sends the IPN
You verify that the actual status of the payment is "Completed"
You retrieve the user'ID from the custom parameter
You update your table
I hope it's clear :)
I have already done a small e-commerce with Paypal and it works, but I feel like it is done wrongly.
Because the page that handles the IPN response from Paypal can't read $_SESSION variables, before the user submits the form and is redirected to Paypal, I get all the cart items and store them in a table in the database and also I register a new order with the user information but with the status 0 ( not completed ).
Then, after the user pays and I get the IPN response, I check if the status is completed, check if the amount paid is correct, currency and the usual checks to make sure the payment is successful.
The problem with this approach is that if the user once redirected to Paypal, decide to leave/close the browser/Paypal tab, I will have a failed order registered in the database and I can't delete it but manually.
How can I handle this kind of situation, and is it correct to register the order/cart before the user pays ?
Thank you and sorry for the long post.
If you want to check if the transaction occurs rely on the IPN messages. Depending on which api you are using you have several way to customize the IPN message with useful information for you, ie:
using paypal custom field
define dynamically the IPN url with extra parameter ie www.yoursite.com/ipn?myvar=myval
That way you can have a hook between the payment and the actual user in your application.
Obiusly the php session attributes of the user is not available when the http post comes from paypal.
I've got a question about the PayPal transaction system. I try to implement a paypal shopping cart in my website. But what I want to do is I want to have like "PrePaid credits" on my website. So when the transaction successfully processed. A database value will change given the credits the user wanted to buy.
I dont have a idea on what to search for. I only know standard php. Not any modification such as paypal. So can anyone give me a code/website where I can find some usefull code?
Thank you!
PS: If you have any suggestions on the post to make it even clearer please comment.
You would use the PayPal IPN (Instant Payment Notification), so a user would click 'Purchase x credits' on your site (you would have a custom field with the user's ID, it would then take them to PayPal via custom form you put together, that form has a return URL which after the payment has been successfully made, would return them to that URL, and you would make that success return URL update your database with the details.
So on a successful return from PayPal, your page would update the database with the custom value (User ID) we initially passed in the form along with the amount of credits they purchase (this can be passed via custom value OR you could just use PayPal's callback information returned with the query (it'll be posted to your page from PayPal I believe).
PayPal Sample Code
Getting Started with the PayPal IPN
Nettuts - Using PayPal's Instant Payment Notification
I have site with a members area that I've set up and want to make it so when people register, they need to subscribe to paypal, and only then the user is created in the database.
I don't know much how paypal works. Does anyone have any pointers? How or where do I start?
Basically I need to somehow redirect the visitor to paypal after he presses the "Register" button, make the payment, and then make Paypal return to my site and tell it that the payment was processed, so the user can be created...
Paypal IPN is the Paypal deployment for this kind of requirement.
IPN (Instant Payment Notification) allows you to delegate an endpoint URL that the payment gateway will send postdata to when a payment is completed successfully.
Most of the time this requires utilizing some kind of database to save the registration state while the user is forwarded over to Paypal for the payment process, making use of their SSL encryption and payment logic. When the process is completed, your application is notified with post data containing a unique identitfier generated by your app and passed with the original redirect in order to identify the user's session that has completed payment.
You will want to generate a unique id either using PHP uniqueid() function or by hashing a timestamp. This will be passed along to paypal in your redirect, and paypal will send it along with success/fail flags when the payment is processed. When the user fills out their form and is redirected to Paypal, save a boolean value for IsPaid in your database associated with their ID (i'd recommend using both a primary key as well as this unique transaction id mentioned earlier.) Your IPN script can then listen for the post data, parse it out and change the false IsPaid boolean for that id to true.
There are numerous good tutorials available. I've only used this in MVC deployments, so if you're doing procedural, googling around will help a great deal. Paypal's documentation has the most up to date parameter guides but there are other great, if a bit old, tutorials available independent of them.
http://www.web-development-blog.com/archives/easy-payments-using-paypal-ipn/
http://net.tutsplus.com/tutorials/php/using-paypals-instant-payment-notification-with-php/
Look at the Paypal IPN API, this is used in most paid membership scripts:
https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/library_code
I've implemented a paypal transaction before but this one has a twist that I'm not quite sure what's the best way to handle it.
The basic idea is I want to create an account for the user when he provides some details and makes a payment via PayPal. Until BOTH the user details are filled out correctly AND the payment is made correctly, I shouldn't create an account for the user.
The setup I've done before was simply a paypal button that the user clicks, makes a payment, and gets forwarded back to just a generic page "your order will be processed and shipped" so there was no pre-order form involved.
This one is different though because
before PayPal, I need to collect initial user data
after PayPal, I need to create the new user account and use in it the user data collected from the pre-paypal form
I'm sure there's a logical way to implement this, but I'm not quite sure what's the flow I should follow to do it.
I use the Zend framework by the way, which shouldn't matter but just in case Zend has an easier way to help me with what I'm trying to do.
I do the following (though I do this in ASP.NET):
User fills out form
Info is saved in Order table in db with a unique invoice number
Invoice number is passed to PayPal, along with the IPN Notify URL, when you do the redirect
User is sent to Paypal to pay and then comes back to a generic Success page
Behind the scenes, Paypal makes a call to the IPN Notify url once processing is complete. This page receives your invoice number which PP returns with its call, and then does the account creation processing for that order after retrieving the details from the db. [This is a page with no UI, since only PP is hitting it.]
An email is sent from that process which notifies the customer that their account has been created and gives them the details.
This is a simplified version of the process, but hits the highlights. You can check out PayPal's page about IPN, and do a search on google for IPN integration with PHP.