this my ipn.php
In my log error file I have reciving this message: Invalid response status: 302
And Im reciving the mail from inside "exception" code, someone know why ? I dont have idea why is failing... Please, I need help!!
Thank you very much
<?php
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');
include '../../modelo.php';
include('ipnlistener.php');
$listener = new IpnListener;
$listener->use_sandbox = true;
$listener->use_ssl = false;
$verified = $listener->processIpn($my_post_data);
try {
// $listener->requirePostMethod();
$verified = $listener->processIpn();
mail('mymail#gmail.com', 'TRY ok', 'ok');
} catch (Exception $e) {
error_log($e->getMessage());
mail('mymail#gmail.com', 'Exception', 'nok');
exit(0);
}
mail('mymail#gmail.com', 'final del script', 'include');
?>
And this is my html code:
<form name="_xclick" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="myemailpaypal#yopmail.com">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="item_name" value="<?php echo $product;?>">
<input type="hidden" name="amount" value="<?php echo $amount;?>">
<input type="hidden" name="return" value="http://www.myweb.com/thankspage.php">
<input type="hidden" name="custom" value="<?php echo $bookcode; ?>">
<input type="hidden" name="notify_url" value="http://www.myweb.com/ipn.php">
<input type="image" src="http://www.paypal.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>
$listener->use_ssl = true;
sandbox needs ssl
Related
I have a subscription based streaming site in which I am trying to implement a trial period of 3 days prior to the user being charged the monthly fee.
THINGS TO KNOW
It works fine before implementing the trial code on the payment page (IE: a user is charged and their subscription automatically begins. Paypal IPN shows response)
I'm pretty sure I need to add variables to the listener but this is where I am having issues.
Providing below the unmodified payment code, unmodified listener code, paypal ipn response from unmodified code, modified payment code, and ipn response when using modified payment code
Some of the info in the code provided has REMOVED to protect information
UNMODIFIED WORKING PAYMENT SCREEN CODE
<!-- Buy button -->
<form action="{{link}}" method="post" id="paypal-form-pay">
<!-- Identify your business so that you can collect the payments -->
<input type="hidden" name="business" value="{{account}}">
<!-- Specify a subscriptions button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Specify details about the subscription that buyers will purchase -->
<input type="hidden" name="item_name" value="{{subscription.pack}}">
<input type="hidden" name="item_number" value="{{id}}">
<input type="hidden" name="currency_code" value="{{subscription.currency}}">
<input type="hidden" name="a3" id="paypalAmt" value="{{subscription.price}}">
<input type="hidden" name="subscription" id="paypalAmt" value="{{subscription.id}}">
<input type="hidden" name="p3" id="paypalValid" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="100">
<input type="hidden" name="sra" value="5">
<input type="hidden" name="cancel_return" value="{{ url('wep_subscription_cancel',{"id":subscription.id})}}">
<input type="hidden" name="return" value="{{ url('wep_subscription_paypal_finish',{"id":subscription.id})}}">
<input type="hidden" name="notify_url" value="{{ url('wep_subscription_notify')}}">
<input class="buy-btn" style="display:none" type="submit" value="Buy Subscription">
</form>
UNMODIFIED WORKING LISTENER CODE
$paypalURL = "https://www.paypal.com/cgi-bin/webscr";
$ch = curl_init($paypalURL);
if ($ch == FALSE) {
return FALSE;
}
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
// Set TCP timeout to 30 seconds
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close', 'User-Agent: company-name'));
$res = curl_exec($ch);
$tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));
if (strcmp($res, "VERIFIED") == 0 || strcasecmp($res, "VERIFIED") == 0) {
$txn_id = !empty($request->get('txn_id'))?$request->get('txn_id'):'';
if(!empty($txn_id)){
$payment_status = !empty($request->get('payment_status'))?$request->get('payment_status'):'';
$currency_code = $request->get('mc_currency');
$payment_gross = !empty($request->get('mc_gross'))?$request->get('mc_gross'):0;
$item_number = $request->get('item_number');
$subscription = $em->getRepository("AppBundle:Subscription")->findOneBy(array("id"=>$item_number,"method"=>"paypal","status"=>"unpaid"));
if (
$payment_status == "Completed" and
$currency_code == $subscription->getCurrency() and
$payment_gross == $subscription->getPrice()
) {
$subscr_id = $request->get('subscr_id');
$payer_email = $request->get('payer_email');
$payer_id = $request->get('payer_id');
$item_name = $request->get('item_name');
$subscription->setEmail($payer_email);
$subscription->setStatus("paid");
$subscription->setTransaction($txn_id);
$started = new \DateTime();
$expired = new \DateTime();
$expired->modify('+'.$subscription->getDuration()." day");
$subscription->setStarted($started);
$subscription->setExpired($expired);
$em->flush();
}
}
}
return new Response("done");
}
public function finishAction(Request $request,$id){
$em=$this->getDoctrine()->getManager();
$subscription = $em->getRepository("AppBundle:Subscription")->findOneBy(array("user"=>$this->getUser(),"id"=>$id));
if ($subscription == null) {
throw new NotFoundHttpException("Page not found");
}
return $this->render('WebBundle:Subscription:finish.html.twig',array("subscription"=>$subscription));
}
public function paypal_finishAction(Request $request,$id){
$em=$this->getDoctrine()->getManager();
$subscription = $em->getRepository("AppBundle:Subscription")->findOneBy(array("user"=>$this->getUser(),"id"=>$id));
if ($subscription == null) {
throw new NotFoundHttpException("Page not found");
}
return $this->render('WebBundle:Subscription:paypal_finish.html.twig',array("subscription"=>$subscription));
}
IPM RESPONSE FOR UNMODIFIED CODE THAT WORKS
mc_gross=0.01&protection_eligibility=Eligible&address_status=confirmed&payer_id=3H4HMXYSVLVWL&address_street=6384 flathead avenue&payment_date=11:26:19 Mar 29, 2021 PDT&payment_status=Completed&charset=windows-1252&address_zip=89122&first_name=Benjamin&mc_fee=0.01&address_country_code=US&address_name=Benjamin Halkum¬ify_version=3.9&subscr_id=I-HY6W0PTGL3NB&payer_status=unverified&business=REMOVED.com&address_country=United States&address_city=Las Vegas&verify_sign=ArlJEh2PTclCmA4aNtb3eN2HF8lEAGBRRl4PvyzHc0gTKjP7ykq8080X&payer_email=REMOVED#gmail.com&txn_id=4W280838190693944&payment_type=instant&last_name=Halkum&address_state=NV&receiver_email=paypal#halkum.com&payment_fee=0.01&receiver_id=NFGUHZAMQSLPS&txn_type=subscr_payment&item_name=Test Only&mc_currency=USD&item_number=314&residence_country=US&receipt_id=0577-5054-4256-1714&transaction_subject=Test Only&payment_gross=0.01&ipn_track_id=79a7131ef33e4
MODIFIED PAYMENT CODE WITH TRIAL
<!-- Buy button -->
<form action="{{link}}" method="post" id="paypal-form-pay">
<!-- Identify your business so that you can collect the payments -->
<input type="hidden" name="business" value="{{account}}">
<!-- Specify a subscriptions button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Specify details about the subscription that buyers will purchase -->
<input type="hidden" name="item_name" value="{{subscription.pack}}">
<input type="hidden" name="item_number" value="{{id}}">
<input type="hidden" name="currency_code" value="{{subscription.currency}}">
<input type="hidden" name="a1" id="paypalAmt" value="0.00">
<input type="hidden" name="subscription" id="paypalAmt" value="{{subscription.id}}">
<input type="hidden" name="p1" id="paypalValid" value="1">
<input type="hidden" name="t1" value="D">
<input type="hidden" name="currency_code" value="{{subscription.currency}}">
<input type="hidden" name="a3" id="paypalAmt" value="{{subscription.price}}">
<input type="hidden" name="subscription" id="paypalAmt" value="{{subscription.id}}">
<input type="hidden" name="p3" id="paypalValid" value="1">
<input type="hidden" name="t3" value="M">
<input type="hidden" name="src" value="100">
<input type="hidden" name="sra" value="5">
<input type="hidden" name="cancel_return" value="{{ url('wep_subscription_cancel',{"id":subscription.id})}}">
<input type="hidden" name="return" value="{{ url('wep_subscription_paypal_finish',{"id":subscription.id})}}">
<input type="hidden" name="notify_url" value="{{ url('wep_subscription_notify')}}">
<input class="buy-btn" style="display:none" type="submit" value="Buy Subscription">
</form>
MODIFIED CODE IPN RESPONSE MESSEGE
amount1=0.00&amount3=6.99&address_status=unconfirmed&subscr_date=11:39:54 Mar 29, 2021 PDT&payer_id=3H4HMXYSVLVWL&address_street=REMOVED&mc_amount1=0.00&mc_amount3=6.99&charset=windows-1252&address_zip=89122&first_name=Benjamin&reattempt=1&address_country_code=US&address_name=Benjamin Halkum¬ify_version=3.9&subscr_id=I-G1VY47ASJ8C4&payer_status=unverified&business=REMOVED.com&address_country=United States&address_city=Las Vegas&verify_sign=AhM9chhyQTrOGTRyOPkwcY26Rcv3AhiXC3kA9XVfl3desynG0cKTMHw4&payer_email=contact#indystars.co&last_name=Halkum&address_state=NV&receiver_email=REMOVED.com&recurring=1&txn_type=subscr_signup&item_name=Monthly*&mc_currency=USD&item_number=318&residence_country=US&period1=1 D&period3=1 M&ipn_track_id=bfcdb7a2bc514
The sample in your "MODIFIED CODE IPN RESPONSE MESSAGE" appears to be what is expected, so this is a matter of updating your listener to handle a different payload when there is a trial period. Among other things, there will be no transaction yet and hence no txn_id, so you will need to write code for the new situation.
I have been on this for a long time now but am unable to figure out the error no matter what I try.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="sales#mysite.co.uk">
<?php
$result = mysqli_query($DB, "SELECT * FROM salestemp WHERE id = '".$_REQUEST['sid'].
"' ") or die("Error: ".mysqli_error($DB));
$counter = 0;
while($row = mysqli_fetch_array($result))
{
$counter++;
?>
<input type="hidden" name="item_name_<?php echo $counter; ?>"
value="<?php echo urlencode($row['name']); ?>">
<input type="hidden" name="ammount_<?php echo $counter; ?>"
value="<?php echo urlencode($row['price']); ?>">
<input type="hidden" name="item_number_<?php echo $counter; ?>"
value="MD<?php echo urlencode($row['pid']); ?>">
<input type="hidden" name="quantity" value="1">
<?php
}
?>
<input type="hidden" name="currency_code" value="GBP">
<!-- Enable override of buyers's address stored with PayPal . -->
<input type="hidden" name="address_override" value="1">
<!-- Set variables that override the address stored with PayPal. -->
<input type="hidden" name="first_name" value="John">
<input type="hidden" name="last_name" value="Doe">
<input type="hidden" name="address1" value="345 Lark Ave">
<input type="hidden" name="city" value="San Jose">
<input type="hidden" name="state" value="CA">
<input type="hidden" name="zip" value="95121">
<input type="hidden" name="country" value="US">
<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">
</form>
When submitting the form I am met with the "Error Detected: Your Cart Is Empty".
Can anyone help me at all please. Thank you very much in advance.
You have 'ammount' instead of 'amount'.
I want to recieve payments from my customers via paypal. And i want to create a system auto confirmation for success/fail payments.
Now i created a function which is below. But when I click to buy button. It redirects to me paypal sanbox page. But i recieve a message like that
Your purchase couldn't be completed
There's a problem with the merchant's PayPal account. Please try again later.
What is the problem ? I'm newbie on Paypal.
public function paypal($products) {
?>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="paymentaction" value="authorization">
<input type="hidden" name="charset" value="utf-8">
<input type="hidden" name="business" value="cihankusmez#facebook.com">
<input type="hidden" name="currency_code" value="TRY">
<input type="hidden" name="return" value="<?php echo BASE_PATH; ?>paypal.php?do=success">
<input type="hidden" name="cancel_return" value="<?php echo BASE_PATH; ?>paypal.php?do=fail">
<input type="hidden" name="first_name" value="John">
<input type="hidden" name="last_name" value="Doe">
<input type="hidden" name="address1" value="9 Elm Street">
<input type="hidden" name="address2" value="Apt 5">
<input type="hidden" name="city" value="Berwyn">
<input type="hidden" name="state" value="PA">
<input type="hidden" name="zip" value="19312">
<input type="hidden" name="night_phone_a" value="610">
<input type="hidden" name="night_phone_b" value="555">
<input type="hidden" name="night_phone_c" value="1234">
<input type="hidden" name="email" value="jdoe#zyzzyu.com">
<input type="hidden" name="address_override" value="1">
<?php foreach ($products['fields'] as $key => $product) { ?>
<?php $i = $key + 1; ?>
<input type="hidden" name="item_name_<?php echo $i ?>" value="<?php echo strip_tags($product['stock_code']." - ".$product['product']); ?>">
<input type="hidden" name="amount_<?php echo $i ?>" value="<?php echo $product['wholesale_price']; ?>">
<input type="hidden" name="discount_rate_<?php echo $i ?>" value="<?php echo $product['discount_ratio'] ?>">
<input type="hidden" name="quantity_<?php echo $i ?>" value="<?php echo $product['total_quantity']; ?>">
<input type="hidden" name="tax_rate_<?php echo $i ?>" value="<?php echo $product['vat'] ?>">
<?php } ?>
<button id="paypal_button" type="submit" name="paypal_button" class="btn btn-success">
<span class="glyphicon glyphicon-shopping-cart"></span> <?php echo _('PAYPAL ile Satın Al'); ?>
</button>
</form>
<?php }
Check your account on PayPal and verify your sandbox account and apps are there.....mine are gone and hence the error.
small problem with this old paypal button code..
I am trying to get the os0 and os1 to POST back with this script.. I am getting the amount and name, but that is all .. ?
Thanks!
I have a Simple form:
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:left; width:49.9%">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" alt="description">
<img alt="description" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
<input type="hidden" name="add" value="1">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="mm#mm.com">
<input type="hidden" name="item_name" value="Digital Image (Download ONLY)">
<input type="hidden" name="amount" value="6.00">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="cancel_return" value="http://www.website.com/store/sorry.php">
<input type="hidden" name="return" value="http://www.website.com/store/thank_you.php">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="bn" value="PP-ShopCartBF"><!--<br />
Phone Number:<input type="text" name="on1" maxlength="60">-->
<table><tr><td><input type="hidden" name="on0" value="Photo ID"></td>
<td><input name="os0" type="hidden" value="{name}" size="40" maxlength="200"></td></tr><tr><td>
<input type="hidden" name="on1" value="Thumbnail preview"></td>
<td><input name="os1" type="hidden" value="{image_url}/{name}" size="40" maxlength="200"></td></tr></table>
</form> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:left; width:49.9%">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="mm#mm.com">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_viewcart_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<input type="hidden" name="display" value="1">
</form>
Once the user buys the product, they auto return w/ PDT enabled and I am trying to get back the variables os0 and os1 -- but nothing is coming back.
I get the amount and the first and last name, but not the option_selection1 or 2 ??
Here is my return script: ( I was trying different variables to see.. but nothing ? )
$firstname = $keyarray['first_name'];
$lastname = $keyarray['last_name'];
$option_name1 = $keyarray['option_name1'];
$option_name2 = $keyarray['option_name2'];
$custom = $keyarray['option_selection1'];
$os1 = $keyarray['os1'];
$option_selection2 = $keyarray['os2'];
$on1 = $keyarray['on1'];
$on2 = $keyarray['on2'];
$os1 = $keyarray['os1'];
$os2 = $keyarray['os2'];
$amount = $keyarray['payment_gross'];
echo ("<p><h3>Thank you for your purchase!</h3></p>");
echo ("<b>Payment Details</b><br>\n");
echo ("<ul><li>Name: $firstname $lastname</li>\n");
echo ("<li>Item: $option_name1</li>\n");
echo ("<li>Item Name: $option_name2</li>\n");
echo ("<li>Item Name 2: $option_selection1</li>\n");
echo ("<li>Item Name 2: $option_selection2</li>\n");
echo ("<li>Item: $custom</li>\n");
echo ("<li>Item: $on1</li>\n");
echo ("<li>Item Name: $on2</li>\n");
echo ("<li>Item Name 2: $os1</li>\n");
echo ("<li>Item Name 2: $os2</li>\n");
echo ("<li>Amount: $amount</li></ul>\n");
echo ("");
}
else if (strcmp ($lines[0], "FAIL") == 0) {
// log for manual investigation
}
Hi did you ever resolve this issue? I have just begun to create a pdt for my website and based on what I have learnt: 'option_name1' will pull the 'on0' label from your form, 'option_name2' will pull the 'on1' label, etc. same with 'option_selection1' (pulls the information entered in the 'os0' text field box) and 'option_selection2'.
So far I've only tried it in the sandbox environment, but I've found https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_IPNandPDTVariables to be useful.
I want to send multiple item names and item prices to PayPal but I am unable to post my item name and price with below code can you please help me?
<form method="post" name="cart" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="navive_1295939206_biz#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="notify_url" value="http://newzonemedia.com/henry/ipn.php" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="return" value="http://www.example.com/thank_you_kindly.html" />
<?php
//select items for table
$srowcart_dtl = mysql_num_rows($srscart_dtl);
if($srowcart_dtl > 0) {
$cnt=1;
while($srscart_dtl1 = mysql_fetch_assoc($srscart_dtl)) {
?>
<input type="hidden" name="item_name[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iname']; ?>">
<input type="hidden" name="amount[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iprc']; ?>">
<?php
$cnt++;
}
}
?>
<input type="image" src="https://www.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.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Create your code like this:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart"> <!-- change _xclick to _cart -->
<input type="hidden" name="upload" value="1"> <!-- add this line in your code -->
<input type="hidden" name="business" value="your_seller_account">
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="1.00">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="2.00">
<input type="submit" value="PayPal">
</form>
In addition to the changes suggested by devilprince, the underscores are missing from the line item input tags' name attributes, and also the tags are not proper self-closing tags because the closing / is missing. Correct like so:
<form method="post" name="cart" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="navive_1295939206_biz#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="notify_url" value="http://newzonemedia.com/henry/ipn.php" />
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="hidden" name="return" value="http://www.mysite.org/thank_you_kindly.html" />
<?php
// select items for table
$srowcart_dtl = mysql_num_rows($srscart_dtl);
if($srowcart_dtl > 0)
{
$cnt=1;
while($srscart_dtl1 = mysql_fetch_assoc($srscart_dtl))
{
?>
<input type="hidden" name="item_name_[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iname']; ?>"/>
<input type="hidden" name="amount_[<?php echo $cnt ?>]" value="<?php echo $srscart_dtl1['cart_iprc']; ?>"/>
<?php
$cnt++;
}
}
?>
<input type="image" src="https://www.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.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
(You may also want to escape special characters in the value attribute, at least for the " character in case it shows up in your item name data.)
Just had to figure this out today for a client. Besides item_name_N and amount_N I also used quantity_N, tax_N, and shipping_N (where N is the line item number, starting with 1).
This page has a list of all parameters: PayPal HTML Form Variables, but the question & answers given here are a better real-world example than the trivial examples on the PayPal site.