【发布时间】:2015-05-03 17:16:57
【问题描述】:
我正在我的 asp.net mvc 应用程序中集成快速结帐。一切正常,响应成功,但是当我尝试调用“GetExpressCheckoutDetailsResponseDetails”时,“PayerID”中的值为空。下面的字段是“requestDetails.PayerID”
public ActionResult PayPalExpressCheckout()
{
PaymentDetailsType paymentDetail = new PaymentDetailsType();
CurrencyCodeType currency = (CurrencyCodeType)EnumUtils.GetValue("GBP", typeof(CurrencyCodeType));
List<PaymentDetailsItemType> paymentItems = new List<PaymentDetailsItemType>();
var AppCart = GetAppCart();
foreach(var item in AppCart.Items)
{
PaymentDetailsItemType paymentItem = new PaymentDetailsItemType();
paymentItem.Name = item.Name;
paymentItem.Description = item.Description;
double itemAmount = Convert.ToDouble(item.Price);
paymentItem.Amount = new BasicAmountType(CurrencyCodeType.GBP, itemAmount.ToString());
paymentItem.Quantity = 1;
paymentItems.Add(paymentItem);
}
paymentDetail.PaymentDetailsItem = paymentItems;
paymentDetail.PaymentAction = (PaymentActionCodeType)EnumUtils.GetValue("Sale", typeof(PaymentActionCodeType));
paymentDetail.OrderTotal = new BasicAmountType(CurrencyCodeType.GBP, (AppCart.TotalPrice).ToString());
List<PaymentDetailsType> paymentDetails = new List<PaymentDetailsType>();
paymentDetails.Add(paymentDetail);
SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType();
ecDetails.ReturnURL = "http://Orchard.Club/Purchase/PayPalExpressCheckoutAuthorisedSuccess";
ecDetails.CancelURL = "http://Orchard.Club/Purchase/CancelPayPalTransaction";
ecDetails.PaymentDetails = paymentDetails;
SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();
ecDetails.FundingSourceDetails = new FundingSourceDetailsType();
//request.Version = "104.0";
ecDetails.LandingPage = LandingPageType.BILLING;
ecDetails.SolutionType = SolutionTypeType.SOLE;
ecDetails.FundingSourceDetails.UserSelectedFundingSource = UserSelectedFundingSourceType.CREDITCARD;
request.SetExpressCheckoutRequestDetails = ecDetails;
SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();
wrapper.SetExpressCheckoutRequest = request;
Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
sdkConfig.Add("mode", "sandbox");
sdkConfig.Add("account1.apiUsername", "mrhammad-facilitator_api1.hotmail.com");
sdkConfig.Add("account1.apiPassword", "1369812511");
sdkConfig.Add("account1.apiSignature", "AJxdrs7c7cXRinyNUS5p1V4s1m4uAGR.wOJ7KzgkewEYmTOOtHrPgSxR");
PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(sdkConfig);
SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper);
if (setECResponse.Ack.Equals(AckCodeType.SUCCESS))
{
GetExpressCheckoutDetailsReq getECWrapper = new GetExpressCheckoutDetailsReq();
// (Required) A timestamped token, the value of which was returned by SetExpressCheckout response.
// Character length and limitations: 20 single-byte characters
getECWrapper.GetExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType(setECResponse.Token);
// # API call
// Invoke the GetExpressCheckoutDetails method in service wrapper object
GetExpressCheckoutDetailsResponseType getECResponse = service.GetExpressCheckoutDetails(getECWrapper);
// Create request object
DoExpressCheckoutPaymentRequestType expressrequest = new DoExpressCheckoutPaymentRequestType();
DoExpressCheckoutPaymentRequestDetailsType requestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
expressrequest.DoExpressCheckoutPaymentRequestDetails = requestDetails;
requestDetails.PaymentDetails = getECResponse.GetExpressCheckoutDetailsResponseDetails.PaymentDetails;
// (Required) The timestamped token value that was returned in the SetExpressCheckout response and passed in the GetExpressCheckoutDetails request.
requestDetails.Token = setECResponse.Token;
// (Required) Unique PayPal buyer account identification number as returned in the GetExpressCheckoutDetails response
requestDetails.PayerID = requestDetails.PayerID;
// (Required) How you want to obtain payment. It is one of the following values:
// * Authorization – This payment is a basic authorization subject to settlement with PayPal Authorization and Capture.
// * Order – This payment is an order authorization subject to settlement with PayPal Authorization and Capture.
// * Sale – This is a final sale for which you are requesting payment.
// Note: You cannot set this value to Sale in the SetExpressCheckout request and then change this value to Authorization in the DoExpressCheckoutPayment request.
requestDetails.PaymentAction = (PaymentActionCodeType)
Enum.Parse(typeof(PaymentActionCodeType), "SALE");
// Invoke the API
DoExpressCheckoutPaymentReq expresswrapper = new DoExpressCheckoutPaymentReq();
expresswrapper.DoExpressCheckoutPaymentRequest = expressrequest;
// # API call
// Invoke the DoExpressCheckoutPayment method in service wrapper object
DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(expresswrapper);
// Check for API return status
if (doECResponse.Ack.Equals(AckCodeType.FAILURE) ||
(doECResponse.Errors != null && doECResponse.Errors.Count > 0))
{
return RedirectToAction("PostPaymentFailure");
}
else
{
TempData["TransactionResult"] = "Transaction ID:" + doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].TransactionID + Environment.NewLine + "Payment status" + doECResponse.DoExpressCheckoutPaymentResponseDetails.PaymentInfo[0].PaymentStatus.Value.ToString();
return RedirectToAction("SaveCustomer", "SignupOrLogin");
}
}
else
{
return RedirectToAction("Error", "Purchase");
}
}
【问题讨论】:
-
嗯...您的代码示例显示您在一个序列中调用 Set、Get 和 DoEC。如果是这样,那就是你的问题。如果您没有将用户重定向到 PayPal 以表明自己的身份,您希望在 SetEC 和 GetEC 之间提供客户的付款信息有什么魔力? :)
标签: c# asp.net paypal paypal-sandbox