Custom Parameter for paypal direct payment rest API - php

I am using paypal REST API for making direct payments.
I want to create internal transaction id before initiating the transaction and use that for identifying the transactions from my end.
I am trying to set id using
$payment = new Payment();
$payment->setId($tId);
Paypal is approving the request and payment is getting done but I am not getting this id in response.
Is there any way by which I can send custom parameters to paypal and get them back in response?

You can use custom variable to pass your custom data, and paypal will return it backto you in post in response.
<input type="hidden" name="amount" value="<?php echo $totalAmount; ?>"/>
<input type="hidden" name="business" value="your_paypal_biz_id"/>
<input type="hidden" name="notify_url" value="<?php echo site_url(); ?>/zad_notify.php"/>
<input type="hidden" name="item_name" value="Image editing"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="return" value="<?php echo $paypalReturnUrl; ?>"/>
<input type="hidden" name="cancel_return" value="<?php echo site_url(); ?>/payment_error.php?id=<?php echo $sr_no; ?>"/>
<input type="hidden" name="custom" value="<?php echo $sr_no; ?>" />
alternatively you can also pass your id in notify url as query string parameter and you will get it back in return url file.
<input type="hidden" name="amount" value="<?php echo $totalAmount; ?>"/>
<input type="hidden" name="business" value="your_paypal_biz_id"/>
<input type="hidden" name="notify_url" value="<?php echo site_url(); ?>/zad_notify.php?id=5"/>
<input type="hidden" name="item_name" value="Image editing"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="return" value="<?php echo $paypalReturnUrl; ?>"/>
<input type="hidden" name="cancel_return" value="<?php echo site_url(); ?>/payment_error.php?id=<?php echo $sr_no; ?>"/>
Hope this help to you, :)

Related

Paypal tax_rate variable is not working

I have integrated Paypal standard payment in my php website now i required to send tax in Paypal payment so i have pass tax_rate variable in paypal form, all are working nice but tax is not send in paypal.
My Paypal form code is below.
<form action="<?php echo PAYPAL_URL;?>" name="paypalForm" method="post">
<input type="hidden" name="business" value="<?php echo PAYPAL_EMAIL;?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" id="item_name" value="<?php echo $mainObj->listing_title;?>">
<input type="hidden" name="item_number" id="item_number" value="<?php echo $booking_id;?>">
<input type="hidden" name="custom" value="<?php echo $mainObj->user_id.'__'.$objExtraPostData->message_to_host.'__'.$objExtraPostData->host_call.'__'.$vat.'__'.$mainObj->pay_price.'__'.$guest_invite_id.'__'.$host_invite_id.'__'.$review_guest_invite_id.'__'.$review_host_invite_id; ?>"/>
<input type="hidden" name="amount" id="amount" value="<?php echo $mainObj->pay_price;?>">
<input type="hidden" name="discount_amount" id="discount_amount" value="<?php echo $discount_price;?>">
<input type="hidden" name="tax_rate" value="<?php echo $vat;?>">
<input type="hidden" name="currency_code" value="<?php echo DEFAULT_PAYMENT_CURRENCY_CODE;?>">
<input type="hidden" name="return" value="<?php echo SITE_MOD."nct-paypal/thankyou.php";?>">
<input type="hidden" name="cancel_return" value="<?php echo SITE_MOD."nct-paypal/failed.php";?>">
<input type="hidden" name="notify_url" value="<?php echo SITE_MOD."nct-paypal/notify.php";?>">
</form>
Check if the tax_rate can be used with your payment type. In addition, it might be better when you set your tax rate in your account profile as described beneath.
Transaction-based tax override variable. Set this variable to a percentage that applies to the amount multiplied by the quantity selected during checkout. This value overrides any tax settings set in your account profile. Allowable values are numbers 0.001 through 100. Valid only for Buy Now and Add to Cart buttons. Default – Profile tax settings, if any, apply.

How can Paypal redirect to my website?

I create a function for admin of my website send money back to users using Paypal. I created a button with Paypal. My problem is: when Admin login Paypal with business account then he send money to personal account, Paypal do not redirect to my website.
Here is my code
<form target="myWindowPayment" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" id="payPalForm">
<input type="hidden" name="item_number" value="<?php echo $idProject ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="business" value="charly#zondertag.net">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="<?php echo base_url() ?>crowdpp/backingProject/3">
<input type="hidden" name="cancel" value="<?php echo base_url() ?>crowdpp/backingProject/3">
<input name="item_name" type="hidden" id="item_name" value="Pledging for <?php echo $result->title ?> project" size="45">
<input name="amount" type="hidden" id="amount" value="<?php echo $pledgeAmount ?>" size="45">
</form>
In payment integration,we get two results.
1.successful payment
2.unsuccessful payment
put success page name in return url if successful payment.put failure page name in cancelurl if unsuccessful payment.example.
$setExpressCheckoutRequestDetails->ReturnURL = "http://localhost:8080/success.php";
$setExpressCheckoutRequestDetails->CancelURL = "http://localhost:8080/cancel.php";
<input type="hidden" name="return_url" value="<?php echo urlencode(base_url().'crowdpp/backingProject/3'); ?>">
<input type="hidden" name="return" value="<?php echo urlencode(base_url().'crowdpp/backingProject/3'); ?>">

custom parameter not getting returned in PAYPAL recursive transaction

Am going to implement the paypal in the form of user subscription...
Bellow code runs fine...
Transaction also works fine...
But am not getting back the 'custom parameters' which i have send(as shown in following code of form)...
<form name="_xclick" id="_xclick" 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="xxx#xxx.com">
<!-- Specify a Subscribe button. -->
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<!-- Identify the subscription. -->
<input type="hidden" name="item_name" value="<?php echo $description; ?>">
<!-- Set the terms of the regular subscription. -->
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a3" value="<?php echo $amount; ?>">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="<?php echo $trial_period; ?>">
<!-- Set recurring payments until canceled. -->
<input type="hidden" name="src" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="notify_url" value="<?php echo $return_domain;?>">
<input type="hidden" name="cancel_return" value="<?php echo $cancel_return;?>">
<input type="hidden" name="return" id="return" value="<?php echo $return_domain;?>" />
<input type="hidden" name="custom" value="<?php echo $serialized_cust_par;?>" />
</form>

Why paypal sandbox not redirecting?

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="POST">
<input type="hidden" name="invoice" id="" value="<?php echo $pay_data['order_id']; ?>" />
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="mymail#gmail.com">
<input type="hidden" name="item_name" value="suite number">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="<?php echo $pay_data['amount']; ?>">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<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="hidden" name="return" value="<?php echo base_url()."/home/paypal_subscripton"; ?>">
<input type="hidden" name="cancel_return" value="<?php echo base_url(); ?>">
<input type="hidden" name="notify_url" value="<?php echo base_url(); ?>" />
<input type="submit" value="Donate!" />
</form>
i payed successfully with this code. but page is not redirecting to my website? what is the problem with my code?
amount: 1
bn: PP-BuyNowBF
business: mymail#gmail.com
cancel_return: http://localhost/ebin/Spacelance/
cmd: _xclick
currency_code: USD
invoice: 50d04dd5ab186
item_name: suite number
item_number: 1
lc: US
no_note: 1
no_shipping: 1
notify_url: http://mydomain/ebin/Spacelance/
return: http://mydomain/ebin/Spacelance/home/paypal_subscripton
this is post params to paypal(from firebug)
If you're using the button as it looks like you are, Paypal only redirects users who have a Paypal account. This is what their documentation says:
Note: 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.
So what I did, was create a page where the I would display instructions to click on the "return to website" link after the transaction is done. Though this is a very inefficient way of taking care of it.
source: www.sandbox.paypal.com/?cmd=p/pop/express_return_learn_more

paypal IPN not sending any notification

I have integrated paypal with my website and but it does take the payment but it doesnot send any IPN to my php file which should update my databse....
there is the code I have been using:
to call
session_start();
if($mode=='live')
{
$url=" https://www.paypal.com/cgi-bin/webscr";
$email="nnnnnnn_singh#live.com";
$_SESSION['url']=$url;
$_SESSION['email']=$email;
$_SESSION['subtotal']=$subtotal;
}
else if($mode=='sandbox')
{
$url= "https://www.sandbox.paypal.com/cgi-bin/webscr";
$email="nnnnnnn_1329707350_biz#gmail.com";
$_SESSION['url']=$url;
$_SESSION['email']=$email;
$_SESSION['subtotal']=$subtotal;
}
?>
<form action="<?php echo $url; ?>" method="post">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" value="<?php echo $email; ?>"/>
<input type="hidden" name="item_name" value="shopping cart"/>
<input type="hidden" name="currency_code" value="GBP"/>
<input type="hidden" name="amount" value="<?php echo $subtotal;?>"/>
<input type="hidden" name="return" value="<?php echo SITE_URL; ?>"/>
<input type="hidden" name="cancel_return" value="<?php echo SITE_URL."/shoppingCart.php" ?>"/>
<input type="hidden" name="notify_url" value="php url" />
<input type="hidden" name="rm" value="2"/>
<input type="hidden" name="custom" value="<?php echo $customer_ID;?>"/>
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
</form>
and php code
from php IPN sample code.....
Try:
1. login in your paypal account
2. go to profile --> History --> IPN history --> turn on my IPN
3. insert your IPN listener URL.
What's the value of:
<input type="hidden" name="notify_url" value="php url" />
This shouldn't be on localhost, since PayPal sends POST data from its servers to that URL. So localhost won't work.

Categories