コード例 #1
0
        /// <summary>
        /// Binds the order details in the payment column
        /// </summary>
        protected void BindPaymentColumn()
        {
            // bind status
            OrderTotal.Text           = _order.TotalCharges.LSCurrencyFormat("lc");
            OrderBalance.Text         = _order.GetBalance(false).LSCurrencyFormat("lc");
            CurrentPaymentStatus.Text = _order.PaymentStatus.ToString();
            if (_order.PaymentStatus == OrderPaymentStatus.Paid)
            {
                CurrentPaymentStatus.CssClass = "goodCondition";
            }
            else
            {
                CurrentPaymentStatus.CssClass = "errorCondition";
            }


            // check for the last payment record
            Payment payment = GetLastPayment();

            if (payment != null)
            {
                // bind static payment info
                LastPaymentAmount.Text    = payment.Amount.LSCurrencyFormat("lc");
                LastPaymentStatus.Text    = StringHelper.SpaceName(payment.PaymentStatus.ToString());
                LastPaymentReference.Text = payment.PaymentMethodName;
                if (!string.IsNullOrEmpty(payment.ReferenceNumber))
                {
                    LastPaymentReference.Text += " " + payment.ReferenceNumber;
                }

                // bind transaction details
                Transaction lastAuthorization = payment.Transactions.GetLastAuthorization();
                if (lastAuthorization == null)
                {
                    lastAuthorization = payment.Transactions.GetLastRecurringAuthorization();
                }
                if (lastAuthorization != null)
                {
                    string friendlyCVV = AbleCommerce.Code.StoreDataHelper.TranslateCVVCode(lastAuthorization.CVVResultCode);
                    if (!string.IsNullOrEmpty(lastAuthorization.CVVResultCode))
                    {
                        friendlyCVV += " (" + lastAuthorization.CVVResultCode + ")";
                    }
                    LastPaymentCVV.Text = friendlyCVV;
                    string friendlyAVS = AbleCommerce.Code.StoreDataHelper.TranslateAVSCode(lastAuthorization.AVSResultCode);
                    if (!string.IsNullOrEmpty(lastAuthorization.AVSResultCode))
                    {
                        friendlyAVS += " (" + lastAuthorization.AVSResultCode + ")";
                    }
                    LastPaymentAVS.Text = friendlyAVS;
                }
                else
                {
                    TransactionPanel.Visible = false;
                }

                PaymentGateway gateway = null;
                if (payment.PaymentMethod != null)
                {
                    gateway = payment.PaymentMethod.PaymentGateway;
                }

                if (gateway == null && payment.PaymentProfile != null)
                {
                    int gatewayId = PaymentGatewayDataSource.GetPaymentGatewayIdByClassId(payment.PaymentProfile.GatewayIdentifier);
                    gateway = PaymentGatewayDataSource.Load(gatewayId);
                }

                IPaymentProvider      provider = (gateway != null ? gateway.GetInstance() : null);
                SupportedTransactions supportedTransactions = SupportedTransactions.None;
                if (provider != null)
                {
                    supportedTransactions = provider.SupportedTransactions;
                }

                // bind payment buttons
                ReceivedButton.Visible = (payment.PaymentStatus == PaymentStatus.Unprocessed);
                if ((supportedTransactions & SupportedTransactions.Void) == SupportedTransactions.Void)
                {
                    VoidLink.Visible     = ((payment.PaymentStatus == PaymentStatus.Unprocessed) || (payment.PaymentStatus == PaymentStatus.Authorized) || (payment.PaymentStatus == PaymentStatus.AuthorizationFailed) || (payment.PaymentStatus == PaymentStatus.CaptureFailed));
                    VoidLink.NavigateUrl = "Payments/VoidPayment.aspx?PaymentId=" + payment.Id.ToString();
                }
                else
                {
                    VoidLink.Visible = false;
                }

                if ((((supportedTransactions & SupportedTransactions.Capture) == SupportedTransactions.Capture) || ((supportedTransactions & SupportedTransactions.AuthorizeCapture) == SupportedTransactions.AuthorizeCapture)))
                {
                    CaptureLink.Visible     = (payment.PaymentStatus == PaymentStatus.Authorized);
                    CaptureLink.NavigateUrl = "Payments/CapturePayment.aspx?PaymentId=" + payment.Id.ToString();
                }
                else
                {
                    VoidLink.Visible = false;
                }

                ButtonPanel.Visible = ReceivedButton.Visible || VoidLink.Visible || CaptureLink.Visible;
            }
            else
            {
                LastPaymentPanel.Visible = false;
            }

            // IP details
            if (!string.IsNullOrEmpty(_order.RemoteIP))
            {
                CustomerIP.Text               = _order.RemoteIP;
                CustomerIPBlocked.Visible     = BannedIPDataSource.IsBanned(CustomerIP.Text);
                BlockCustomerIP.Visible       = (!CustomerIPBlocked.Visible && (_order.RemoteIP != Request.UserHostAddress));
                BlockCustomerIP.OnClientClick = string.Format(BlockCustomerIP.OnClientClick, _order.RemoteIP);
            }
            else
            {
                CustomerIPPanel.Visible = false;
            }

            //Refferrer url
            if (!string.IsNullOrEmpty(_order.Referrer))
            {
                if (_order.Referrer.Length > UrlMaxLenght)
                {
                    OrderReferrer.NavigateUrl = _order.Referrer;
                    OrderReferrer.Text        = _order.Referrer.Substring(0, UrlMaxLenght) + "...";
                }
                else
                {
                    OrderReferrer.NavigateUrl = _order.Referrer;
                    OrderReferrer.Text        = _order.Referrer.Replace("/", "/<wbr />").Replace("_", "_<wbr />");
                }
            }

            // affiliate details
            if (_order.AffiliateId != 0)
            {
                Affiliate.Text = _order.Affiliate.Name;
            }
            else
            {
                AffiliatePanel.Visible = false;
            }
            TaxExemptionMessagePanel.Visible = this._order.Items.TotalPrice(OrderItemType.Tax) == 0 && !string.IsNullOrEmpty(this._order.TaxExemptionReference);
        }
コード例 #2
0
        public bool ShowButton(string buttonName, object dataItem)
        {
            Payment          payment  = (Payment)dataItem;
            PaymentMethod    method   = payment.PaymentMethod;
            PaymentGateway   gateway  = method == null ? null : method.PaymentGateway;
            IPaymentProvider provider = null;

            if (gateway != null)
            {
                provider = gateway.GetInstance();
            }

            SupportedTransactions supportedTransactions = SupportedTransactions.None;

            if (provider != null)
            {
                supportedTransactions = provider.SupportedTransactions;
            }

            switch (buttonName.ToUpperInvariant())
            {
            case "RETRYAUTH":
                if (provider != null)
                {
                    if (!(((supportedTransactions & SupportedTransactions.Authorize) == SupportedTransactions.Authorize) || ((supportedTransactions & SupportedTransactions.AuthorizeCapture) == SupportedTransactions.AuthorizeCapture)))
                    {
                        return(false);
                    }
                }

                // DISABLE FOR PHONE CALL PAYMENT METHOD
                if (payment.PaymentMethod != null && payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.PhoneCall)
                {
                    return(false);
                }
                return(payment.PaymentStatus == PaymentStatus.AuthorizationFailed);

            case "RETRYCAPTURE":
                if (provider != null)
                {
                    if (!(((supportedTransactions & SupportedTransactions.Authorize) == SupportedTransactions.Authorize) || ((supportedTransactions & SupportedTransactions.AuthorizeCapture) == SupportedTransactions.AuthorizeCapture)))
                    {
                        return(false);
                    }
                }

                // DISABLE FOR PHONE CALL PAYMENT METHOD
                if (payment.PaymentMethod != null && payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.PhoneCall)
                {
                    return(false);
                }
                return(payment.PaymentStatus == PaymentStatus.CaptureFailed);

            case "RECEIVED":
                return(payment.PaymentStatus == PaymentStatus.Unprocessed);

            case "AUTHORIZE":
                if (provider != null)
                {
                    if (!(((supportedTransactions & SupportedTransactions.Authorize) == SupportedTransactions.Authorize) || ((supportedTransactions & SupportedTransactions.AuthorizeCapture) == SupportedTransactions.AuthorizeCapture)))
                    {
                        return(false);
                    }
                }

                // DISABLE FOR PHONE CALL PAYMENT METHOD
                if (payment.PaymentMethod != null && payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.PhoneCall)
                {
                    return(false);
                }
                return(payment.PaymentStatus == PaymentStatus.Unprocessed);

            case "VOID":
                if (provider != null)
                {
                    if (!((supportedTransactions & SupportedTransactions.Void) == SupportedTransactions.Void))
                    {
                        return(false);
                    }
                }

                //Disable Void for Google Checkout AND PHONE CALL PAYMENT METHOD
                if (payment.PaymentMethod != null && (payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.GoogleCheckout || payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.PhoneCall))
                {
                    return(false);
                }
                else
                {
                    //VOID SHOULD ONLY BE SHOWN IF THE PAYMENT IS UNPROCESSED OR IN AN AUTHORIZED STATE
                    return(payment.PaymentStatus == PaymentStatus.Unprocessed ||
                           payment.PaymentStatus == PaymentStatus.AuthorizationFailed ||
                           payment.PaymentStatus == PaymentStatus.Authorized ||
                           payment.PaymentStatus == PaymentStatus.CaptureFailed);
                }

            case "CAPTURE":
                if (provider != null)
                {
                    if (!(((supportedTransactions & SupportedTransactions.Capture) == SupportedTransactions.Capture) || ((supportedTransactions & SupportedTransactions.AuthorizeCapture) == SupportedTransactions.AuthorizeCapture)))
                    {
                        return(false);
                    }
                }

                // DISABLE FOR PHONE CALL PAYMENT METHOD
                if (payment.PaymentMethod != null && payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.PhoneCall)
                {
                    return(false);
                }
                return(payment.PaymentStatus == PaymentStatus.Authorized);

            case "CANCEL":
                // DISABLE FOR PHONE CALL PAYMENT METHOD
                if (payment.PaymentMethod != null && payment.PaymentMethod.PaymentInstrumentType == PaymentInstrumentType.PhoneCall)
                {
                    return(false);
                }
                return(payment.PaymentStatus == PaymentStatus.Completed);

            case "REFUND":
                if (provider != null)
                {
                    if (!((supportedTransactions & SupportedTransactions.Refund) == SupportedTransactions.Refund))
                    {
                        return(false);
                    }
                }

                //SHOW REFUND IF THE PAYMENT WAS MADE WITHIN 60 DAYS
                //AND THE PAYMENT IS CAPTURED
                //AND THERE IS IS A POSTIVE TRANSACTION CAPTURE AMOUNT
                return((payment.PaymentDate > DateTime.UtcNow.AddDays(-60)) &&
                       (payment.PaymentStatus == PaymentStatus.Captured) &&
                       (payment.Transactions.GetTotalCaptured() > 0));

            case "DELETE":
                //BY DEFAULT DO NOT SHOW THE DELETE BUTTON
                return(false);

            default:
                throw new ArgumentException("Invalid button name: '" + buttonName, buttonName);
            }
        }