本文整理汇总了C#中ProcessorArgumentCollection.GetReturnUrl方法的典型用法代码示例。如果您正苦于以下问题:C# ProcessorArgumentCollection.GetReturnUrl方法的具体用法?C# ProcessorArgumentCollection.GetReturnUrl怎么用?C# ProcessorArgumentCollection.GetReturnUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ProcessorArgumentCollection
的用法示例。
在下文中一共展示了ProcessorArgumentCollection.GetReturnUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializePayment
/// <summary>
/// Processes the Authorize and AuthorizeAndCapture transactions
/// </summary>
/// <param name="invoice">The <see cref="IInvoice"/> to be paid</param>
/// <param name="payment">The <see cref="IPayment"/> record</param>
/// <param name="args"></param>
/// <returns>The <see cref="IPaymentResult"/></returns>
public IPaymentResult InitializePayment(IInvoice invoice, IPayment payment, ProcessorArgumentCollection args) {
var setExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
Func<string, string> adjustUrl = (url) => {
if (!url.StartsWith("http")) url = GetWebsiteUrl() + (url[0] == '/' ? "" : "/") + url;
url = url.Replace("{invoiceKey}", invoice.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
url = url.Replace("{paymentKey}", payment.Key.ToString(), StringComparison.InvariantCultureIgnoreCase);
url = url.Replace("{paymentMethodKey}", payment.PaymentMethodKey.ToString(), StringComparison.InvariantCultureIgnoreCase);
return url;
};
// Save ReturnUrl and CancelUrl in ExtendedData.
// They will be usefull in PayPalApiController.
var returnUrl = args.GetReturnUrl();
if (returnUrl.IsEmpty()) returnUrl = _settings.ReturnUrl;
if (returnUrl.IsEmpty()) returnUrl = "/";
returnUrl = adjustUrl(returnUrl);
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.ReturnUrl, returnUrl);
var cancelUrl = args.GetCancelUrl();
if (cancelUrl.IsEmpty()) cancelUrl = _settings.CancelUrl;
if (cancelUrl.IsEmpty()) cancelUrl = "/";
cancelUrl = adjustUrl(cancelUrl);
payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.CancelUrl, cancelUrl);
// Set ReturnUrl and CancelUrl of PayPal request to PayPalApiController.
setExpressCheckoutRequestDetails.ReturnURL = adjustUrl("/umbraco/MerchelloPayPal/PayPalApi/SuccessPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");
setExpressCheckoutRequestDetails.CancelURL = adjustUrl("/umbraco/MerchelloPayPal/PayPalApi/AbortPayment?InvoiceKey={invoiceKey}&PaymentKey={paymentKey}");
//setExpressCheckoutRequestDetails.OrderDescription = "#" + invoice.InvoiceNumber;
setExpressCheckoutRequestDetails.PaymentDetails = new List<PaymentDetailsType> { CreatePayPalPaymentDetails(invoice, args) };
var setExpressCheckout = new SetExpressCheckoutReq() {
SetExpressCheckoutRequest = new SetExpressCheckoutRequestType(setExpressCheckoutRequestDetails)
};
try {
var response = GetPayPalService().SetExpressCheckout(setExpressCheckout);
if (response.Ack != AckCodeType.SUCCESS && response.Ack != AckCodeType.SUCCESSWITHWARNING) {
return new PaymentResult(Attempt<IPayment>.Fail(payment, CreateErrorResult(response.Errors)), invoice, false);
}
var redirectUrl = string.Format("https://www.{0}paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={1}", (_settings.LiveMode ? "" : "sandbox."), response.Token);
payment.ExtendedData.SetValue("RedirectUrl", redirectUrl);
return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);
} catch (Exception ex) {
return new PaymentResult(Attempt<IPayment>.Fail(payment, ex), invoice, true);
}
}