/// <summary>
    /// Checks whether the payment option is valid for current user.
    /// </summary>
    /// <param name="shoppingCart">The shopping cart.</param>
    /// <param name="message">The message in case of failure.</param>
    protected bool CheckPaymentOptionIsValidForUser(ShoppingCartInfo shoppingCart, out string message)
    {
        message = string.Empty;
        CMSPaymentGatewayProvider provider = CMSPaymentGatewayProvider.GetPaymentGatewayProvider(shoppingCart.ShoppingCartPaymentOptionID);

        if ((provider != null) && (!provider.IsUserAuthorizedToFinishPayment(shoppingCart.User, shoppingCart)))
        {
            message = provider.ErrorMessage;
            return(false);
        }

        return(true);
    }
Beispiel #2
0
    private void ExecutePayment()
    {
        if (mOrderGuid == Guid.Empty || StopProcessing || RequestHelper.IsCallback())
        {
            return;
        }

        if (String.IsNullOrEmpty(mPaymentId) || String.IsNullOrEmpty(mPayerId))
        {
            // Payment parameters not specified
            LogEvent(null, "Payment_Parameters_Not_Specified");

            return;
        }

        var order = OrderInfoProvider.GetOrders().WhereEquals("OrderGuid", mOrderGuid).FirstOrDefault();

        if (order != null)
        {
            var payPalProvider = CMSPaymentGatewayProvider.GetPaymentGatewayProvider <CMSPayPalProvider>(order.OrderPaymentOptionID);
            if (payPalProvider != null)
            {
                payPalProvider.OrderId = order.OrderID;
                payPalProvider.ExecutePayment(mPaymentId, mPayerId);
            }
            else
            {
                // Payment provider not found
                LogEvent(null, "Payment_Provider_Not_Found");
            }
        }
        else
        {
            // Order not found
            LogEvent(String.Format(ResHelper.GetString("PaymentGatewayProvider.ordernotfound"), mOrderGuid), "Order_Not_Found");
        }
    }
Beispiel #3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get order id
        orderId = ValidationHelper.GetInteger(Request.Form["invoice"], 0);

        // Get transaction id
        transactionId = ValidationHelper.GetString(Request.Form["txn_id"], "");

        // Get payment status
        paymentStatus = ValidationHelper.GetString(Request.Form["payment_status"], "");

        // Get notification culture stored in custom field
        orderCulture = ValidationHelper.GetString(Request.Form["custom"], "");

        CMSPayPalProvider payPalProvider = null;
        string            errorMessage   = "";

        // Get paypal provider
        OrderInfo oi = OrderInfoProvider.GetOrderInfo(orderId);

        if (oi != null)
        {
            try
            {
                payPalProvider         = (CMSPayPalProvider)CMSPaymentGatewayProvider.GetPaymentGatewayProvider(oi.OrderPaymentOptionID);
                payPalProvider.OrderId = orderId;
            }
            catch (Exception ex)
            {
                // Log exception
                errorMessage = EventLogProvider.GetExceptionLogMessage(ex);
                LogEvent(errorMessage, "Payment_Provider_Not_Found");
                return;
            }
        }
        else
        {
            // Order not found
            errorMessage = string.Format(GetString("PaymentGatewayProvider.ordernotfound"), orderId);
            LogEvent(errorMessage, "Order_Not_Found");
            return;
        }

        PayPalPaymentResultInfo paypalResult = (PayPalPaymentResultInfo)(payPalProvider.PaymentResult);

        // Confirm payment and get PayPal payment gateway response
        string response = payPalProvider.ConfirmPayment(Request.Form);

        // Set payment as verified / not verified
        paypalResult.PayPalPaymentVerified = (response.ToLowerCSafe() == "verified");

        // Set transaction ID
        paypalResult.PaymentTransactionID = transactionId;

        // Set payment status (take received status seriously only if payment was verified)
        paypalResult.PayPalPaymentStatus = PayPalPaymentResultInfo.GetPayPalPaymentStatus(paypalResult.PayPalPaymentVerified ? paymentStatus : "failed");

        // Set payment as completed / not completed
        switch (paypalResult.PayPalPaymentStatus)
        {
        case PayPalPaymentStatusEnum.CanceledReversal:
        case PayPalPaymentStatusEnum.Completed:
        case PayPalPaymentStatusEnum.Processed:
            paypalResult.PaymentIsCompleted = true;
            break;

        default:
            paypalResult.PaymentIsCompleted = false;
            break;
        }

        // Compare payment data to order data
        string error = payPalProvider.ComparePaymentDataToOrderData(Request.Form);

        if (error != "")
        {
            paypalResult.PaymentIsCompleted    = false;
            paypalResult.PayPalPaymentVerified = false;
            paypalResult.PaymentDescription    = error;
        }

        // Order culture
        payPalProvider.ShoppingCartInfoObj.ShoppingCartCulture = orderCulture;

        // Update order payment result in database
        errorMessage = payPalProvider.UpdateOrderPaymentResult();
        if (errorMessage != "")
        {
            // Log the event
            errorMessage += error;
            LogEvent(errorMessage, "Order_Payment_Result_Update");
        }
    }