Paypal 定期付款交易错误:11502:令牌无效

2024-03-28

我是贝宝新手,我需要为我的客户实施订阅(定期付款)。我正在使用贝宝沙箱来实施。我遵循贝宝坚持创建定期付款资料的方式。从 SetExpressCheckout、GetExpressCheckOut 和 DoExpressCheckOut 获得“成功”确认。我尝试使用 DoExpressCheckOut payment 响应中的令牌创建定期付款配置文件,但 CreateRecurrin payment 配置文件的响应返回失败,指出 ivnalid 中的令牌。我尝试在设置的快速结账请求上设置“BILLINGAGREMENTDESCRIPTION 和 BILLINGTYPE=RecurringPayments”,但同样的错误仍然存​​在。

请在下面找到我用来实现定期存款的代码。

设置快速结帐

{
NameValueCollection values = new NameValueCollection();

            values["METHOD"] = "SetExpressCheckout";

            values["RETURNURL"] = PayPalSettings.ReturnUrl;

            values["CANCELURL"] = PayPalSettings.CancelUrl;

            values["PAYMENTACTION"] = "Sale";

            values["CURRENCYCODE"] = "USD";

            values["BUTTONSOURCE"] = "PP-ECWizard";

            values["USER"] = PayPalSettings.Username;

            values["PWD"] = PayPalSettings.Password;

            values["SIGNATURE"] = PayPalSettings.Signature;

            values["SUBJECT"] = "";

            values["L_NAME0"] = "MyName";

            values["L_AMT0"] = "20.00";

            values["VERSION"] = "2.3";

            values["AMT"] = PayPalSettings.OrderAmount;

            values["L_BILLINGTYPE0"] = "RecurringPayments";

            values["L_BILLINGAGREEMENTDESCRIPTION0"] = "Test subscription";





            values = Submit(values);



            string ack = values["ACK"].ToLower();



            if (ack == "success" || ack == "successwithwarning")

            {

                return new PayPalRedirect

                {

                    Token = values["TOKEN"],
                    Url = String.Format("https://{0}/cgi-bin/webscr?cmd=_express-checkout&token={1}",
                       PayPalSettings.CgiDomain, values["TOKEN"])
                 };
            }
             else
            {
            throw new Exception(values["L_LONGMESSAGE0"]);
            }
}

Submit

private static NameValueCollection Submit(NameValueCollection values)

        {

            string data = String.Join("&", values.Cast<string>()

              .Select(key => String.Format("{0}={1}", key, HttpUtility.UrlEncode(values[key]))));



            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(

               String.Format("https://{0}/nvp", PayPalSettings.ApiDomain));



            request.Method = "POST";

            request.ContentLength = data.Length;



            using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))

            {

                writer.Write(data);

            }



            using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))

            {

                return HttpUtility.ParseQueryString(reader.ReadToEnd());

            }

        }

设置快速结账

public ActionResult Success(string token)

    {

        GetExpressCheckout getExpressCheckout = new GetExpressCheckout();

        GetExpressCheckoutDetailsResponseType getExpressCheckoutResponse = getExpressCheckout.ECGetExpressCheckoutCode(token);



        if (getExpressCheckoutResponse.Ack == AckCodeType.Success)

        {

            ExpressCheckout expressCheckout = new ExpressCheckout();

            DoExpressCheckoutPaymentResponseType doExpressCheckoutResponse = expressCheckout.DoExpressCheckoutPayment

                                                        (

                                                            token,

                                                            getExpressCheckoutResponse.GetExpressCheckoutDetailsResponseDetails.PayerInfo.PayerID,

                                                            PayPalSettings.OrderAmount,

                                                            PaymentActionCodeType.Sale,

                                                            CurrencyCodeType.USD

                                                        );



            if (doExpressCheckoutResponse.Ack == AckCodeType.Success)

            {

CreateRecurringPaymentsProfile createRecurringPaymentsProfile = new CreateRecurringPaymentsProfile();               

                CreateRecurringPaymentsProfileResponseType recurringPaymentProfileResponse = createRecurringPaymentsProfile.CreateRecurringPaymentsProfileCode(

                                                                                                doExpressCheckoutResponse.DoExpressCheckoutPaymentResponseDetails.Token,

                                                                                                doExpressCheckoutResponse.Timestamp,

                                                                                                PayPalSettings.OrderAmount,

                                                                                                1,

                                                                                                BillingPeriodType.Month,

                                                                                                CurrencyCodeType.USD

                                                                                                );

                if (recurringPaymentProfileResponse.Ack == AckCodeType.Success)

                {
}

创建重复发生付款资料

public CreateRecurringPaymentsProfileResponseType CreateRecurringPaymentsProfileCode(string token, DateTime date, string amount, int BF, BillingPeriodType BP, CurrencyCodeType currencyCodeType)

              {

                     CallerServices caller = new CallerServices();



                     IAPIProfile profile = ProfileFactory.createSignatureAPIProfile();



            // Set up your API credentials, PayPal end point, and API version.

            profile.APIUsername = PayPalSettings.Username;

            profile.APIPassword = PayPalSettings.Password;

            profile.APISignature = PayPalSettings.Signature;

                     profile.Environment="sandbox";

                     caller.APIProfile = profile;





                     // Create the request object.

                    CreateRecurringPaymentsProfileRequestType pp_request=new CreateRecurringPaymentsProfileRequestType();

                     pp_request.Version="51.0";



            // Add request-specific fields to the request.

                     pp_request.CreateRecurringPaymentsProfileRequestDetails= new CreateRecurringPaymentsProfileRequestDetailsType();

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.Token=token;

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.RecurringPaymentsProfileDetails=new RecurringPaymentsProfileDetailsType();

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.RecurringPaymentsProfileDetails.BillingStartDate=date;

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails=new ScheduleDetailsType();

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod=new BillingPeriodDetailsType();

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.Amount=new BasicAmountType();

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.Amount.Value =amount ;

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.Amount.currencyID= currencyCodeType;//Enum for currency code is  CurrencyCodeType.USD

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.BillingFrequency=BF;

                     pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.PaymentPeriod.BillingPeriod=BP;////Enum for BillingPeriod is  BillingPeriodType.Day

            //pp_request.Version = "51.0";



            pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.Description = "Test subscription";

            //pp_request.CreateRecurringPaymentsProfileRequestDetails.ScheduleDetails.Description



            // Execute the API operation and obtain the response.

                     CreateRecurringPaymentsProfileResponseType pp_response=new CreateRecurringPaymentsProfileResponseType();

                     pp_response= (CreateRecurringPaymentsProfileResponseType) caller.Call("CreateRecurringPaymentsProfile", pp_request);

                     return pp_response;

              }

任何帮助将不胜感激。

提前致谢


Sujth,根据您的需要给出的正确版本是 51.0。 快乐编码!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Paypal 定期付款交易错误:11502:令牌无效 的相关文章

  • 分段错误(核心转储)错误

    我的程序编译罚款 但在输入文件时出现 分段错误 核心转储 错误 我没有正确处理 ostream 吗 include
  • 从多线程程序中调用 system()

    我们正在开发一个用 C 编写的多线程内存消耗应用程序 我们必须执行大量的 shellscript linux 命令 并获取返回码 读完之后article http www linuxprogrammingblog com threads a
  • System.IO.IOException:由于意外>数据包格式,握手失败?

    有谁知道这意味着什么 System Net WebException 底层连接已关闭 发送时发生意外错误 gt System IO IOException 由于意外 握手失败 数据包格式 在 System Net Security SslS
  • @RenderBody() 该怎么办?

    我有一个 ASP NET MVC 3 应用程序JQuery UI Tabs 我有一个主布局页面 layout cshtml 代码如下 大师 layout cshtml需要一个 RenderBody 代码 既然是必需的 那我该怎么办呢 我想我
  • 如何尝试/捕获所有异常

    我正在完成由其他人启动的 UWP 应用程序 该应用程序经常崩溃 我总是陷入困境应用程序 at if global System Diagnostics Debugger IsAttached global System Diagnostic
  • CultureInfo 的实例(来自相同的文化)根据操作系统而变化

    我有一个网站 上面写着这样的日期 CultureInfo cultureInfo CultureInfo GetCultures CultureTypes AllCultures FirstOrDefault c gt string Equ
  • 将字符串中的“奇怪”字符转换为罗马字符

    我需要能够将用户输入仅转换为 a z 罗马字符 不区分大小写 所以 我感兴趣的角色只有26个 然而 用户可以输入他们想要的任何 形式 的字符 西班牙语 n 法语 e 和德语 u 都可以包含用户输入中的重音符号 这些重音符号会被程序删除 我已
  • 将字符串转换为正确的 URI 格式?

    有没有简单的方法可以将电子邮件地址字符串转换为正确的 URI 格式 Input http mywebsite com validate email 3DE4ED727750215D957F8A1E4B117C38E7250C33 email
  • 带 If 的嵌套 For 循环的时间复杂度

    void f int n for int i 1 i lt n i if i int sqrt n 0 for int k 0 k lt pow i 3 k do something 我的思考过程 执行if语句的次数 sum i 1 to
  • 无法解析远程名称 - webclient

    我面临这个错误 The remote name could not be resolved russgates85 001 site1 smarterasp net 当我请求使用 Web 客户端读取 html 内容时 出现错误 下面是我的代
  • 从 Code::Blocks 运行程序时出现空白控制台窗口 [重复]

    这个问题在这里已经有答案了 当我尝试在 Code Blocks 中构建并运行新程序时 控制台窗口弹出空白 我必须单击退出按钮才能停止它 它对我尝试过的任何新项目 包括 Hello world 都执行此操作 奇怪的是 它对于我拥有的任何旧项目
  • 使用 WF 的多线程应用程序的错误处理模式?

    我正在写一个又长又详细的问题 但只是放弃了它 转而选择一个更简单的问题 但我在这里找不到答案 应用程序简要说明 我有一个 WPF 应用程序 它生成多个线程 每个线程执行自己的 WF 处理线程和 WF 中的错误 允许用户从 GUI 端进行交互
  • C++ 错误 - “成员初始值设定项表达式列表被视为复合表达式”

    我收到一个我不熟悉的 C 编译器错误 可能是一个非常愚蠢的错误 但我不能完全指出它 Error test cpp 27 error member initializer expression list treated as compound
  • C++11 动态线程池

    最近 我一直在尝试寻找一个用于线程并发任务的库 理想情况下 是一个在线程上调用函数的简单接口 任何时候都有 n 个线程 有些线程比其他线程完成得更快 并且到达的时间不同 首先我尝试了 Rx 它在 C 中非常棒 我还研究了 Blocks 和
  • 二叉树中的 BFS

    我正在尝试编写二叉树中广度优先搜索的代码 我已将所有数据存储在队列中 但我不知道如何访问所有节点并消耗它们的所有子节点 这是我的 C 代码 void breadthFirstSearch btree bt queue q if bt NUL
  • asp.net网格分页的SQL查询

    我在用iBatis and SQLServer 使用偏移量和限制进行分页查询的最佳方法是什么 也许我添加该列ROW NUMBER OVER ORDER BY Id AS RowNum 但这只会阻止简单查询的数据访问 在某些情况下 我使用选择
  • 使用 mingw32 在 Windows 上构建 glew 时“DllMainCRTStartup@12”的多个定义

    我关注了这个主题 使用 mingw 使建筑物在 Windows 上闪闪发光 https stackoverflow com questions 6005076 building glew on windows with mingw 6005
  • ASP.NET JQuery AJAX POST 返回数据,但在 401 响应内

    我的应用程序中有一个网页 需要调用我设置的 Web 服务来返回对象列表 这个调用是这样设置的 document ready function var response ajax type POST contentType applicati
  • 如何引用解决方案之外的项目?

    我有一个 Visual Studio C 解决方案 其中包含一些项目 其中一个项目需要引用另一个不属于解决方案的项目 一开始我引用了dll
  • ASP.NET Core 会话超时

    我记得我们在 ASP NET 中使用了 session timeout 来更改会话超时 如果不更改 则为 20 分钟 我尝试在 Startup cs 中更改 ASP NET Core 3 1 中的会话超时 但没有任何反应 我对操作员使用身份

随机推荐