/// <summary>
            /// Validates the merchant account.
            /// </summary>
            /// <param name="request">The request.</param>
            /// <param name="errors">The error list to add any validation errors.</param>
            private static void ValidateMerchantAccount(Request request, List <PaymentError> errors)
            {
                // Get payment processor
                PaymentProcessorManager.Create(new string[] { AppSettings.ConnectorAssembly });
                IPaymentProcessor processor = PaymentProcessorManager.GetPaymentProcessor(AppSettings.ConnectorName);

                // Prepare a request for validating merchant account
                var validateMerchantAccountRequest = new Request();

                validateMerchantAccountRequest.Locale = request.Locale;
                var validateMerchantAccountRequestPropertyList = new List <PaymentProperty>();

                foreach (var paymentProperty in request.Properties)
                {
                    if (paymentProperty.Namespace == GenericNamespace.MerchantAccount)
                    {
                        validateMerchantAccountRequestPropertyList.Add(paymentProperty);
                    }
                }

                validateMerchantAccountRequest.Properties = validateMerchantAccountRequestPropertyList.ToArray();

                // Validates the merchant account by calling the payment processor
                Response validateMerchantAccountResponse = processor.ValidateMerchantAccount(validateMerchantAccountRequest);

                if (validateMerchantAccountResponse != null)
                {
                    if (validateMerchantAccountResponse.Errors != null)
                    {
                        errors.AddRange(validateMerchantAccountResponse.Errors);
                    }
                }
                else
                {
                    var error = new PaymentError(ErrorCode.InvalidMerchantConfiguration, "Merchant configuraiton is invalid.");
                    errors.Add(error);
                }
            }
Esempio n. 2
0
            private void RetrievePaymentAcceptResult()
            {
                // Get payment processor
                PaymentProcessorManager.Create(new string[] { ConnectorAssembly });
                IPaymentProcessor processor = PaymentProcessorManager.GetPaymentProcessor(ConnectorName);

                // Prepare payment request
                var request = new Request();

                request.Locale = this.requestLocale;

                var properties = new List <PaymentProperty>();

                this.AddMerchantProperties(properties);

                PaymentProperty property;

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.PaymentAcceptResultAccessCode,
                    this.ResultAccessCodeHiddenField.Value);
                properties.Add(property);

                request.Properties = properties.ToArray();

                // Call
                Response response = processor.RetrievePaymentAcceptResult(request);

                string cardTokenResult     = "N/A";
                string authorizationResult = "N/A";
                string captureResult       = "N/A";
                string voidResult          = "N/A";
                string errors = "None";

                if (response != null && response.Properties != null)
                {
                    Hashtable responseProperties = PaymentProperty.ConvertToHashtable(response.Properties);

                    // Read card token
                    string token;
                    PaymentProperty.GetPropertyValue(
                        responseProperties,
                        GenericNamespace.PaymentCard,
                        PaymentCardProperties.CardToken,
                        out token);

                    if (!string.IsNullOrEmpty(token))
                    {
                        // Store token or use token.
                        // In this sample, we send the token to the next page to display. Do not do this in production.
                        cardTokenResult = token;
                    }

                    // Read authorize result
                    if (this.transactionType == TransactionType.Authorize || this.transactionType == TransactionType.Capture)
                    {
                        PaymentProperty innerAuthorizeResponseProperty = PaymentProperty.GetPropertyFromHashtable(
                            responseProperties,
                            GenericNamespace.AuthorizationResponse,
                            AuthorizationResponseProperties.Properties);

                        if (innerAuthorizeResponseProperty != null)
                        {
                            var innerAuthorizeResponseProperties = PaymentProperty.ConvertToHashtable(innerAuthorizeResponseProperty.PropertyList);

                            string authorizationResultOut = null;
                            PaymentProperty.GetPropertyValue(
                                innerAuthorizeResponseProperties,
                                GenericNamespace.AuthorizationResponse,
                                AuthorizationResponseProperties.AuthorizationResult,
                                out authorizationResultOut);

                            if (!string.IsNullOrEmpty(authorizationResultOut))
                            {
                                authorizationResult = authorizationResultOut;
                            }
                        }
                    }

                    // Read capture result
                    if (this.transactionType == TransactionType.Capture)
                    {
                        PaymentProperty innerCaptureResponseProperty = PaymentProperty.GetPropertyFromHashtable(
                            responseProperties,
                            GenericNamespace.CaptureResponse,
                            CaptureResponseProperties.Properties);

                        if (innerCaptureResponseProperty != null)
                        {
                            var innerCaptureResponseProperties = PaymentProperty.ConvertToHashtable(innerCaptureResponseProperty.PropertyList);

                            string captureResultOut = null;
                            PaymentProperty.GetPropertyValue(
                                innerCaptureResponseProperties,
                                GenericNamespace.CaptureResponse,
                                CaptureResponseProperties.CaptureResult,
                                out captureResultOut);

                            if (!string.IsNullOrEmpty(captureResultOut))
                            {
                                captureResult = captureResultOut;
                            }
                        }
                    }

                    // Read void result
                    if (this.transactionType == TransactionType.Authorize || this.transactionType == TransactionType.Capture)
                    {
                        PaymentProperty innerVoidResponseProperty = PaymentProperty.GetPropertyFromHashtable(
                            responseProperties,
                            GenericNamespace.VoidResponse,
                            VoidResponseProperties.Properties);

                        if (innerVoidResponseProperty != null)
                        {
                            var innerVoidResponseProperties = PaymentProperty.ConvertToHashtable(innerVoidResponseProperty.PropertyList);

                            string voidResultOut = null;
                            PaymentProperty.GetPropertyValue(
                                innerVoidResponseProperties,
                                GenericNamespace.VoidResponse,
                                VoidResponseProperties.VoidResult,
                                out voidResultOut);

                            if (!string.IsNullOrEmpty(voidResultOut))
                            {
                                voidResult = voidResultOut;
                            }
                        }
                    }
                }

                if (response.Errors != null && response.Errors.Length > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var error in response.Errors)
                    {
                        sb.AppendLine(string.Format("{0}: {1}", error.Code, error.Message));
                    }

                    errors = sb.ToString();
                }

                Server.Transfer(
                    string.Format(
                        "ResultPage.aspx?cardTokenResult={0}&authorizationResult={1}&captureResult={2}&voidResult={3}&errors={4}",
                        HttpUtility.UrlEncode(cardTokenResult),
                        HttpUtility.UrlEncode(authorizationResult),
                        HttpUtility.UrlEncode(captureResult),
                        HttpUtility.UrlEncode(voidResult),
                        HttpUtility.UrlEncode(errors)));
            }
Esempio n. 3
0
            private void GetPaymentAcceptPoint()
            {
                // Get payment processor
                PaymentProcessorManager.Create(new string[] { ConnectorAssembly });
                IPaymentProcessor processor = PaymentProcessorManager.GetPaymentProcessor(ConnectorName);

                // Prepare payment request
                var request = new Request();

                request.Locale = this.requestLocale;

                var properties = new List <PaymentProperty>();

                this.AddMerchantProperties(properties);

                PaymentProperty property;

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.CardType,
                    "Visa;MasterCard;Amex;Discover;Debit");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.ShowSameAsShippingAddress,
                    this.showSameAsShippingAddress);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.StreetAddress,
                    "1 Microsoft Way");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.City,
                    "Redmond");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.State,
                    "WA");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.PostalCode,
                    "98052");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.PaymentCard,
                    PaymentCardProperties.Country,
                    "US");
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.TransactionType,
                    this.transactionType.ToString());
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.SupportCardSwipe,
                    this.supportCardSwipe);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.SupportCardTokenization,
                    this.supportCardTokenization);
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.HostPageOrigin,
                    HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority));
                properties.Add(property);

                property = new PaymentProperty(
                    GenericNamespace.TransactionData,
                    TransactionDataProperties.IndustryType,
                    this.industryType);
                properties.Add(property);

                if (this.transactionType == TransactionType.Authorize || this.transactionType == TransactionType.Capture)
                {
                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.PurchaseLevel,
                        PurchaseLevel.Level1.ToString());
                    properties.Add(property);

                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.AllowPartialAuthorization,
                        "true");
                    properties.Add(property);

                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.AllowVoiceAuthorization,
                        this.supportVoiceAuthorization);
                    properties.Add(property);

                    property = new PaymentProperty(
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.CurrencyCode,
                        "USD");
                    properties.Add(property);
                }

                request.Properties = properties.ToArray();

                // Call
                Response response = processor.GetPaymentAcceptPoint(request);

                if (response != null && response.Errors == null && response.Properties != null)
                {
                    Hashtable responseProperties = PaymentProperty.ConvertToHashtable(response.Properties);

                    string paymentAcceptUrl;
                    PaymentProperty.GetPropertyValue(
                        responseProperties,
                        GenericNamespace.TransactionData,
                        TransactionDataProperties.PaymentAcceptUrl,
                        out paymentAcceptUrl);

                    if (!string.IsNullOrEmpty(paymentAcceptUrl))
                    {
                        this.PaymentAcceptUrl = string.Format(
                            "{0}&fontsize={1}&fontfamily={2}&labelcolor={3}&textbackgroundcolor={4}&textcolor={5}&disabledtextbackgroundcolor={6}&columnnumber={7}",
                            paymentAcceptUrl,
                            HttpUtility.UrlEncode(this.fontSize),
                            HttpUtility.UrlEncode(this.fontFamily),
                            HttpUtility.UrlEncode(this.labelColor),
                            HttpUtility.UrlEncode(this.textBackgroundColor),
                            HttpUtility.UrlEncode(this.textColor),
                            HttpUtility.UrlEncode(this.disabledTextBackgroundColor),
                            HttpUtility.UrlEncode(this.columnNumber));
                        this.CardPageOriginHiddenField.Value = new Uri(paymentAcceptUrl).GetLeftPart(UriPartial.Authority);
                    }
                    else
                    {
                        throw new InvalidOperationException("Failed to retrieve card page. Payment accepting URL is null or empty.");
                    }
                }
                else
                {
                    string errorMessage = string.Empty;
                    if (response == null)
                    {
                        errorMessage = "Response is null. ";
                    }
                    else
                    {
                        if (response.Properties == null)
                        {
                            errorMessage += "Response properties is null. ";
                        }

                        if (response.Errors != null)
                        {
                            errorMessage += "Response contains error(s). ";
                            foreach (var error in response.Errors)
                            {
                                errorMessage += string.Format("{0}: {1}.", error.Code, error.Message);
                            }
                        }
                    }

                    throw new InvalidOperationException("Failed to retrieve card page. " + errorMessage);
                }
            }