我们正在使用PayPal AdaptivePayments SDK一段时间,
现在,与之前相同的网址会在50%的时间内通过302临时重定向将客户重定向到paypal主页。
https://www.paypal.com/webscr&cmd=_ap-payment&paykey=XXXXXXXXXX
代码主要是来自paypal示例的副本
public override string CreateRedirectUrl(NameValueCollection parameters)
{
ReceiverList receiverList = new ReceiverList();
receiverList.receiver = new List<Receiver>();
PayRequest request = new PayRequest();
RequestEnvelope requestEnvelope = new RequestEnvelope("en_CA");
request.requestEnvelope = requestEnvelope;
request.feesPayer = "PRIMARYRECEIVER";
//request.feesPayer = "SECONDARYONLY";
Receiver receiver1 = new Receiver();
if (parameters["amount1"] != null && parameters["amount1"].Trim() != string.Empty)
{
// Required) Amount to be paid to the receiver
receiver1.amount = Convert.ToDecimal(parameters["amount1"].ToString(), CultureInfo.InvariantCulture);
}
if (parameters["mail1"] != null && parameters["mail1"].Trim() != string.Empty)
{
// 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
receiver1.email = parameters["mail1"];
}
//if (parameters["primaryReceiver1"] != null && parameters["primaryReceiver1"].Trim() != string.Empty)
//{
// receiver1.primary = Convert.ToBoolean(parameters["primaryReceiver1"]);
//}
receiver1.primary = true;
receiver1.invoiceId = parameters["invoiceId"];
receiverList.receiver.Add(receiver1);
Receiver receiver2 = new Receiver();
if (parameters["amount2"] != null && parameters["amount2"].Trim() != string.Empty)
{
// (Required) Amount to be paid to the receiver
receiver2.amount = Convert.ToDecimal(parameters["amount2"], CultureInfo.InvariantCulture);
}
if (parameters["mail2"] != null && parameters["mail2"].Trim() != string.Empty)
{
// 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
receiver2.email = parameters["mail2"];
}
//if (parameters["primaryReceiver2"] != null && parameters["primaryReceiver2"].Trim() != string.Empty)
//{
// receiver2.primary = Convert.ToBoolean(parameters["primaryReceiver2"]);
//}
receiverList.receiver.Add(receiver2);
ReceiverList receiverlst = new ReceiverList(receiverList.receiver);
request.receiverList = receiverlst;
// (Optional) Sender's email address. Maximum length: 127 characters
if (parameters["senderEmail"] != null && parameters["senderEmail"].Trim() != string.Empty)
{
request.senderEmail = parameters["senderEmail"];
}
// The action for this request. Possible values are: PAY – Use this
// option if you are not using the Pay request in combination with
// ExecutePayment. CREATE – Use this option to set up the payment
// instructions with SetPaymentOptions and then execute the payment at a
// later time with the ExecutePayment. PAY_PRIMARY – For chained
// payments only, specify this value to delay payments to the secondary
// receivers; only the payment to the primary receiver is processed.
//if (parameters["actionType"] != null && parameters["actionType"].Trim() != string.Empty)
//{
// request.actionType = parameters["actionType"];
//}
request.actionType = "PAY";
// URL to redirect the sender's browser to after canceling the approval
// for a payment; it is always required but only used for payments that
// require approval (explicit payments)
if (parameters["cancelURL"] != null && parameters["cancelURL"].Trim() != string.Empty)
{
request.cancelUrl = parameters["cancelURL"];
}
// The code for the currency in which the payment is made; you can
// specify only one currency, regardless of the number of receivers
if (parameters["currencyCode"] != null && parameters["currencyCode"].Trim() != string.Empty)
{
request.currencyCode = parameters["currencyCode"];
}
// URL to redirect the sender's browser to after the sender has logged
// into PayPal and approved a payment; it is always required but only
// used if a payment requires explicit approval
if (parameters["returnURL"] != null && parameters["returnURL"].Trim() != string.Empty)
{
request.returnUrl = parameters["returnURL"];
}
request.requestEnvelope = requestEnvelope;
// (Optional) The URL to which you want all IPN messages for this
// payment to be sent. Maximum length: 1024 characters
if (parameters["ipnNotificationURL"] != null && parameters["ipnNotificationURL"].Trim() != string.Empty)
{
request.ipnNotificationUrl = parameters["ipnNotificationURL"];
}
AdaptivePaymentsService service = null;
try
{
// Configuration map containing signature credentials and other required configuration.
// For a full list of configuration parameters refer in wiki page
// (https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters)
Dictionary<string, string> configurationMap = PaypalAdaptiveConfiguration.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 (System.Exception ex)
{
// contextHttp.Response.Write(ex.Message);
//return;
}
Dictionary<string, string> responseValues = new Dictionary<string, string>();
string redirectUrl = null;
if (!Response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILURE.ToString()) && !Response.responseEnvelope.ack.ToString().Trim().ToUpper().Equals(AckCode.FAILUREWITHWARNING.ToString()))
{
if (ConfigurationManager.AppSettings["PAYPAL_MODE"].ToLower() == "live")
{
redirectUrl = ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL_LIVE"] + "_ap-payment&paykey=" + Response.payKey;
}
else
{
redirectUrl = ConfigurationManager.AppSettings["PAYPAL_REDIRECT_URL"] + "_ap-payment&paykey=" + Response.payKey;
}
// The pay key, which is a token you use in other Adaptive Payment APIs
// (such as the Refund Method) to identify this payment.
// The pay key is valid for 3 hours; the payment must be approved while the
// pay key is valid.
responseValues.Add("Pay Key", Response.payKey);
// The status of the payment. Possible values are:
// CREATED – The payment request was received; funds will be transferred once the payment is approved
// COMPLETED – The payment was successful
// INCOMPLETE – Some transfers succeeded and some failed for a parallel payment or, for a delayed chained payment, secondary receivers have not been paid
// ERROR – The payment failed and all attempted transfers failed or all completed transfers were successfully reversed
// REVERSALERROR – One or more transfers failed when attempting to reverse a payment
// PROCESSING – The payment is in progress
// PENDING – The payment is awaiting processing
responseValues.Add("Payment Execution Status", Response.paymentExecStatus);
if (Response.defaultFundingPlan != null && Response.defaultFundingPlan.senderFees != null)
{
// Fees to be paid by the sender
responseValues.Add("Sender Fees", Response.defaultFundingPlan.senderFees.amount + Response.defaultFundingPlan.senderFees.code);
}
}
foreach (ErrorData ed in Response.error)
{
this.ErrorMessage += ed.message + " ";
}
if (!string.IsNullOrWhiteSpace(this.ErrorMessage))
{
new Tracker().sendToGenclikDev("PaypalAdaptiveGateway", this.ErrorMessage);
}
responseValues.Add("Acknowledgement", Response.responseEnvelope.ack.ToString().Trim().ToUpper());
return redirectUrl;
}
答案 0 :(得分:2)
我们也有同样的问题,但能够通过做一些小改动来解决它。
您需要更改重定向网址:
从此: https://www.paypal.com/webscr&cmd=_ap-payment&paykey=XXXXXXXXXX
要强> https://www.paypal.com/webscr?cmd=_ap-payment&paykey=XXXXXXXXXX
请注意'webscr'之后的“?”。
答案 1 :(得分:1)
自2017年1月13日星期五以来,我们遇到了完全相同的问题。它似乎主要发生在第一次付款重定向请求中。如果您从Paypal主屏幕导航回来,使用浏览器的后退按钮并再次使用新令牌发布,则可以正常工作。
任何知道解决方案的人都会有很大的帮助!