PayPal Payment Request Notice: Undefined index - php

I am using the following code to integrate PayPal Payment System to my website and after the payment I am getting the following Notices and "Payment Failed" even when everything went smooth.
Notice: Undefined index: item_name in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 2
Notice: Undefined index: tx in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 3
Notice: Undefined index: amount in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 4
Notice: Undefined index: currency_code in /Applications/XAMPP/xamppfiles/htdocs/payment/success.php on line 5
Payment Failed
I am using the following code to create the payment button
<div class="btn">
<form action="<?php echo $paypal_url ?>" method="post" name="frmPayPal1">
<input type="hidden" name="business" value="<?php echo $paypal_id ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="20Percents (12 Credits)">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="credits" value="12">
<input type="hidden" name="userid" value="1">
<input type="hidden" name="amount" value="10">
<input type="hidden" name="cpp_header_image" value="http://20percents.com/wp-content/uploads/2014/06/logo-1.png">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="handling" value="0">
<input type="hidden" name="cancel_return" value="http://localhost/payment/cancel.php">
<input type="hidden" name="return" value="http://localhost/payment/success.php">
<input type="image" src="https://www.sandbox.paypal.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.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
And, the following code to verify the payment:
<?php
$item_name = $_GET['item_name']; // I also tried $_REQUEST['item_name']; instead
$item_transaction = $_GET['tx']; // Paypal transaction ID
$item_price = $_GET['amount']; // Paypal received amount
$item_currency = $_GET['currency_code']; // Paypal received currency type
$price = '10.00';
$currency='USD';
//Rechecking the product price and currency details
if($item_price==$price && $item_currency==$currency)
{
$content = "<h1>Welcome, Guest</h1>";
$content .= "<h1>Payment Successful</h1>";
}
else
{
$content = "<h1>Payment Failed</h1>";
}
?>
I don't know why I am receiving these notices, any help is highly appreciated. Thanks

The method you gave in form is POST. But getting values using $_GET[].
Change form to
<form action="<?php echo $paypal_url ?>" method="get" name="frmPayPal1">
or change
$item_name = $_GET['item_name'];
to
$item_name = $_POST['item_name'];

Follow these steps to configure your account for PDT:
Log in to your PayPal account.
Click the Profile subtab.
Click Website Payment Preferences in the Seller Preferences column.
Under Auto Return for Website Payments, click the On radio button.
For the Return URL, enter the URL on your site that will receive the transaction ID posted by PayPal after a customer payment.
Under Payment Data Transfer, click the On radio button.
Click Save.
Click Website Payment Preferences in the Seller Preferences column.
Scroll down to the Payment Data Transfer section of the page to view your PDT identity token.

I know this is old, but these parameters worked for me with $_POST method. I added them to my ipn.php file
$item_transaction = $_POST['txn_id'];
$item_price = $_POST['mc_gross'];
$item_currency = $_POST['mc_currency'];

Related

PHP Paypal express 10413

I'm using Paypal Express Checkout on my website and i receive this error:
SetExpressCheckout API call failed. Detailed Error Message: The totals of the cart item amounts do not match order amounts.Short Error Message: Transaction refused because of an invalid argument. See additional error messages for details.Error Code: 10413Error Severity Code: Error
When i enter a quantity of 1 everything is working fine but when i enter 2 or more i get the error.
I'm using SMARTY Templating.
<form class="pull-right" action="../Checkout/paypal_ec_redirect.php" method="POST">
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME0" value="{$product_naam}"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT0" value="{$product_productprijs}"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY0" value="{$product_aantal}"></input>
<input type="hidden" name="PAYMENTREQUEST_0_ITEMAMT" value="{$product_subtotaal}"></input>
<input type="hidden" name="PAYMENTREQUEST_0_TAXAMT" value="{$product_btw}"></input>
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="{$product_totaalprijs}"></input>
<input type="hidden" name="currencyCodeType" value="EUR"></input>
<input type="hidden" name="paymentType" value="Sale"></input>
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png" alt="Check out with PayPal"></input>
</form>
</div>
</div>
</div>
Here is the PHP:
foreach ($getproduct as $row) {
$productaantal = $aantalbesteld;
$productnaam = $row['naam'];
$productprijs = $row['prijs'];
$btwtarief = $row['btw_tarief'];
$btwbedrag = ($productprijs*$aantalbesteld)/100*$btwtarief;
$subtotaal = ($productprijs*$aantalbesteld)-$btwbedrag;
$totaalprijs = $productprijs*$aantalbesteld;
}
//Product
$smarty->assign('product_naam', $productnaam);
$smarty->assign('product_aantal', $productaantal);
$smarty->assign('product_prijs', money_format('%.2n', $productprijs));
$smarty->assign('product_subtotaal', money_format('%.2n', $subtotaal));
$smarty->assign('product_btw', money_format('%.2n', $btwbedrag));
$smarty->assign('product_totaalprijs', money_format('%.2n', $totaalprijs));
$smarty->assign('product_bestelknop', 'Bestellen');
EDIT: Even this isn't working:
<form class="pull-right" action="../Checkout/paypal_ec_redirect.php" method="POST">
<input type="hidden" name="L_PAYMENTREQUEST_0_NAME0" value="{$product_naam}"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_AMT0" value="5.00"></input>
<input type="hidden" name="L_PAYMENTREQUEST_0_QTY0" value="2"></input>
<input type="hidden" name="PAYMENTREQUEST_0_ITEMAMT" value="10.00"></input>
<input type="hidden" name="PAYMENTREQUEST_0_TAXAMT" value="2.10"></input>
<input type="hidden" name="PAYMENTREQUEST_0_AMT" value="12.10"></input>
<input type="hidden" name="currencyCodeType" value="EUR"></input>
<input type="hidden" name="paymentType" value="Sale"></input>
<input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-large.png" alt="Check out with PayPal"></input>
</form>
It says when they multiply quantity and amount it doesn't add up to what you specify as totalamount
$btwbedrag = ($productprijs*$aantalbesteld)/100*$btwtarief;
$subtotaal = ($productprijs*$aantalbesteld)-$btwbedrag;
$totaalprijs = $productprijs*$aantalbesteld;
Your VAT is calculated by taking 1% of the total price amount multiply by VAT rate. This assumes your product amounts are exclusive VAT.
Then in the next line you remove VAT from $subtotaal, why? It wasn't included in the first place. Or if it was then you should divide by 121 instead of 100.
$totaalprijs seems to be calculated assuming VAT is included already.
Did you check the values of your hidden fields in the source of your page?
When I changed the qty to 2, this is the request that is sent to PayPal.
paymentrequest_0_currencycode "EUR"
paymentrequest_0_amt "89.90"
paymentrequest_0_itemamt "71.02"
paymentrequest_0_taxamt "18.88"
paymentrequest_0_paymentaction "Sale"
paymentrequest_0_name "Sweaters van Superdry"
paymentrequest_0_qty "2"
Ideally, the request should be like this:
paymentrequest_0_itemamt=71.02
paymentrequest_0_taxamt=18.88
paymentrequest_0_amt=89.90
L_PAYMENTREQUEST_0_NAME0 = Sweaters van Superdry
L_PAYMENTREQUEST_0_AMT0= 35.51
L_PAYMENTREQUEST_0_QTY0= 2
This is causing the problem.
There is no paymentrequest_0_qty parameter.
You can test it here :
https://api-3t.sandbox.paypal.com/nvp?&user=us-30_api1.cri.com&pwd=EYFNSNUSV85CT34Z&signature=AH57zE.nAaElaFFAysViNA9TIte1AxtSpBjx2HLqHJOiu2js3l1Kd48i&version=70.0&METHOD=SetExpressCheckout&RETURNURL=http://www.paypal.com/test.php&CANCELURL=http://www.paypal.com/test.php&PAYMENTACTION=Sale&paymentrequest_0_itemamt=71.02&paymentrequest_0_taxamt=18.88&paymentrequest_0_amt=89.90&L_PAYMENTREQUEST_0_NAME0=Sweateranuperdry&L_PAYMENTREQUEST_0_AMT0=35.51&L_PAYMENTREQUEST_0_QTY0=2
Just click/copy-pasate the link above and see the reponse

Paypal return a variable issue

I'm have an issue with Paypal, i'm using a simple form :
<html>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="boukhersya#gmail.com">
<input type="hidden" name="item_name" value="DEMANDE D ETUDE PERSONNALISEE">
<input type='hidden' name='rm' value='2'>
<input type="hidden" name="amount" id=val value="79">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="notify_url" value= "http://<?php echo $_SERVER['SERVER_NAME'];?>/etude-gratuite.php" >
<input type="hidden" name="cancel_return" value="http://<?php echo $_SERVER['SERVER_NAME'];?>/etude-personalisee/test.php">
<input type="hidden" name="return" value="http://<?php echo $_SERVER['SERVER_NAME'];?>/etude-personalisee/paimentconfirme.php">
<input type="submit" value="Payer votre commande">
</form>
I want to return the email used in the payment, so i can know which user has paid
so i can get the email in the page test.php, can i do that with PDT ??
You can pass the field "custom" to pyapal and it will pass it back to you when the transaction is completed. You may want to use your user ID rather than an email address though.
<input type="hidden" name="custom" value="email#address.com">
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
The way it works is: you use these hidden input values on for your paypal button. When the user is transferred to paypal all of these values are sent with it. One of the values you use is name="notify_url" when the user completes checkout paypal posts the checkout information to that url. In the case of php you do something like this:
$useremail = $_POST['custom']
Any custom information you want to have returned to you needs to go in the custom field. I use some kind of delimiter if I want more pieces of information returned, like this:
<input type="hidden" name="custom" value="user#email.com-firstname-userID">
Then you just explode the data:
$paypalvars = explode("-", $_POST['custom']);
$email = $paypalvars[0];
$firstName = $paypalvars[1];
$userID = $paypalvars[2];
Whatever value is in the custom filed will be posted back to your notify_url exactly the same way you give it to paypal.
You could use the Paypal IPN API to handle this.
Simply set up IPN within your Paypal account and then create a file which will manage the data that gets sent back upon payment.
This includes their email address too!
Note that the <input type="hidden" name="notify_url"> should be the input used to direct to test.php because at the moment, the information that will get passed back to you will be sent to the etude-gratuite.php

PayPal and User payment system

I'm playing around with some eCommerce stuff with PayPal Sandbox. So far this is how the application flows:
User logs in, server stores user_id in a session from the database. User can then click a buy now button once logged in. Takes them to paypal, they login and do payment, and IPN receives the notification fine :)
The only thing I now want to do to extend it, is create away of the IPN receiving the users_id back so I can set a flag on their database entry. Can this be done in PayPal?
I have tried the following with the view:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="--ID-FROM-PAYPAL--">
<input type="hidden" name="user_id" value="<?php echo $user_id;?>">
<input type="image" src="https://www.sandbox.paypal.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.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Thanks for the help :)
<input type="hidden" name="custom" id="custom" value="<?php echo $user_id;?>"/>
Your IPN will receive the userID in the $_POST['custom'] variable.
If you want to pass more than one value to Paypal and back to your IPN:
<script type="text/javascript">
// using prototype
function checkCustom(){
var custom1 = $F('custom1');
var custom2 = $F('custom2');
$('custom').value = '{"userID":"'+ custom1 +'","publicDonation":"'+ custom2 +'"}';
}
</script>
<input type="hidden" name="custom1" id="custom1" value="<?php echo $user_id;?>"/>
<input type="hidden" name="custom2" id="custom2" value="<?php echo $user_email;?>"/>
For further information check the paypal IPN:
custom
Custom value as passed by you, the merchant. These are pass-through
variables that are never presented to your customer Length: 255
characters
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables#id091EAB0105Z

How to create an PayPal button with overwritable variables

Hello I would like to create a paypal buy button which has a dynamic set amount.
I would like to pass the amount by a text input field within the form and the item_number by a hidden field.
The issue is that what ever I do I get a encrypted s-xclick button from the paypal website.
This button does not allow hidden variables being placed in the form.
I think what I need is a xclick button. My goal is to allow users to increase their internally credit of my website.
EDIT (moving the addition to the question from the answer to the question)(from here #tokam:
To add this to the discussion I would like to show my current solution for the problem:
Here we have some Javascript validation which helps the user with the input. Recognize that it opens a lightbox on success
function validatePaypalForm()
{
var val = $('#paypalPaymentAmount').val().replace(/\s*$/, "").replace(/,/ , ".").replace(/€$/, "");
var errormsg = '';
var ret, amountField;
if( val==='' || isNaN( parseFloat(val) ) || !isFinite(val) )
{
errormsg = 'Bitte geben Sie einen gültigen Betrag an';
}else if( parseFloat( val ) < <?php echo $this->minimum?> )
{
errormsg = 'Das Einzahlungsminimum beträgt <?php echo $this->minimum?>€';
}
ret = ( errormsg === '' );
amountField = $( '#paypalAmountField' );
if( ret )
{
amountField.removeClass( 'error' );
$('#paypalAmountErrorMessage').html( ' ' );
$('#paypalPaymentAmount').val( val );
fb.start(
'<p><strong>Sie werden in kürze zur Seite von Paypal weitergeleitet.</strong></p>',
'width:700 showPrint:false modal:true showClose:false showOuterClose:true showItemNumber:false closeOnNewWindow:false outsideClickCloses:true innerBorder:0 imageClickCloses:false scrolling: no'
);
}else{
amountField.addClass( 'error' );
$('#paypalAmountErrorMessage').html( errormsg );
}
return ret;
}
Here comes my button now. The issues I am having with are e.g. that it is easy for the user to set an other currency code. I could handle this in my IPN Listener by refunding the payment. Are there other issues which come with an unencrypted changeable button?
<form onsubmit="return validatePaypalForm();" class="stn-form" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<fieldset id="fieldset-p"><legend><span>2.</span>myproject Guthaben aufladen per Paypal Zahlung</legend>
<div id='paypalAmountField' class="field">
<label for='paypalPaymentAmount' >Betrag €:</label>
<input id='paypalPaymentAmount' type="text" name='amount' value='' />
<span style='display:block;' id='paypalAmountErrorMessage' class='errorText'>' </span>
</div>
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="THE_ID_OF_MY_CLIENT">
<input type="hidden" name="lc" value="DE">
<input type="hidden" name="item_name" value="myproject Advertiser Vorkasse">
<input type="hidden" name='item_number' value="11500">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_paynowCC_LG.gif:NonHosted">
<input type="hidden" name="rm" value="1">
<input type="hidden" name='cbt' value="Zu myproject.de zurückkehren">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="return" value="http://myproject.somedomain.net/advertiser/guthaben-aufladen/ret/success" />
<input type="hidden" name="cancel_ return" value="http://myproject.somedomain.net/advertiser/guthaben-aufladen/ret/canceled" />
<div class="actionrow">
<input type="image" src="https://www.paypalobjects.com/de_DE/DE/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="Jetzt einfach, schnell und sicher online bezahlen – mit PayPal.">
<img alt="" border="0" src="https://www.paypalobjects.com/de_DE/i/scr/pixel.gif" width="1" height="1">
</div>
</fieldset>
</form>
The reason you can't override the amount dynamically, is because you have a so-called 'PayPal hosted button'.
With a hosted button, the amount is stored on PayPal's side and can't be overwritten with the 'amount' variable.
You'll either want to use a non-hosted button, or use the BMUpdateButton API call to dynamically update the button's amount.
To use a non-hosted button, simply find 'Step 2' in the button creation tool and untick 'Host button with PayPal'.
Option 2:
Still use the hosted button, and use the BMUpdateButton API to update the amount. An example request for BMUpdateButton would look as follows:
USER=Your API username
PWD=Your API password
SIGNATURE=Your API signature
VERSION=82.0
HOSTEDUBTTONID=The value of <input type="hidden" name="hosted_button_id" value="">
BUTTONTYPE=The type of button. E.g. BUYNOW
BUTTONCODE=The type of code you want to get back. E.g. HOSTED
L_BUTTONVAR0=amount=The new amount with a period as separator
L_BUTTONVAR1=item_name=Optional: a new item name if you wish
Similary, you could also use the BMCreateButton API to create a new button, or use the BMButtonSearch API to search through a list of all your stored hosted buttons (to find the hosted_button_id of your button automatically, for example)
The reason to use a hosted button is because it's more secure. A non-hosted, unencrypted button would basically leave the amounts open to manipulation. Fraudulent transactions waiting to happen.
you shouldn't use xclick which isn't encrypted . the way I solved this is using paypal button api - with some kind of caching in the client so you won't do the whole http request response every time.
note that paypal uses 2 types of api - the NVP which is sort of restful (also not really) and SOAP (I used the NVP method)
you could also generate the the encrypted button in your server using openssl - but I run into unsolvable problems with this method and couldn't get any help for that either here or in paypal horrible developer forums
edit: the problem with not encrypted buttons are that anyone using firebug (not talking about more advanced tools) could interecept a payment and change the cost etc'..
If you insist in that direction you could follow the simple html form from paypal to create this button. you do it in paypal site and create an unencrypted button and then just edit the html and change the needed field to <?php $variable?>. I would strongly advice against this path.
I think this might work for you if you update ... "you#yoursite.com" ... it's non encrypted and still seems to host on paypal's site for clearing
drop the: value="my_default_price"
if you want the user to enter it into a blank text box ... for my page, prices are tied to the price of gold, so I have to dynamically update the variable "amount" and i just leave off value=
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you#yoursite.com">
<input type="hidden" name="item_name" value="example description">
<input type="hidden" name="item_number" value="">
<input type="text" name="amount" value="my_default_price">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="return" value="http://www.yoursite.com/returnpage.php">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but02.gif" border="0" name="submit" alt="Make your payments with PayPal. It is free, secure, effective.">
<img alt="" border="0" src="https://www.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>

paypal and Php?

I have two ways to check from user:
1.if user input (Amount field < 5(user credit):
do update database the remain amount in my database table.
2.if user input(Amount field) > 5(user credit):
Do paypal transaction with the submit form.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">
<input type="hidden" name="item_number" value="01 - General Payment to FreelanceSwitch.com">
<input name="item_name" type="hidden" id="item_name" size="45" value="Posting job">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="business" value="seller_1265789181_biz#xxx.xxx.xx">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://freelanceswitch.com/payment-complete/">
Paying Page:<input name="amount" type="text" id="amount" size="5">
<input type="submit" name="Submit" value="Pay">
</form>
Anybody could tell me how to do with the paypal submit form with the conditions.?
thanks.
Thanks #Donny Kurnia ,now I have tried:
EDIT::
function compare_user_credit($paying_price, $user_credit){
$db = &JFactory::getDBO();
$user =& JFactory::getUser();
$user_id = $user->get('id');
if ($paying_price <= $user_credit) {
$remain_credit = $user_credit - $paying_price;
//DO UPDATE:enough credit
update_user_credit_after_paying($remain_credit,$user_id);
$action_after_paying = header("Location: index.php?xxxx=5");
}
# Case2 direct to paypal with the submit form.
else if ($paying_price > $user_credit){
//Need submit form to paypal.
$action_after_paying = header("Location: index.php=xxxx&paypal=".$_POST["amount"]);
}
return $action_after_paying;
}
$output = '<form method="POST" > ';
$output .='<h1>Credit:'.get_credit().'</h1>';
$output .= ' Paying Page <input type="text" name="amount" size=3 max_length=5 />';
$output .='<input type="submit" name="pay" value="pay" />' ;
echo $output;
if(isset($_POST["pay"])){
compare_user_credit($_POST["amount"], $user_credit);
}
HOw Could I do with Paypal in Case 02.(direct to paypal with submit form.)
Maybe you can receive the form submit to your own code and then check it's value. If it satisfy the first condition, do the database update. If it satisfy the second condition, redirect the user to a page that have hidden form that will submit to paypal. You can populate the data in this hidden form using data from database or previous form input, and put a javascript code so the form will automatically submitted when the page is loaded.
In my code, I use Micah Carrick's Paypal IPN class to send data to paypal. The class have a sample code on how to display the hidden form, with a submit button in case the javascript is disabled.

Categories