public string ProcessSubmitButton(IList <ShoppingCartItem> cart, TempDataDictionary tempData) { using (var payPalApiaaInterface = _payPalInterfaceService.GetAAService()) { var customSecurityHeaderType = _payPalSecurityService.GetRequesterCredentials(); var setExpressCheckoutResponse = payPalApiaaInterface.SetExpressCheckout( ref customSecurityHeaderType, _payPalRequestService.GetSetExpressCheckoutRequest(cart)); var result = new ProcessPaymentResult(); var redirectUrl = string.Empty; setExpressCheckoutResponse.HandleResponse(result, (paymentResult, type) => { var token = setExpressCheckoutResponse.Token; redirectUrl = _payPalUrlService.GetExpressCheckoutRedirectUrl(token); }, (paymentResult, type) => { _logger.InsertLog(LogLevel.Error, "Error passing cart to PayPal", string.Join(", ", setExpressCheckoutResponse.Errors.Select( errorType => errorType.ErrorCode + ": " + errorType.LongMessage))); tempData["paypal-ec-error"] = "An error occurred setting up your cart for PayPal."; redirectUrl = _webHelper.GetUrlReferrer(); }, Guid.Empty); return(redirectUrl); } }
/// <summary> /// Process a payment /// </summary> /// <param name="processPaymentRequest">Payment info required for an order processing</param> /// <returns>Process payment result</returns> public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest) { var customSecurityHeaderType = _payPalSecurityService.GetRequesterCredentials(); using (var payPalApiaaInterfaceClient = _payPalInterfaceService.GetAAService()) { var doExpressCheckoutPaymentResponseType = payPalApiaaInterfaceClient.DoExpressCheckoutPayment(ref customSecurityHeaderType, _payPalRequestService.GetDoExpressCheckoutPaymentRequest(processPaymentRequest)); _session.Set("express-checkout-response-type", doExpressCheckoutPaymentResponseType); return(doExpressCheckoutPaymentResponseType.HandleResponse(new ProcessPaymentResult(), (paymentResult, type) => { paymentResult.NewPaymentStatus = _payPalExpressCheckoutPaymentSettings.PaymentAction == PaymentActionCodeType.Authorization ? PaymentStatus.Authorized : PaymentStatus.Paid; paymentResult.AuthorizationTransactionId = processPaymentRequest.CustomValues["PaypalToken"].ToString(); var paymentInfoType = type.DoExpressCheckoutPaymentResponseDetails.PaymentInfo.FirstOrDefault(); if (paymentInfoType != null) { paymentResult.CaptureTransactionId = paymentInfoType.TransactionID; } paymentResult.CaptureTransactionResult = type.Ack.ToString(); }, (paymentResult, type) => { paymentResult.NewPaymentStatus = PaymentStatus.Pending; type.Errors.AddErrors(paymentResult.AddError); paymentResult.AddError(type.DoExpressCheckoutPaymentResponseDetails.RedirectRequired); }, processPaymentRequest.OrderGuid)); } }