I have two payment methods one is through subscription and another one is single payment.
for single payment: I receive the message payment_status 'completed' to return url then I do the database update.
for subscription : I receive the message txn_type subscr_signup.to return url not subscr_payment.
But I need to immediately tell give the product to the user.
How to know in the success page itself the payment is collected by paypal... for subscription
In short I want to know the payment status.
please help me
for single payment: I receive the message payment_status 'completed' to return url then I do the database update.
That's where I feel you are doing it wrong. You are relying on the buyer to go back to your webpage (in order to do the database update) by clicking on the link at the end of the checkout or by Paypal automatically redirecting to your webpage. What's the problem with that? If the buyer doesn't click the link or wait for the redirect, then they do not go back to the webpage and therefore no database update gets made.
So how can I get the payment information? There is a better (but not 100% reliable) way to do this and that is by using IPN. With both payment methods, you can add a notify_url variable. This is the URL of a listener script to which Paypal will post information about the transaction that is made. So when a buyer makes a payment, your script will be called to make the necessary database update. Just be aware the script has to do certain things in order for Paypal to send you the information. I have used this implementation in the past and it has worked for the most part.
How to know in the success page itself the payment is collected by paypal... for subscription
Above might not answer your original question. From looking at their documentation, you might be able to use return and cancel_return variables in both methods to determine whether the payment was complete or not, respectively.
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 a custom button that is calling paypal, standard checkout method. It's just like this: Passing price variable to PayPal with custom button
If the customer uses a credit card and paypal accept, then paypal redirect to my site and I "mark" the product as paid. But, after a while the bank reject it. How can I get this information? If I'm using standard checkout.
Sounds like you're getting an e-check that hasn't cleared. Then a couple of days later when the payment should clear it fails for some reason.
The best way to handle this is to utilize Instant Payment Notification. Once configured, it will POST transaction data to a listener script that you have setup. This script can receive that data and update your database, send out email notifications, or anything else you want to automate based on different transaction types.
In the case of e-check the IPN data would have a payment_status of Pending, and then when that payment status changes you would get another IPN with the same transaction ID, but the new status. That way you can wait to deliver goods until the payment status of any transaction is actually Completed as opposed to anything else.
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
My sent data to paypal is
"https://www.paypal.com/cgi-bin/webscr/cmd=_cart&upload=1&business=seller.email#something.com¤cy_code=USD&bn=BusinessName&return=http://www.sellersite.com&item_number_1=55&item_name_1=battery&amount_1=55&quantity_1=2&item_number_2=52&item_name_2=bat&amount_2=5&quantity_2=3"
And I want to show those sent data(item number, item name,amount,quantity) and the paypal transaction id to the buyer on "http://www.sellersite.com" after successful payment. (Suppose, the seller has the merchant account with paypal and he would enter that paypal id into database from admin section of the website. So,I would not think about his paypal account settings, my job is just to create the environment for paypal payment for the seller.)
If I write a script like
$T_ID=$_REQUEST['tx']; // or $T_ID=$_GET['tx']; **ref(tx):- "https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_html_paymentdatatransfer"
$item=$_REQUEST['item_number_1']; // or $item=$_GET['item_number_1'];
Then would I get those data from paypal ?
Please tell me.
-Thanks.
It's not going to be quite that simple. You'll need to setup Payment Data Transfer (PDT) in order to get details sent back to your return URL after the buyer completes the payment.
This is useful if you're simply going to display details back to the user, but it's not recommended for updating your own database, sending out email notifications, etc. because there is no guarantee this page will ever be reached so the code won't always run.
For that sort of thing you'll want to use Instant Payment Notification (IPN). This works very similar to PDT except that it will always POST data to your IPN listener on your server regardless of whether or not the user makes it back to your return URL, and it happens outside of your checkout system all together.