PHP:How to add credit card method option in paypal? - php

I have been working on paypal integration gateway in php. I have taken some tutorials from google. Now I want to add some credit card option via paypal like (visa, mastercard etc). Kindly guide me that how to add this functionality in php
Here is simple html form
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="businesstest541#shop.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Hot Sauce-12oz Bottle">
<input type="hidden" name="amount" value="5.95">
<input type="hidden" name="currency_code" value="USD">
<!-- Display the payment button. -->
<input type="image" name="submit" border="0"
src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1"
src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>

To process cards on your own site, you'd need to use one of the Pro or Braintree options listed here.

Related

Paypal Button Not Working - We are sorry error

I am trying to integrate PayPal to my website. My requirement is that I want to pass a computer generated amount to PayPal to make payment of that amount.
But when I make payment using button , I am taken to website for payment, Where I login using sandbox account and make payment. But when I make payment I get a message saying
We’re sorry Things don’t appear to be working at the moment.
I searched about the possible problem's from similar questions asked and implemented the suggested fix's which is Hosting a button in a server and providing different parameters , But no luck. Here's the code I am using
<form
action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="**********#gmail.com">
<!-- Specify a Buy Now button. -->
<input type="hidden" name="cmd" value="_xclick">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Product1">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="10.00">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="rm" value="2" />
<!--in custom field add user id-->
<input type="hidden" name="custom" value="102">
<!-- Specify URLs -->
<input type='hidden' name='cancel_return' value='http://www.shreyash.tech'>
<input type='hidden' name='return' value='http://www.google.co.in'>
<input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
<img alt="" border="0" width="1" height="1" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" >
</form>
I have no idea what I am doing wrong here.
It looks the issue with your sandbox account. Would you please create your new sandbox seller and buyer test accounts and try again.
Here is the link for your reference to create PayPal sandbox account.

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.

PayPal simple upload cart using one button - why is shopping cart empty?

I'm trying to upload a cart with the following code, but when the user hits the "buy now" button, then instead of showing PayPal's order summary page where the user can sign in to pay, I get an error that says Your shopping cart is empty.
This is my code, what's wrong with it?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<a href='cart.php?type=current' class='buttonlink previous'>Edit Order</a> <a href='checkout4_confirm.php' class='buttonlink next'>Submit Order</a>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="hosted_button_id" value="JRECLRTYAJDKY">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="XXX#XXX.XXX">
<input type="hidden" name="item_name_1" value="<?php echo $order_number; ?>">
<input type="hidden" name="item_number_1" value="1">
<input type="hidden" name="quantity_1" value="1">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.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>
This is most likely being caused by the fact that you are creating a hosted button from your account, but then you are making modifications to the code. If you are going to do this, you need to create a clear text, non hosted button.
When creating the button from within your account, uncheck the option on step 2 to save button at PayPal. Then once the code is generated, click the link to remove code protection. This will create a clear text non hosted button. Then you should be able to modify the button.

Adding item total to PayPal's order summary, for full aggregate cart payment

I've got my own shopping cart and everything set up, I just need a "Pay Now" button for my website users, and I just intend to send the entire cart's total amount up to payPal, that's it, no other integration necessary. So the customers on my website have already reviewed their order, checked quantities and shipping charges etc for individual items, and now PayPal just needs to be given the total amount which they will confirm and pay.
My code for the "Pay Now" button is below ($overall_total has already been calculated somewhere above in my php code):
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="JRECLRTYAJDKY">
<input type="hidden" name="amount" value="<?php echo $overall_total;?>">
<input type="hidden" name="item_total" value="<?php echo $overall_total;?>">
<input type="hidden" name="item_name" value="Your Shopping order">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.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>
The user submits this form when they hit "Pay Now", and they come to next page. But Even though I included the amount and item_total variables, the next page gives me an item_total of 0.00. Also, I don't want any Quantity or Item price to show since I am simply implementing an aggregate cart payment for customers, and they have already reviewed per item charges before coming to the payment. This is what I get:
How can I get rid of Quantity and Item price, and have the $overall_total value that I calculated inside the total price on the PayPal summary?
there is no item_total or any total, since every single button handles ONE item at once
$overall_total must be in the english format with "." as decimals separator
problem may be the cmd parameter.. use instead:
<input type="hidden" name="cmd" value="_xclick">
also you need to specify:
<input type="hidden" name="business" value="yourBusiness#yourBusiness.tld">
look at this for a more complete example:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="yourBusiness#yourBusiness.tld">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="amount" value="10.10">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Item bought desc">
<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_paynow_SM.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.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>
also have a look at:
the documentation of cart parameters: HTML Form Basics for PayPal Payments Standard
the cart button builder: Create a PayPal payment button
about the "quantity" issue, sadly you can't hide it... if this is an important issue for you, you could try instead the ExpressCheckout (using php) which is very customizable and not that difficult to implement
hoping to be helpful
The most straightforward way to get around the Qty:1 issue of simple 'Pay Now' buttons is to implement 'Cart Upload' instead, which is how 99% of shopping carts implement Standard. See: PayPal's Cart Upload Documentation
If you are a programmer who can handle API calls, I instead recommend using Express Checkout (perhaps with SOLUTIONTYPE=Sole) rather than a Standard form post like Cart Upload. EC is a more robust interface to program against and essentially a free upgrade to Standard that's available to all PayPal seller accounts.

PayPal shopping cart button markup error?

I'm getting this error message when testing my Add to Cart functionality using PayPal.
PayPal is very misleading with what fields and values I should be using. For example it says the cmd field should have _cart as value if the button is an Add to Cart, but I've found a working example using -s_xclick (which doesn't work for me).
Here is my markup:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<!-- Specify an Add to Cart button. -->
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<!-- Specify details about the item that buyers will purchase. -->
<input type="hidden" name="item_name" value="Product Two">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="business" value="HY3MQABS97HT">
<span>£200</span><input type="hidden" name="amount" value="200"> <!-- <input type="image" name="submit" border="0"src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif"alt="PayPal - The safer, easier way to pay online"> -->
<input type="image" name="submit" border="0" src="http://www.karenrothwell.com/wp-content/themes/twentyten/images/addToBasketSmall.png" alt="PayPal - The safer, easier way to pay online">
</form>
What am I missing that would cause it not work? All seems in order to me!
The business 'HY3MQABS97HT' is invalid. Is it perhaps for a Sandbox account? Then you'll need to change https://www.paypal.com/cgi-bin/webscr to https://www.sandbox.paypal.com/cgi-bin/webscr
Note: The difference between _cart and _s-xclick is that _cart is used for unencrypted buttons, and _s-xclick is used for 'hosted' buttons (details stored with PayPal).
This works for me: its the same fields that you are using, the difference is i've used my email address for business field replacing yours

Categories