c# - Paypal 开发者测试版 : Test transaction not listed in Sandbox Business account

标签 c# .net paypal paypal-sandbox

所以..... Paypal Developer 似乎决定从 2013 年开始更改其全新网站上的所有内容,这让我过去几天的生活很痛苦。请注意,我对在网站中集成 Paypal 完全陌生。我试图按照本教程进行操作,但它来自 2009 年:http://www.codeproject.com/Articles/42894/Introduction-to-PayPal-for-C-ASP-NET-developers

我没有使用 Paypal Api。不知道我是否应该这样做?

这是我做的:

1) 我去了https://developer.paypal.com/并使用我自己的 paypal 帐户登录。

2) 这是棘手的部分之一。在我检查过的教程中,有一个创建“预配置测试帐户”的选项,但它不再可用。所以我用他们新的创建帐户按钮创建了两个测试帐户(或者我认为)。一位个人(买家)和一位企业(卖家)。如果这些测试帐户的邮件地址需要存在或者它们是否可以是虚构的,则没有提及教程......我让买家成为真实的(我为这次测试创建的)而卖家是虚构的。

3) 在我的测试卖家账户中,我使用我的 CallbackUrl 激活了 AutoReturn,我激活了支付数据传输 (PDT) 并将 token 放入我的 web.config 中。

4) 再次按照教程,我创建了我的 .Net Visual Studio 项目。非常简单的东西,一个 Default.aspx、一个 Callback.aspx 和一个 Cancelled.aspx。检查交易是否成功的回调和检查用户是否取消交易的 Cancelled。

5) 这里是Default.aspx的code/Paypal hiddenfield变量。没什么特别的:

<form id="form1" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" runat="server">
<div>
    <!-- Type: Buy Now/Simple Payment -->
    <input type="hidden" name="cmd" value="_xclick" />
    <!-- PayPal ID or an email address associated with your PayPal account -->
    <input type="hidden" name="business" value="THE-SELLER-MAIL-ADRESS" />
    <!-- Name of service selected -->
    <input type="hidden" name="item_name" value="Forfait Regulier" />
    <!-- Currency -->
    <input type="hidden" name="currency_code" value="CAD" />
    <!-- Return method: 2 – the buyer’s browser is redirected to the return URL by using the POST method, and all payment variables are included -->
    <input type="hidden" name="rm" value="2" />
    <!-- Button text -->
    <input type="hidden" name="cbt" value="Retourner sur Bloc D'Affaires" />
    <!-- Cancel callback url -->
    <input type="hidden" name="cancel_return" value="http://dev.triarts.ca/Pages/Cancelled.aspx" />
    <!-- Amount -->
    <input type="hidden" name="amount" value="10.00" />
    <!-- Don't show Shipping adress form -->
    <input type="hidden" name="no_shipping" value="1" />
    <!-- Don't show seller note box -->
    <input type="hidden" name="no_note" value="1" /> 
    <!-- Button -->
    <input type="submit" value="Payer" />
</div>
</form>

6) Callback.aspx 的代码隐藏,取自并改编自上述 2009 年的教程:

protected void Page_Load(object sender, EventArgs e)
{
    string authToken = WebConfigurationManager.AppSettings["PDTToken"];

    //read in tx token from querystring
    string txToken = Request.QueryString.Get("tx");


    string query = string.Format("cmd=_notify-synch&tx={0}&at={1}",
                          txToken, authToken);

    // Create the request back
    string url = WebConfigurationManager.AppSettings["PayPalSubmitUrl"];
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

    // Set values for the request back
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";
    req.ContentLength = query.Length;

    // Write the request back IPN strings
    StreamWriter stOut = new StreamWriter(req.GetRequestStream(),
                             System.Text.Encoding.ASCII);
    stOut.Write(query);
    stOut.Close();

    // Do the request to PayPal and get the response
    StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
    string strResponse = stIn.ReadToEnd();
    stIn.Close();

    // If response was SUCCESS, parse response string and output details
    if (strResponse.StartsWith("SUCCESS"))
    {
        Label1.Text = "Success";
    }
    else
    {
        Label1.Text = "Oooops, something went wrong...";
    }
}

7) 到目前为止,它并没有那么复杂。之后,我首先登录我的 Paypal 开发者帐户。我启动项目并对其进行测试。按立即购买按钮,按预期重定向到 Paypal 沙盒测试商店。我用我的买家测试账户登录,点击立即付款。过程。交易成功。该页面按预期将我重定向到 Callback.aspx,并显示成功消息。不那么破旧。

8) 但这是另一个棘手的部分。在 Paypal 开发者网站上,我看到买家/卖家通知说付款已发送/收到。我在沙盒中以测试买家的身份登录并检查最近的事件:一个条目显示付款已完成并完成(状态)。我以测试卖家身份登录,我查看最近的事件,没有看到任何交易条目,但 Paypal 余额增加,这意味着付款已添加?!?...

我不明白……这应该会发生吗?我做错什么了吗?如果我使用这些设置,一切都会出错吗?

在对我没有真正帮助的视频教程中,它清楚地显示了卖家测试帐户中的交易条目。为什么没有出现我的,或者我迄今为止完成的无数次测试交易中的任何一个?

谁能确保这个过程是合法的?这会让我放心很多。当我不确定这一点时,我会觉得乱花钱很不自在。此代码是否足以创建后付款逻辑,例如更新我的数据库以提及付款已完成或已取消?如果有更简单的方法,请不要犹豫告诉我。

提前非常感谢您,并为这部史诗小说感到抱歉。

最佳答案

新沙盒企业账户目前默认启用 Payments Pro,账户布局不同于标准企业或个人账户。使用 Pro 帐户,您在首次登录时不会在“帐户概览”页面上看到交易。

要查看 Pro 账户上的交易,您需要打开“历史记录”选项卡。你想通了,你很高兴。我担心交易没有出现在“历史记录”选项卡上,但这似乎不是问题所在,所以我松了一口气。

关于c# - Paypal 开发者测试版 : Test transaction not listed in Sandbox Business account,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17090663/

相关文章:

c# - VS2010 中的 FxCop 行为、代码分析和 SuppressMessage

c# - 在 Windows 窗体应用程序 c# 中选择两个日期之间的查询

c# - System.Reflection 如何访问类成员数据/信息?

java - 如何通过API取消paypal支付

paypal - PayPal 按钮和 PayPal Express Checkout 之间有什么区别?

C#:使用 System.Speech 命名空间将 WAV 文件转录为文本(语音到文本)

c# - XmlDocument() 内存泄漏

.net - 如何在 ColorMatrix 中使用计算出的颜色值?

.net - Entity Framework 代码首先使用时间戳类型

paypal - 如何将 paypal 循环 gem 与 Spree 集成