/// <summary> /// Executes the charge operation. /// </summary> /// <param name="paymentInfo">The payment info.</param> public void ExecuteCharge(PaymentInfo paymentInfo) { try { // If the order is already reserved, CanCompleteTransaction will be true. // Call complete transaction on the already reserved order, else call direct charge customer account. if (paymentInfo.PaymentProvider.CanCompleteCurrentTransaction) { PayPalCompletePaymentArgs completePaymentArgs = new PayPalCompletePaymentArgs( CompleteType.Complete, paymentInfo.TotalAmountWithVAT, paymentInfo.Order.Currency.CurrencyCode, paymentInfo.Order.ExternalOrderID, string.Empty); paymentInfo.PaymentProvider.CompletePayment(completePaymentArgs, FoundationContext.Token); //redirect to view payment. Response.Redirect(UrlConstants.VIEW_PAYMENT + "?" + ParameterConstants.ECOM_SELECTED_NAVBAR_PAGE + "=" + ((int)Enums.FilterType.Payments).ToString() + "&" + ParameterConstants.FROM_PAYMENT + "=true&" + ParameterConstants.ECOM_ORDER_ID + "=" + paymentInfo.OrderID + "&" + ParameterConstants.ECOM_PAYMENT_INFO_ID + "=" + paymentInfo.ID + "&" + ParameterConstants.QUERY_STRING_NAVIGATE_FROM + "=2"); } else { PayPalExecutePaymentArgs args = new PayPalExecutePaymentArgs(UrlConstants.PAYMENT_SUCCESS, UrlConstants.PAYMENT_CANCEL, FoundationContext.Culture.Name); args.PaymentMode = ExecutePaymentMode.Charge; args.UserHostAddress = Request.UserHostAddress; //add redirect script on success. args.ExecuteScript = new PayPalExecutePaymentArgs.ExecuteScriptHandler(delegate(string scriptArgs, bool redirect) { if (redirect) Response.Redirect(scriptArgs, true); }); PayPalExecutePaymentResult result = (PayPalExecutePaymentResult)paymentInfo.PaymentProvider.ExecutePayment(args, FoundationContext.Token); if (!result.Success) { Response.Redirect(UrlConstants.VIEW_PAYMENT + "?" + ParameterConstants.ECOM_SELECTED_NAVBAR_PAGE + "=" + ((int)Litium.Studio.UI.ECommerce.Common.Enums.FilterType.Payments).ToString() + "&" + ParameterConstants.FROM_PAYMENT + "=true&" + ParameterConstants.ECOM_ORDER_ID + "=" + paymentInfo.OrderID + "&" + ParameterConstants.ECOM_PAYMENT_INFO_ID + "=" + paymentInfo.ID + "&" + ParameterConstants.QUERY_STRING_NAVIGATE_FROM + "=2"); } } } catch (PaymentProviderException) { } }
/// <summary> /// Executes the reserve operation. /// </summary> /// <param name="paymentInfo">The payment info.</param> public void ExecuteReserve(PaymentInfo paymentInfo) { try { PayPalExecutePaymentArgs args = new PayPalExecutePaymentArgs(UrlConstants.PAYMENT_SUCCESS, UrlConstants.PAYMENT_CANCEL, FoundationContext.Culture.Name); args.PaymentMode = ExecutePaymentMode.Reserve; args.UserHostAddress = Request.UserHostAddress; args.ExecuteScript = new PayPalExecutePaymentArgs.ExecuteScriptHandler(delegate(string scriptArgs, bool redirect) { if (redirect) Response.Redirect(scriptArgs, true);}); PayPalExecutePaymentResult result = (PayPalExecutePaymentResult)paymentInfo.PaymentProvider.ExecutePayment(args, FoundationContext.Token); if (!result.Success) { Response.Redirect(UrlConstants.VIEW_PAYMENT + "?" + ParameterConstants.ECOM_SELECTED_NAVBAR_PAGE + "=" + ((int)Litium.Studio.UI.ECommerce.Common.Enums.FilterType.Payments).ToString() + "&" + ParameterConstants.FROM_PAYMENT + "=true&" + ParameterConstants.ECOM_ORDER_ID + "=" + paymentInfo.OrderID + "&" + ParameterConstants.ECOM_PAYMENT_INFO_ID + "=" + paymentInfo.ID + "&" + ParameterConstants.QUERY_STRING_NAVIGATE_FROM + "=2"); } } catch (PaymentProviderException) { } }
/// <summary> /// Creates the payment args. /// </summary> /// <param name="checkoutFlowInfo">The checkout flow info.</param> /// <returns>Instance of <see cref="ExecutePaymentArgs"/> if checkout info can be /// converted to <see cref="ExtendedCheckoutFlowInfo"/> else a null reference.</returns> public virtual ExecutePaymentArgs CreatePaymentArgs(CheckoutFlowInfo checkoutFlowInfo) { PayPalExecutePaymentArgs args = new PayPalExecutePaymentArgs(); ExtendedCheckoutFlowInfo info = checkoutFlowInfo as ExtendedCheckoutFlowInfo; if (info != null) { args.CancelUrl = info.CancelUrl; args.ResponseUrl = info.ResponseUrl; args.ClientLanguage = CurrentState.Current.WebSite.Culture.Name; args.ExecuteScript = new PayPalExecutePaymentArgs.ExecuteScriptHandler(info.ExecuteScript); //store end-users IP address HttpContext currentContext = HttpContext.Current; if (currentContext != null && currentContext.Request != null) args.UserHostAddress = HttpContext.Current.Request.UserHostAddress; //set the payment mode if its being set, otherwise leave it at its default value. if (checkoutFlowInfo.ExecutePaymentMode != ExecutePaymentMode.Unset) args.PaymentMode = checkoutFlowInfo.ExecutePaymentMode; } return args; }