Custom paypal payment form - php

What I want to do is to store payments via paypal in MySQL database using php. But there are always chances of fail. I mean if customer enters amount and press "pay now" it doesn't mean that customer successfully paid this amount. Customer may simply exit or fail.
This code below is customizable and works like a charm, but there is a problem. The thing is, I can't set callback url with custom variables in following form to get success or fail and store this transaction in my own database.
Any suggestions?
<form name="_xclick" action="https://www.paypal.com/us/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="me#mybusiness.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Teddy Bear">
<input type="hidden" name="amount" value="12.99">
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

Related

How to switch PayPal sandbox account to live account in PHP

Hi guys hope you are all safe. i just want to know that how can i switch sandbox account to live account.
First i was using https://www.sandbox.paypal.com/cgi-bin/webscr in paypal form action but when i go to live i changed it into https://www.paypal.com/cgi-bin/webscr
i also changed the business attribute in form to Paypal live business account.
right now PayPal is accepting the payment which is coming from website but when it redirects to my website paypal_success(page after payment success) page i cant able to get return values from Paypal like transaction id, item value, item name etc.
Can you please help me. here is my code.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top" class="float-right w_100">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="business#awakeningsme.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Awakenings Products">
<input type="hidden" name="item_number" value="<?php echo $pro_id ?>">
<input type="hidden" name="amount" value="<?php echo $total; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://mywebsite.com/paypal_success.php">
<input type="hidden" name="cancel_return" value="http://mywebsite.com/paypal_cancel.php">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/buy-logo-large.png" alt="Buy now with PayPal" border="0" name="submit">
</form>
A more important issue is that PDT should never be used for anything important. It is for informational purposes only (e.g. to show a success page to the buyer)
If you depend on the information from PDT to trigger business logic like updating order records, you are going to have a bad time. After a successful Payments Standard payment, the customer may never return.
Their browser may crash, or they may be shown a receipt at PayPal and need to click a button to return, and so just close the window.
If you need reliable notifications of payment completion, your options are:
Implement a separate asynchronous service, such as Webhooks or IPN.
Switch to an API-based integration that is notified synchronously when the capture is successful, such as a server-side integration of v2/orders with Smart Payment Buttons (front-end code: https://developer.paypal.com/demo/checkout/#/pattern/server ). This way, the capture happens on your server, and you have an immediate API notification of success/failure

Upload file to be bought with paypal

I am using an html form to create a buy now button on a webpage. I would like the buy now button to lead to a paypal page which the user can enter their information. If the information is validated, the user should be able to download the file they requested to buy. The button is working and the price is being set correctly but I am not sure how to upload the file to paypal so it can be downloaded directly once the payment is processed.
Here is the code for the current html form i am using:
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post" class="paypal">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="$bandEmail">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="item_name" value="$song1Name">
<input type="hidden" name="amount" value="$song1Price">
<input type="image" src="http://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

Paypal return with produt id array

I am using paypal payment gateway with my website for payment.
Here I want a feature like where I could send list of product id those I want to purchase.
And after successful payment I want to these all id so that I could update my datasbe.
I can not use IPN, because its already used for other site.
Below is my html form for paypal..
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="praveend06-facilitator#gmail.com">
<input type="hidden" name="item_name" value="PAYMENT REASON">
<input type="hidden" name="amount" value="10">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="MX">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="notify_url" value="http://localhost/paypal/notify.php">
<input type="hidden" name="return" value="http://localhost/paypal/success.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value="http://localhost/paypal/fail.php">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
I wrote below code in success.php
but its returning blank array. Even i didn't get transaction id.
Please help me to achieve this. Thank you
There is only one parameter that you can use for custom data with Website Payments Standard and that's "custom".
Simply pass in you custom data in
<input type="hidden" name="custom" value="your custom data here">
In the custom data, first add the product IDs as a comma separated string and then you will get that back on successful payment.
You can retrieve the value for 'custom' by polling through PayPal PDT (https://www.paypal.com/pdt/) or getting the data POST'ed to you by PayPal, using PayPal IPN (https://www.paypal.com/ipn/).
But you already mentioned that you cannot use IPN. So go for PDT instead.
PDT is NOT the recommended way to update your database. Even with Auto-Return enabled there is no guarantee the user would make it back to your site. In these cases the return page would never be reached and that code would never run, leaving your database without the updates it needs.
You CAN use IPN with multiple PayPal accounts. You just need to use the notify_url parameter to specify the unique URL you want to use for IPN on that particular checkout.
On that note I see you're already including the notify_url parameter in your code here, but you're using localhost for it. That won't work because it will be PayPal's server sending data to that URL. As such, "localhost" is their own server at that point.
What you need to do for testing purposes is use your public IP address or setup a domain to resolve to your IP address so you can use that as your IPN URL instead of localhost.
So then, again, you can use as many different IPN URL's with a single account as you need to. Just set notify_url to whichever one you need to use based on the checkout that you're setting up.

Paypal Subscription check with PHP for non hosted button

I am having a peculiar problem implementing recurring payment for a webapp that I am developing. I could not use a hosted paypal subscription button, because the payment sum would be variable. So, I used a non hosted solution something like this :
<form action="https://www.sandbox.paypal.com/us/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="business#email.com">
<input type="hidden" name="item_name" value="Some item"/>
<input type="hidden" name="return" value="return_url">
<input type="hidden" name="cancel_return" value="cancel_url">
<input type="hidden" name="notify_url" value="notification_url">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="1">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="a3" value="variable_amount">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="src" value="1">
<input type="hidden" name="sra" value="1">
<input type="hidden" name="custom" value="planid1,planid2"/>
</form>
Now, I need to check every month using a cron that who has paid, and generate content according to that.
From the discussions all over the internet, it is clear that paypal doesn't send txn_id for the subscription. So, how am I supposed to check if user has paid in the next month or not?
One thing that comes to my mind is an IPN listener, but will that work with a non-hosted button? Totally confused with this. Could someone point me to the right direction?
IPN would be the way to go. With IPN, your system would be notified when the profile is created, when the profile bills the user again, when the profile is canceld, or when it fails to bill. You would also get the transaction id back in the IPN each thim the profile is charged.

paypal buy now button with redirection after success

I am creating a website where there will be a lot of digital products with variety of product prices. I went to paypal and created a button.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="W6HILXXVHKYZBY">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
They price is predefined when creating the button. And also I want the users to be redirected to a success in my website after the payment is complete. The above code works in live environment but in sandbox it gives error. PLUS it is not what I require.
I want something like this
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="accounts#mydomain.com">
<strong>How much do you want to pay?</strong><br />
$ <input type="text" name="amount" value="30" readonly="readonly">
<input type="hidden" name="no_shipping" value="0">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="AU">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="http://net.mydomain.com/payment-complete/">
<br /><br />
<input type="submit" value="Pay with PayPal!">
</form>
Everything in this code works, but it wont redirect to my success page automatically.
There are some conditions for it to work correctly. you can read them here on the PayPal Developers website.
Here is the Note from PayPal about Auto Return:
If you have turned on Auto Return and have chosen to turn on PayPal Account Optional for new users, a new user will not be automatically directed back to your website, but will be given the option to return.
The Return URL will be applied to all of your Auto Return payments unless otherwise specified within the button or link for that Website Payment. You may specify a different Return URL by changing it in your profile settings; otherwise, you may add or edit the HTML (variable: return) associated with a button or link. In this case, the Return URL that is associated with the button or link will override what was specified in the profile settings.
Firstly, your live account credentials are different from sandbox credentials. Check that you are using the right account email.
Secondly, as Prakash-GPz said, you should enable auto return in your sandbox account also in order to be redirected to success page.

Categories