这就是我正在设计一个网站,在这个网站上我可以提供多种商店销售产品 . 每个卖家都会在我的网站上有一个虚拟商店 . 我正在使用paypal进行购买操作 . 我已经考虑过允许客户使用信用卡而无需使用PayPal账户,我正在尝试使用自适应支付流程来允许“以客户身份购买”流程 . 我正在尝试使用paypal默认流程(而不是其余的api)因为我不想担心处理信用卡数据并且不得不将我的网站设计为PCI兼容 .
所以这个场景就是我正在使用的:
- 来自此网站https://developer.paypal.com/webapps/developer/docs/classic/adaptive-payments/integration-guide/APIntro/我正在尝试实施该部分指定的付款流程
设置网页以使用灯箱调用嵌入式支付流程
- 由于此付款流程需要生成付款密钥,因此我使用此链接上的代码:
https://github.com/paypal/rest-api-sdk-dotnet/tree/master/Samples/RestApiSample
- 因此,在我的MVC上,我有一个生成订单的页面,它调用Helper方法来获取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 "";
}
- 获得此密钥后,我从另一个视图中获取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的方法 . 有没有办法获得这些钥匙?
非常感谢
2 回答
这真是令人尴尬......但真正的问题是表格后期行动的网址 . 我有
哪个是 生产环境 链接 . 而且我还没有上线,我正在使用paypal api凭证用于sanbox帐户,所以真正的表单操作应该是:
咄!希望这可以帮助另一个人犯同样的错误 .
非常感谢@Andrew Angell
听起来您正在使用Pay请求发送Preapproval密钥 . 当您这样做时,不需要重定向到PayPal . 这就是重点...您已经通过预批准密钥获得批准,因此当您提交包含预先批准密钥的付款请求时,付款将立即进行(只要预批准配置文件仍然有效 . )
因此,当您进行重定向时,它会告诉您到底发生了什么......交易已经处理完毕 . 同样,不需要重定向 .
重点是能够在您需要任何重定向或进一步批准的任何时候使用您的应用程序中的预批准配置文件触发付款 . 获得该预批准密钥后,您可以按照自己的方式触发付款 . 例如,您可能希望每次使用时向某人收取费用,并在他们登录您的网站时触发付款,但您不希望他们每次都必须批准付款 . 付款可以通过Pay API在后台进行,包括预先批准密钥,但用户根本不会被中断 .
希望有所帮助 .