1

这就是我正在设计的一个网站,多个商店可以在该网站上出售他们的产品。每个卖家都会在我的网站上拥有一个虚拟商店。我正在使用贝宝进行购买操作。我考虑过允许客户在没有贝宝账户的情况下使用信用卡,并且我正在尝试使用自适应支付流程来允许“以访客身份购买”流程。我正在尝试使用贝宝默认流程(而不是其他 api),因为我不想担心处理信用卡数据并且必须将我的网站设计为符合 PCI 标准。

因此,在这种情况下,这就是我正在使用的:

设置网页以使用灯箱调用嵌入式支付流程

  • 由于此付款流程需要生成付款密钥,因此我使用此链接上的代码:

https://github.com/paypal/rest-api-sdk-dotnet/tree/master/Samples/RestApiSample

- 所以在我的 MVC 上,我有一个生成订单的页面,它调用 Helper 方法来获取支付密钥。这是最相关的一个:

public static string GetPayKey(DummyPurchase purchase)
    {
        ReceiverList receiverList = new ReceiverList();
        receiverList.receiver = new List<Receiver>();
        //(Required) Amount to be paid to the receiver
        string[] amt = new string[1] { purchase.TotalPrice.ToString() };
        // Receiver's email address. This address can be unregistered with paypal.com.
        // If so, a receiver cannot claim the payment until a PayPal account is linked
        // to the email address. The PayRequest must pass either an email address or a phone number. 
        // Maximum length: 127 characters 
        string[] receiverEmail = new string[1] { purchase.StoreId.ToString() };
        string cancelUrl = ConfigurationHelper<string>.GetKeyValue(Constants.PAYPAL_CANCEL_URL);
        string returnUrl = ConfigurationHelper<string>.GetKeyValue(Constants.PAYPAL_RETURN_URL);
        string currency = ConfigurationHelper<string>.GetKeyValue(Constants.PAYPAL_CURRENCY_CODE);

        //Generate Receivers list
        for (int i = 0; i < amt.Length; i++)
        {
            Receiver rec = new Receiver(Convert.ToDecimal(amt[i]));
            if (receiverEmail[i] != string.Empty)
            {
                rec.email = receiverEmail[i];
            }

            receiverList.receiver.Add(rec);
        }

        PayRequest request = new PayRequest(new RequestEnvelope("en_US"), "PAY",
                            cancelUrl, currency,
                            receiverList, returnUrl);




        //call the service
        AdaptivePaymentsService service = null;
        PayResponse response = null;
        try
        {
            // (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)
            Dictionary<string, string> configurationMap = GetAcctAndConfig();

            // Creating service wrapper object to make an API call and loading
            // configuration map for your credentials and endpoint
            service = new AdaptivePaymentsService(configurationMap);

            response = service.Pay(request);
        }
        catch (Exception ex)
        {
            Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex));
            return "";
        }

        Dictionary<string, string> responseValues = new Dictionary<string, string>();
        string redirectUrl = null;
        if (!(response.responseEnvelope.ack == AckCode.FAILURE) &&
            !(response.responseEnvelope.ack == AckCode.FAILUREWITHWARNING))
        {

            return response.payKey;
        }
        return "";
    }

- 获得此密钥后,我从另一个视图获取 html,该视图具有 API 指南指定的表单,将 paykey 字符串作为此视图的模型。

@model string
<h2>ConfirmCheckout</h2>
<script src="https://www.paypalobjects.com/js/external/dg.js">
</script>
<form action="https://www.paypal.com/webapps/adaptivepayment/flow/pay"
target="PPDGFrame">
<input id="type" type="hidden" name="expType" value="light">
<input id="paykey" type="hidden" name="paykey" value="@Model">
<input type="submit" id="submitBtn" value="Pay with PayPal">
</form>

- 视图呈现后,我调用 javascript 代码启动流程:

var dgFlow = new PAYPAL.apps.DGFlow({ trigger: 'submitBtn' });

- 流程完美运行,我在此表单上获得了有效的支付密钥。但是,当我单击此按钮(使用 paykey 提交表单上的按钮)时,我收到 2 个不同的错误。这是最常见的:

该交易已获批准。请访问您的 PayPal 帐户概览以查看详细信息。

- 但有时我会收到“您的付款会话已过期”错误。

我有两个问题:

  • 有人知道如何解决这些错误吗?
  • 我正在使用 clasic API,因为用于自适应支付的访客支付流程需要 PayKey 来启动流程(以避免安全和 PCI 合规问题)。我没有在 Paypal REST API 上找到可以获取相同 PayKey 的方法。有什么方法可以获得这些密钥吗?

非常感谢

4

2 回答 2

3

嗯,这真的很尴尬......但真正的问题是表单的发布操作上的 url。我有

<form action="https://www.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame">

哪个是生产环节。而且我还没有上线,我正在使用 sanbox 帐户的 paypal api 凭据,所以真正的表单操作应该是:

<form action="https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay" target="PPDGFrame">  

呸!希望这可以帮助另一个有同样错误的人。

非常感谢@Andrew Angell

于 2013-11-05T18:13:19.713 回答
0

听起来您正在通过付款请求发送 Preapproval 密钥。当您这样做时,不需要重定向到 PayPal。这就是重点......您已经通过 Preapproval Key 获得批准,因此当您提交包含 preapproval key 的付款请求时,将立即付款(只要 preapproval profile 仍然有效。)

因此,当您进行重定向时,它会准确地告诉您发生了什么……交易已经处理完毕。同样,不需要重定向。

关键是能够在您需要任何重定向或进一步批准的任何时候使用您的应用程序中的预批准配置文件触发付款。拥有该预先批准密钥后,您可以以任何方式触发付款。例如,您可能希望向某人收取每次使用费用并在他们登录您的网站时触发付款,但您不希望他们每次都必须批准付款。支付可以通过支付 API 在后台进行,其中包含预批准密钥,但用户根本不会被中断。

希望有帮助。

于 2013-10-31T08:44:04.367 回答