private ActionResult ProcessingResult_PayPal(ProcessingResultModel model) { if (model == null) { throw new System.ArgumentNullException("model"); } PaymentResultContext context = new PaymentResultContext(); context.Order = model.order; if (model.success == true) { if (model.token == null) { throw new System.ArgumentNullException("token"); } if (model.payerID == null) { throw new System.ArgumentNullException("payerID"); } GetExpressCheckoutDetailsRequestType request = new GetExpressCheckoutDetailsRequestType(); request.Version = "104.0"; request.Token = model.token; GetExpressCheckoutDetailsReq wrapper = new GetExpressCheckoutDetailsReq(); wrapper.GetExpressCheckoutDetailsRequest = request; System.Collections.Generic.Dictionary <string, string> config = PaymentController.PayPal_CreateConfig(); PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(config); GetExpressCheckoutDetailsResponseType ecResponse = service.GetExpressCheckoutDetails(wrapper); if (ecResponse == null) { throw new System.Exception("checkout details result is null"); } if (ecResponse.Errors != null && ecResponse.Errors.Count > 0) { ecResponse.Errors.ForEach(delegate(ErrorType m) { context.Errors.Add(m.LongMessage); }); } if (ecResponse.Ack == AckCodeType.SUCCESS || ecResponse.Ack == AckCodeType.SUCCESSWITHWARNING) { GetExpressCheckoutDetailsResponseDetailsType details = ecResponse.GetExpressCheckoutDetailsResponseDetails; if (details == null) { throw new System.Exception("details object is null"); } if (string.IsNullOrEmpty(details.InvoiceID)) { throw new System.Exception("invoiceID not found"); } if (details.PaymentDetails == null) { throw new System.Exception("payment details is null"); } System.Collections.Generic.List <PaymentDetailsType> paymentDetails = new System.Collections.Generic.List <PaymentDetailsType>(); foreach (PaymentDetailsType payment in details.PaymentDetails) { paymentDetails.Add(new PaymentDetailsType { NotifyURL = null, PaymentAction = payment.PaymentAction, OrderTotal = payment.OrderTotal }); } DoExpressCheckoutPaymentRequestType paymentRequest = new DoExpressCheckoutPaymentRequestType(); paymentRequest.Version = "104.0"; paymentRequest.DoExpressCheckoutPaymentRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType { PaymentDetails = paymentDetails, Token = model.token, PayerID = model.payerID }; DoExpressCheckoutPaymentResponseType doECResponse = service.DoExpressCheckoutPayment(new DoExpressCheckoutPaymentReq { DoExpressCheckoutPaymentRequest = paymentRequest }); if (doECResponse == null) { throw new System.Exception("payment result is null"); } if (doECResponse.Errors != null && doECResponse.Errors.Count > 0) { doECResponse.Errors.ForEach(delegate(ErrorType m) { context.Errors.Add(m.LongMessage); }); } if (doECResponse.Ack == AckCodeType.SUCCESS || doECResponse.Ack == AckCodeType.SUCCESSWITHWARNING) { ConfirmInvoiceResult invoiceResult = BookingProvider.ConfirmInvoice(details.InvoiceID.Trim()); Tracing.DataTrace.TraceEvent(TraceEventType.Information, 0, "PAYPAL transaction: invoice: '{0}', invoice confirmation: '{1}'", new object[] { details.InvoiceID, invoiceResult.IsSuccess ? "SUCCESS" : "FAILED" }); if (!invoiceResult.IsSuccess) { context.Errors.Add(string.Format("invoice confirmation error: {0}", invoiceResult.ErrorMessage)); } else { context.Success = true; BookingProvider.AcceptInvoice(Convert.ToInt32(context.Order)); } } } } else { context.Errors.Add(PaymentStrings.PaymentCancelled); } return(base.View("_ProcessingResult", context)); }
private ActionResult Processing_PayPal(int claim, PaymentMode payment) { if (payment == null) { throw new System.ArgumentNullException("payment"); } PaymentBeforeProcessingResult beforePaymentResult = BookingProvider.BeforePaymentProcessing(UrlLanguage.CurrentLanguage, payment.paymentparam); if (beforePaymentResult == null) { throw new System.Exception("cannot get payment details"); } if (!beforePaymentResult.success) { throw new System.Exception("payment details fail"); } System.Collections.Generic.List <PaymentDetailsType> paymentDetails = new System.Collections.Generic.List <PaymentDetailsType>(); PaymentDetailsType paymentDetail = new PaymentDetailsType(); paymentDetail.AllowedPaymentMethod = new AllowedPaymentMethodType?(AllowedPaymentMethodType.ANYFUNDINGSOURCE); CurrencyCodeType currency = (CurrencyCodeType)EnumUtils.GetValue(payment.payrest.currency, typeof(CurrencyCodeType)); PaymentDetailsItemType paymentItem = new PaymentDetailsItemType(); paymentItem.Name = string.Format(PaymentStrings.ResourceManager.Get("PaymentForOrderFormat"), claim); paymentItem.Amount = new BasicAmountType(new CurrencyCodeType?(currency), payment.payrest.total.ToString("#.00", System.Globalization.NumberFormatInfo.InvariantInfo)); paymentItem.Quantity = new int?(1); paymentItem.ItemCategory = new ItemCategoryType?(ItemCategoryType.PHYSICAL); paymentItem.Description = string.Format("Booking #{0}", claim); paymentDetail.PaymentDetailsItem = new System.Collections.Generic.List <PaymentDetailsItemType> { paymentItem }; paymentDetail.PaymentAction = new PaymentActionCodeType?(PaymentActionCodeType.SALE); paymentDetail.OrderTotal = new BasicAmountType(paymentItem.Amount.currencyID, paymentItem.Amount.value); paymentDetails.Add(paymentDetail); SetExpressCheckoutRequestDetailsType ecDetails = new SetExpressCheckoutRequestDetailsType(); ecDetails.ReturnURL = new Uri(base.Request.BaseServerAddress(), base.Url.Action("processingresult", new { id = "paypal", success = true })).ToString(); ecDetails.CancelURL = new Uri(base.Request.BaseServerAddress(), base.Url.Action("processingresult", new { id = "paypal", success = false })).ToString(); ecDetails.NoShipping = "1"; ecDetails.AllowNote = "0"; ecDetails.SolutionType = new SolutionTypeType?(SolutionTypeType.SOLE); ecDetails.SurveyEnable = "0"; ecDetails.PaymentDetails = paymentDetails; ecDetails.InvoiceID = beforePaymentResult.invoiceNumber; SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType(); request.Version = "104.0"; request.SetExpressCheckoutRequestDetails = ecDetails; SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq(); wrapper.SetExpressCheckoutRequest = request; System.Collections.Generic.Dictionary <string, string> config = PaymentController.PayPal_CreateConfig(); PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(config); SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper); System.Collections.Generic.KeyValuePair <string, string> sandboxConfig = config.FirstOrDefault((System.Collections.Generic.KeyValuePair <string, string> m) => m.Key == "mode"); string sandboxServer = (sandboxConfig.Key != null && sandboxConfig.Value == "sandbox") ? ".sandbox" : ""; return(base.View("PaymentSystems\\PayPal", new ProcessingContext { Reservation = BookingProvider.GetReservationState(UrlLanguage.CurrentLanguage, claim), PaymentMode = payment, BeforePaymentResult = beforePaymentResult, RedirectUrl = string.Format("https://www{0}.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={1}", sandboxServer, base.Server.UrlEncode(setECResponse.Token)) })); // return new RedirectResult(string.Format("https://www{0}.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token={1}", sandboxServer, base.Server.UrlEncode(setECResponse.Token))); }