protected void btnProcessPayment_Click(object sender, EventArgs e)
    {
        if (PaymentGatewayProvider != null && PaymentGatewayProvider.OrderId > 0)
        {
            // Validate data if web part is not placed in wizard
            if (!String.IsNullOrEmpty(mPaymentDataForm.ValidateData()))
            {
                // Do not continue if validation failed
                return;
            }

            // Prevent duplicit payment
            if (PaymentGatewayProvider.IsPaymentCompleted)
            {
                ShowError(ResHelper.GetString("paymentgateway.form.duplicitpayment"));
                return;
            }

            PaymentResultInfo result = null;

            // Skip payment when user is not authorized
            if (PaymentGatewayProvider.IsUserAuthorizedToFinishPayment(MembershipContext.AuthenticatedUser, ShoppingCart, !IsLiveSite))
            {
                var data = mPaymentDataForm.GetPaymentGatewayData();
                result = Service.Resolve <IPaymentGatewayProcessor>().ProcessPayment(PaymentGatewayProvider, data);
            }

            // Show info message
            if (!string.IsNullOrEmpty(PaymentGatewayProvider.InfoMessage))
            {
                lblInfo.Visible = true;
                lblInfo.Text    = PaymentGatewayProvider.InfoMessage;
            }

            // Show error message
            if (!string.IsNullOrEmpty(PaymentGatewayProvider.ErrorMessage))
            {
                ShowError(PaymentGatewayProvider.ErrorMessage);
            }

            if (PaymentGatewayProvider.UseDelayedPayment())
            {
                // Process succesfull authorization of delayed payment
                HandleDelayedPaymentResult(result);
            }
            else
            {
                // Redirect after successful direct payment
                HandleDirectPaymentResult(result);
            }
        }
    }
Exemple #2
0
    public override bool ProcessStep()
    {
        if (ShoppingCartControl.PaymentGatewayProvider != null)
        {
            // Skip payment when already paid except when editing existing order or user is not authorized
            if (((!IsPaymentCompletedOrAuthorized()) || (ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems)) &&
                ShoppingCartControl.PaymentGatewayProvider.IsUserAuthorizedToFinishPayment(MembershipContext.AuthenticatedUser, ShoppingCartControl.ShoppingCartInfoObj, !IsLiveSite))
            {
                var data = mPaymentDataForm.GetPaymentGatewayData();
                mPaymentResult = Service.Resolve <IPaymentGatewayProcessor>().ProcessPayment(ShoppingCartControl.PaymentGatewayProvider, data);
            }

            // Show info message
            if (!string.IsNullOrEmpty(ShoppingCartControl.PaymentGatewayProvider.InfoMessage))
            {
                lblInfo.Visible = true;
                lblInfo.Text    = ShoppingCartControl.PaymentGatewayProvider.InfoMessage;
            }

            // Show error message
            if (!string.IsNullOrEmpty(ShoppingCartControl.PaymentGatewayProvider.ErrorMessage))
            {
                lblError.Visible = true;
                lblError.Text    = ShoppingCartControl.PaymentGatewayProvider.ErrorMessage;
                return(false);
            }

            if (IsPaymentCompleted())
            {
                // Delete current shopping cart after successful payment attempt
                ShoppingCartControl.CleanUpShoppingCart();

                // Raise payment completed event
                ShoppingCartControl.RaisePaymentCompletedEvent();

                return(true);
            }

            if (IsPaymentAuthorized())
            {
                ShoppingCartControl.CleanUpShoppingCart();

                return(true);
            }
        }

        return(false);
    }