gpt4 book ai didi

asp.net-mvc - MVC Paypal 自适应支付

转载 作者:太空宇宙 更新时间:2023-11-03 15:53:31 26 4
gpt4 key购买 nike

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

所以在这个场景中,我使用的是:

Setting Up Web Pages to Invoke the Embedded Payment Flow Using a Lightbox

  • 由于此支付流程需要生成支付 key ,因此我使用此链接中的代码:

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

-因此,在我的 MVC 上,我有一个生成订单的页面,它调用一个帮助程序方法来获取 paykey。这是最相关的一个:

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

-获得此 key 后,我从另一个 View 获取 html,该 View 具有 API 指南指定的形式,并将 paykey 字符串作为此 View 的模型。

@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>

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

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

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

This transaction has already been approved. Please visit your PayPal Account Overview to see the details.

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

我有两个问题:

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

非常感谢

最佳答案

嗯,这真的很尴尬……但真正的问题是表单的 post 操作上的 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

关于asp.net-mvc - MVC Paypal 自适应支付,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19689622/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com