1

I'm trying to perform a payment in 3 classic steps:

1) Order Page with PayNow Button

2) PayPal Payment

3) Redirect to "Payment completed page"

What I want to achieve is to have an ID going from step 1 to step 3. What I tried to do is to insert this field into the "custom" variable like:

<input type="hidden" name="custom" value="--Server Code--">

After the PayPal payment, PayPal redirect me to my page:

http://www.mysite.cm/tx=blalba?aaaa

In this URL there is not custom Field. If, from API, I contact PayPal to have the sale details, I get nothing related to my custom Field.

What I'm doing wrong? I'm thinking of a work around using cookies but I prefer to do it in the standard way.

  <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
        <input type="hidden" name="cmd" value="_s-xclick">
        <input type="hidden" name="return" value="testestest">
        <input type="image" src="https://www.paypalobjects.com/it_IT/IT/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal è il metodo rapido e sicuro per pagare e farsi pagare online.">
        <img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1">
    </form>
Ziba Leah
  • 2,484
  • 7
  • 41
  • 60

2 Answers2

3

The PayPal Custom variable is returned in the IPN (Instante payment notification), not when the user is returned to your website after completed the payment.

In your case just a session variable would be enough.

EDIT:

Another way might be adding in the "return" field the proper url value. example:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="return" value="http://www.website.com?pram=value">
    <input type="hidden" name="cancel" value="http://www.website.com?param=value">
    <input type="hidden" name="business" value="yourpaypal@email.com">
    <input type="hidden" name="item_name" value="Test">
    <input type="hidden" name="amount" value="9.00">
    <input type="hidden" name="currency_code" value="EUR">

    <input type="image" src="https://www.paypalobjects.com/it_IT/IT/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal è il metodo rapido e sicuro per pagare e farsi pagare online.">
   <img alt="" border="0" src="https://www.paypalobjects.com/it_IT/i/scr/pixel.gif" width="1" height="1">
</form>
CCamilo
  • 897
  • 1
  • 15
  • 18
  • I'm not sure about it. 'Cause if I set from the online configuration the custom field to a value I find it on the details and in query string. The problem is assigning it from code behind! I could go on with the IPN but it's something more "async".. – Ziba Leah Jul 01 '16 at 08:34
  • One question, why do you need the custom variable for? – CCamilo Jul 01 '16 at 08:51
  • Track the specific session. The process is composed by: Data Collect, Payment, Doc creation based on the data collected at step 1. I need an identifier but I find horrible to store it in cookies or session! – Ziba Leah Jul 01 '16 at 09:06
  • 1
    Have you tried to specify in the return your url with the variable you want. like ; As I said, the custom variable is ONLY for IPN purposes – CCamilo Jul 01 '16 at 09:18
  • Adding the return hidden field I get this message: Error Detected Error Message Some required information is missing or incomplete. Please correct your entries and try again. – Ziba Leah Jul 01 '16 at 13:31
  • I don't get any error. Maybe if I see your button I would be able to help you better. – CCamilo Jul 04 '16 at 06:00
  • Coded added! On the question! Thanks again for your support! – Ziba Leah Jul 04 '16 at 08:57
  • 1
    I added an example: In this case because we are creating a button on the fly we have to use "_xclick" instead of "_s-xclick". Also, you must add the amount, currency code and other mandatory fields. – CCamilo Jul 04 '16 at 10:30
  • 1
    In the end I simply implemented the IPN to get those info... Thank you very much for your suggestions! – Ziba Leah Jul 04 '16 at 15:20
2

The existing answer already mentions that IPN is the way to go, but what's missing is more info how to actually implement this.

I had to do this myself recently, so here's the solution that worked for me:

First, you need to add your ID to your "Pay Now" button's HTML, for example into the "custom" variable, like shown in the question.

In my own implementation, I had some problems using the "custom" variable (don't remember details anymore), so I passed my ID as an URL parameter in the IPN "notify" URL instead:

<input type="hidden" name="notify_url" value="https://example.com/notify/?id=xyz">

Here's the complete HTML code for my button:

<form action="https://www.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="ABCDEFGHILJKLM">
    <table>
    <tr><td><input type="hidden" name="on0" value="Betrag">Betrag</td></tr><tr><td><select name="os0">
        <option value="Gebuehr">Gebuehr €3,50 EUR</option>
        <option value="Gebuehr und Spende">Gebuehr und Spende €5,00 EUR</option>
    </select> </td></tr>
    </table>
    <input type="hidden" name="currency_code" value="EUR">
    <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">
    <input type="hidden" name="notify_url" value="https://example.com/notify/?id=xyz">
</form>

After the payment process is completed, PayPal will post an IPN message to my notify URL, which contains a lot of information about the transaction (see the link for more information).

My ID was passed via URL parameter, so I can get it (in PHP) like this:

$uid = "";
if (!empty($_GET['id'])) {
    $uid = $_GET['id'];
}

And of course, you need to check whether the IPN call is actually coming from PayPal.

Christian Specht
  • 35,843
  • 15
  • 128
  • 182