如何在 Android 上将多个参数传递给 IPN url 到 PayPal?

发布于 2024-11-18 16:25:03 字数 1124 浏览 4 评论 0原文

我正在我的 Android 应用程序中实现 PayPal,并且我想将多个参数作为带有 IPN URL 的查询字符串发送到 PayPal。

例如

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

,但问题是当我使用此 URL 作为 IPN URL 时,PayPal 给我一个错误。

我尝试过使用 URLEncoding 但再次没有成功付款。

如果我尝试使用单个参数,它就可以工作。

示例

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

我遇到了 PayPal 不接受字符串中的 & 字符的问题 所以我尝试用 &\\& 替换 & 但它也没有帮助。

我知道我可以将多个参数设置为一个变量并将其传递给 PayPal,但我想传递多个参数,例如查询字符串。

如何让 PayPal 通过多个参数接受我的付款?

编辑

目前我正在使用此代码来编码 URL,但它失败了。

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;
    }

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;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏别ゝ 2024-11-25 16:25:03

摘自《开发者指南》第 20 页:
https://cms.paypal.com/cms_content/en_US/files/ developer/PP_PayflowPro_Guide.pdf

在值中使用特殊字符

因为与符号 ( & )和等号 (=) 字符在 PARMLIST 中具有特殊含义,如下例所示的名称-值对无效:

NAME=Ruff & Johnson

COMMENT1=Level=5

要在名称-值对的值中使用特殊字符,请使用长度标记。长度标签指定值中出现的字符和空格的确切数量。以下名称/值对有效:

NAME[14]=Ruff & Johnson

COMMENT1[7]=Level=5

更新

按照我们在 Android 讨论室 我们发现您正在使用适用于 Android 的 Paypal Payment API。 Paypal 不支持使用 Android Payment API 的 IPN 地址中的多个参数。

一种选择是将 & 字符替换为在 URL 中没有特殊含义的字符。然后,当 IPN 侦听器收到单个参数值时,解析这些值,但您还必须替换后续的 = 字符。

例如 http://www.example.com/ipn/params=txnId_12-cartId_12

您声明您需要这些附加参数用于验证目的,但如果要安全,则应按照 PayPal 的概述实施验证实施的。

请阅读即时付款通知概述< /a>.这描述了 IPN 流程以及验证对侦听服务的 IPN 请求所需的内容。

您还可以找到实施PHP 中的 IPN 监听器

IPN 消息体参数的完整列表可以在 订单管理集成指南

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

欲拥i 2024-11-25 16:25:03

您可以使用“自定义”字段,但也会出现同样的问题!
我将尝试使用自定义的长度标签,例如:

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

Values

th&ee

t=o


是这个还是我遗漏了什么?

如果所有其他方法都失败,我将替换字符并在接收端重新替换它们。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文