Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multiple parameters to IPN url to PayPal on Android?

I am implementing PayPal in my Android application and I want to send multiple parameters to PayPal as query string with IPN URL.

For example

http://www.example.com/ipn/txnId=12&cartId=12

but the problem is when I use this URL as IPN URL PayPal gives me an error.

I have tried with URLEncoding but again no successful payment.

If I try with single parameter it is working.

Example

http://www.example.com/ipn/txnId=12

I encountered a problem that PayPal is not accept & characters in string so I have tried to replace & with & and also \\& but it didn't help either.

I know I can set multiple parameters into a single variable and pass it to PayPal but I want to pass multiple parameters like query string.

How can I have PayPal accept my payment with multiple parameters?

EDIT

Currently i am using this code for encode URL but it fails.

protected String addLocationToUrl(String url){

        if(!url.endsWith("?"))
            url += "?";

        List<NameValuePair> params = new LinkedList<NameValuePair>();

            params.add(new BasicNameValuePair("txnId", "45"));
            params.add(new BasicNameValuePair("cartId", "34"));



        String paramString = URLEncodedUtils.format(params, "utf-8");

        url += paramString;


        return url;
    }
like image 888
Dharmendra Avatar asked Jul 05 '11 14:07

Dharmendra


2 Answers

From p20 of the developers guide at https://cms.paypal.com/cms_content/en_US/files/developer/PP_PayflowPro_Guide.pdf

Using Special Characters in Values

Because the ampersand ( & ) and equal sign (=) characters have special meanings in the PARMLIST, name-value pairs like the following examples are not valid:

NAME=Ruff & Johnson

COMMENT1=Level=5

To use special characters in the value of a name-value pair, use a length tag. The length tag specifies the exact number of characters and spaces that appear in the value. The following name-value pairs are valid:

NAME[14]=Ruff & Johnson

COMMENT1[7]=Level=5

UPDATE

Following our conversation discussed in the Android Disussion Room it became apprent that you were using the Paypal Payment API for Android. Paypal do not provide support for multiple parameters in the IPN address using the Android Payment API.

One option would be to replace the & character with one that does not have a special meaning in URL's. Then parse the values from a single parameter value when recieved by your IPN listener, however you would also have to replace the subsequent = characters.

e.g. http://www.example.com/ipn/params=txnId_12-cartId_12

You stated that you require these additional parameters for validation purposes but validation should be implemented as outlined by paypal if it is to securely implemented.

Please read the Overview of Instant Payment Notification. This describes the IPN process and what you need to validate IPN requests to your listening service.

You will also find an example for Implementing an IPN listener in PHP

A complete list of IPN message body parameters can be found in the Order Management Integration Guide

like image 179
Moog Avatar answered Nov 15 '22 09:11

Moog


You could use "Custom" field but the same problem arises! I Will try that usage of length tags with custom something like:

var1[5]=th&ee&var2[3]=t=o&var3[3]=one

Values

th&ee

t=o

one


is this it or am I missing something?

If all else fails I will replace the chars and reReplace them on the receiving end.

like image 38
JDuarteDJ Avatar answered Nov 15 '22 07:11

JDuarteDJ