Reputation: 3391
I'm new using paypal and I'm searching this question in 1 day. I need your help guys. I've done coding express checkout API and I successfully getting the payment transaction but my problem is the cancel url. When I cancel my payment, it returns to my cancel url and the paypal gives token like this url http://www.example.com/?token=EC-75630865LV806263H
Is it possible to get the firstname, lastname or any info about the client when the client click the cancel and return to my cancel url?
If ever possible can you give me link or tutorial on how to get the info of client when do cancel url.
thanks in advance.
Upvotes: 5
Views: 8762
Reputation: 1068
The token
is also a parameter in the redirect URL after you create the payment
. So you could do something like this to put it in your database (associated with the pending order or whatever) for later retrieval, without relying on cookies:
$payment->create($apiContext);
$link = $payment->getApprovalLink();
parse_str(parse_url($link, PHP_URL_QUERY), $linkParams);
if (!empty($linkParams['token'])) {
// Store token in database for possible lookup later
// Presumably just another column field...
yourSaveToken($yourOrder, $linkParams['token']);
}
header('Location: ' . $link);
Then, when your cancellation URL fires you can retrieve the cancelled order
if (!empty($_REQUEST['token'])) {
// Match token previousy stored by `yourSaveToken`
$yourOrder = yourGetOrderFromToken($_REQUEST['token']);
}
Upvotes: 2
Reputation: 81
I wrote my code such that I generated the cancelurl at runtime. So before sending the payment transaction payload, I set the cancel url like so:
$settings->cancelurl = 'http://www.example.com';
if($_SESSION['customer_ref']){ //save loggedin customer ref in session.
$settings->cancelurl .= '&customer_ref='.$_SESSION['customer_ref'];
}
So when the cancelurl on paypal would look like this http://www.example.com/?customer_ref=qwuy16436771&token=EC-2Q454WDAE110BD2
So you can then grab the customer_ref from the url and do whatever you need to do with it once it hits your server.
I hope this helps.
Upvotes: 3
Reputation: 1662
on the checkout page, look for the 'cancel_return' hidden form element:
<input type="hidden" name="cancel_return" id="cancel_return" value="" />
set the value of the cancel_return form element to the URL you wish to return to:
<input type="hidden" name="cancel_return" id="cancel_return" value="http://royaltytech.in" />
Upvotes: 2
Reputation: 31614
I would assume not, since usually the cancel button is pressed before authentication but I've not tried it mid-process either. Normally the process is they log in, confirm payment and PayPal bounces them back to your payment completion page. But it could be possible to call getExpressCheckoutDetails if they cancel after authenticating. Again, I've never tried. But the worst that will happen is PayPal fails to return anything.
Upvotes: 2