Exemple #1
0
        /// <summary>
        /// Verifies the fingerprint returned by WireCard
        /// </summary>
        /// <param name="secret">The customer secret key</param>
        /// <param name="items">The form values</param>
        /// <returns></returns>
        public static bool VerifyFingerprint(string secret, NameValueCollection items)
        {
            var builder   = new FingerprintBuilder();
            var itemArray = (items["responseFingerprintOrder"] ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var key in itemArray)
            {
                if (key == "secret")
                {
                    builder.AddValue("secret", secret);
                }
                else
                {
                    builder.AddValue(key, items[key]);
                }
            }

            if (builder.GetFingerprintOrder() != items["responseFingerprintOrder"])
            {
                throw new WireCardException("Fingerprint could not be checked!");
            }

            var hash = builder.GetFingerprint();

            return(hash.Equals(items["responseFingerprint"], StringComparison.OrdinalIgnoreCase));
        }
        /// <summary>
        /// Verifies the fingerprint returned by WireCard
        /// </summary>
        /// <param name="secret">The customer secret key</param>
        /// <param name="items">The form values</param>
        /// <returns></returns>
        public static bool VerifyFingerprint(string secret, NameValueCollection items)
        {
            var builder = new FingerprintBuilder();

            string[] itemArray = (items["responseFingerprintOrder"] ?? "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string key in itemArray)
            {
                if (key == "secret")
                {
                    builder.AddValue("secret", secret);
                }
                else
                {
                    builder.AddValue(key, items[key]);
                }
            }

            if (builder.GetFingerprintOrder() != items["responseFingerprintOrder"])
            {
                throw new WireCardException("Fingerprint could not be checked!");
            }

            string hash = builder.GetFingerprint();

            return hash.Equals(items["responseFingerprint"], StringComparison.OrdinalIgnoreCase);
        }
Exemple #3
0
        /// <summary>
        /// Returns all form values that have to be POSTed to QPay
        /// </summary>
        /// <remarks>
        /// This method also verifies the form values and throws an exception, i.e. if a mandatory
        /// field is null.
        /// </remarks>
        /// <exception cref="WireCardNet.WireCardException">Thrown if a field violates the requirements
        /// by QPay</exception>
        /// <returns>A NameValueCollection containing form values</returns>
        public NameValueCollection GetFormValues()
        {
            var b = new FingerprintBuilder(WireCard.QPayCustomerSecret);

            foreach (string key in _customParameters.AllKeys)
            {
                b.AddValue(key, _customParameters[key]);
            }

            b.AddValue("customerId", WireCard.QPayCustomerId);

            if (!string.IsNullOrEmpty(WireCard.QPayShopId))
            {
                b.AddValue("shopId", WireCard.QPayShopId);
            }

            b.AddValue("amount", Amount.ToString("0.00", CultureInfo.InvariantCulture));

            if (AmountNet.HasValue)
            {
                b.AddValue("amount_net", Amount.ToString("0.00", CultureInfo.InvariantCulture));
            }

            b.AddValue("currency", Currency);

            if (PaymentType != PaymentType.Undefined)
            {
                b.AddValue("paymenttype", PaymentType.ToString().ToUpper().Replace('_', '-'));
            }

            if (!string.IsNullOrEmpty(FinancialInstitution))
            {
                b.AddValue("financialInstitution", FinancialInstitution);
            }

            b.AddValue("language", Language);
            b.AddValue("orderDescription", OrderDescription);

            if (!string.IsNullOrEmpty(DisplayText))
            {
                b.AddValue("displayText", DisplayText);
            }

            b.AddValue("successURL", SuccessURL);
            b.AddValue("cancelURL", CancelURL);
            b.AddValue("failureURL", FailureURL);
            b.AddValue("serviceURL", ServiceURL);

            if (!string.IsNullOrEmpty(ConfirmURL))
            {
                b.AddValue("confirmURL", ConfirmURL);
            }

            if (!string.IsNullOrEmpty(ImageURL))
            {
                b.AddValue("imageURL", ImageURL);
            }

            if (DuplicateRequestCheck)
            {
                b.AddValue("duplicateRequestCheck", "yes");
            }

            if (AutoDeposit)
            {
                b.AddValue("autoDeposit", "yes");
            }

            if (MaxRetries.HasValue)
            {
                b.AddValue("maxRetries", MaxRetries.Value.ToString(CultureInfo.InvariantCulture));
            }

            NameValueCollection form = b.GetFormValues();

            form.Add("requestFingerprintOrder", b.GetFingerprintOrder());
            form.Add("requestFingerprint", b.GetFingerprint());

            return(form);
        }
Exemple #4
0
        /// <summary>
        /// Factory method that creates a checkout response from the specified HTTP request
        /// </summary>
        /// <param name="request">The request to create the response from</param>
        /// <param name="successCallback"></param>
        /// <param name="failureCallback"></param>
        /// <param name="cancelCallback"></param>
        /// <returns>A subclass of CheckoutResponse or null if no QPay response is found in the request</returns>
        public static CheckoutResponse FromRequest(HttpRequestBase request,
                                                   Action <CheckoutSuccessResponse> successCallback = null,
                                                   Action <CheckoutFailureResponse> failureCallback = null,
                                                   Action <CheckoutCancelResponse> cancelCallback   = null)
        {
            if (string.IsNullOrEmpty(WireCard.QPayCustomerId))
            {
                throw new WireCardException("Customer id is invalid. Please specify WireCard.CustomerId!");
            }

            if (string.IsNullOrEmpty(WireCard.QPayCustomerSecret))
            {
                throw new WireCardException("Customer secret is invalid. Please specify WireCard.CustomerSecret!");
            }

            CheckoutResponse checkoutResponse = null;

            Debug.WriteLine("checkout response: " + request.Form.ToString());

            var paymentState = request.Form["paymentState"];

            if (paymentState.Equals("SUCCESS", StringComparison.InvariantCultureIgnoreCase))
            {
                var successResponse = new CheckoutSuccessResponse
                {
                    PaymentState               = PaymentState.Success,
                    Amount                     = Decimal.Parse(request.Form["amount"], CultureInfo.InvariantCulture),
                    Currency                   = request.Form["currency"],
                    PaymentType                = (PaymentType)Enum.Parse(typeof(PaymentType), request.Form["paymentType"].Replace('-', '_'), true),
                    FinancialInstitution       = request.Form["financialInstitution"],
                    Language                   = request.Form["language"],
                    OrderNumber                = request.Form["orderNumber"],
                    AnonymousPan               = request.Form["anonymousPan"],
                    Message                    = request.Form["message"],
                    Expiry                     = request.Form["expiry"],
                    Cardholder                 = request.Form["cardholder"],
                    MaskedPan                  = request.Form["maskedPan"],
                    GatewayReferenceNumber     = request.Form["gatewayReferenceNumber"],
                    GatewayContractNumber      = request.Form["gatewayContractNumber"],
                    IDealConsumerName          = request.Form["idealConsumerName"],
                    IDealConsumerCity          = request.Form["idealConsumerCity"],
                    IDealConsumerAccountNumber = request.Form["idealConsumerAccountNumber"],
                    PayPalPayerID              = request.Form["paypalPayerID"],
                    PayPalPayerEMail           = request.Form["paypalPayerEmail"],
                    PayPalPayerLastName        = request.Form["paypalPayerLastName"],
                    PayPalPayerFirstName       = request.Form["paypalPayerFirstName"],
                    SenderAccountOwner         = request.Form["senderAccountOwner"],
                    SenderAccountNumber        = request.Form["senderAccountNumber"],
                    SenderBankNumber           = request.Form["senderBankNumber"],
                    SenderBankName             = request.Form["senderBankName"],
                    SenderBIC                  = request.Form["senderBIC"],
                    SenderIBAN                 = request.Form["senderIBAN"],
                    SenderCountry              = request.Form["senderCountry"],
                    SecurityCriteria           = request.Form["securityCriteria"]
                };

                if (request.Form["authenticated"] != null)
                {
                    successResponse.Authenticated = request.Form["authenticated"].Equals("YES", StringComparison.InvariantCultureIgnoreCase);
                }

                successResponse.IsValid = FingerprintBuilder.VerifyFingerprint(WireCard.QPayCustomerSecret, request.Form);

                checkoutResponse = successResponse;

                checkoutResponse = HandleCustomParameters(request, checkoutResponse);

                if (successCallback != null)
                {
                    successCallback((CheckoutSuccessResponse)checkoutResponse);
                }
            }
            else if (paymentState.Equals("FAILURE", StringComparison.InvariantCultureIgnoreCase))
            {
                var failureResponse = new CheckoutFailureResponse
                {
                    PaymentState = PaymentState.Failure,
                    Message      = request.Form["message"]
                };

                checkoutResponse = failureResponse;

                checkoutResponse = HandleCustomParameters(request, checkoutResponse);

                if (failureCallback != null)
                {
                    failureCallback((CheckoutFailureResponse)checkoutResponse);
                }
            }
            else if (paymentState.Equals("CANCEL", StringComparison.InvariantCultureIgnoreCase))
            {
                var cancelResponse = new CheckoutCancelResponse {
                    PaymentState = PaymentState.Cancel
                };

                checkoutResponse = cancelResponse;

                checkoutResponse = HandleCustomParameters(request, checkoutResponse);

                if (cancelCallback != null)
                {
                    cancelCallback((CheckoutCancelResponse)checkoutResponse);
                }
            }

            return(checkoutResponse);
        }
Exemple #5
0
        /// <summary>
        /// Returns all form values that have to be POSTed to QPay
        /// </summary>
        /// <remarks>
        /// This method also verifies the form values and throws an exception, i.e. if a mandatory
        /// field is null.
        /// </remarks>
        /// <exception cref="WireCardNet.WireCardException">Thrown if a field violates the requirements
        /// by QPay</exception>
        /// <returns>A NameValueCollection containing form values</returns>
        public NameValueCollection GetFormValues()
        {
            var b = new FingerprintBuilder(WireCard.QPayCustomerSecret);

            foreach (string key in _customParameters.AllKeys)
            {
                b.AddValue(key, _customParameters[key]);
            }

            b.AddValue("customerId", WireCard.QPayCustomerId);

            if (!string.IsNullOrEmpty(WireCard.QPayShopId))
            {
                b.AddValue("shopId", WireCard.QPayShopId);
            }

            b.AddValue("amount", Amount.ToString("0.00", CultureInfo.InvariantCulture));

            if (AmountNet.HasValue)
            {
                b.AddValue("amount_net", Amount.ToString("0.00", CultureInfo.InvariantCulture));
            }

            b.AddValue("currency", Currency);

            if (PaymentType != PaymentType.Undefined)
            {
                b.AddValue("paymenttype", PaymentType.ToString().ToUpper().Replace('_', '-'));
            }

            if (!string.IsNullOrEmpty(FinancialInstitution))
            {
                b.AddValue("financialInstitution", FinancialInstitution);
            }

            b.AddValue("language", Language);
            b.AddValue("orderDescription", OrderDescription);

            if (!string.IsNullOrEmpty(DisplayText))
            {
                b.AddValue("displayText", DisplayText);
            }

            b.AddValue("successURL", SuccessURL);
            b.AddValue("cancelURL", CancelURL);
            b.AddValue("failureURL", FailureURL);
            b.AddValue("serviceURL", ServiceURL);

            if (!string.IsNullOrEmpty(ConfirmURL))
            {
                b.AddValue("confirmURL", ConfirmURL);
            }

            if (!string.IsNullOrEmpty(ImageURL))
            {
                b.AddValue("imageURL", ImageURL);
            }

            if (DuplicateRequestCheck)
            {
                b.AddValue("duplicateRequestCheck", "yes");
            }

            if (AutoDeposit)
            {
                b.AddValue("autoDeposit", "yes");
            }

            if (MaxRetries.HasValue)
            {
                b.AddValue("maxRetries", MaxRetries.Value.ToString(CultureInfo.InvariantCulture));
            }

            NameValueCollection form = b.GetFormValues();

            form.Add("requestFingerprintOrder", b.GetFingerprintOrder());
            form.Add("requestFingerprint", b.GetFingerprint());

            return form;
        }
        /// <summary>
        /// Factory method that creates a checkout response from the specified HTTP request
        /// </summary>
        /// <param name="request">The request to create the response from</param>
        /// <returns>A subclass of CheckoutResponse or null if no QPay response is found in the request</returns>
        public static CheckoutResponse FromRequest(HttpRequestBase request)
        {
            if (string.IsNullOrEmpty(WireCard.QPayCustomerId))
            {
                throw new WireCardException("Customer id is invalid. Please specify WireCard.CustomerId!");
            }

            if (string.IsNullOrEmpty(WireCard.QPayCustomerSecret))
            {
                throw new WireCardException("Customer secret is invalid. Please specify WireCard.CustomerSecret!");
            }

            CheckoutResponse result = null;

            if (request.Form["paymentState"] == "SUCCESS")
            {
                var success = new CheckoutSuccessResponse
                {
                    PaymentState               = PaymentState.Success,
                    Amount                     = Decimal.Parse(request.Form["amount"], CultureInfo.InvariantCulture),
                    Currency                   = request.Form["currency"],
                    PaymentType                = (PaymentType)Enum.Parse(typeof(PaymentType), request.Form["paymentType"].Replace('-', '_'), true),
                    FinancialInstitution       = request.Form["financialInstitution"],
                    Language                   = request.Form["language"],
                    OrderNumber                = request.Form["orderNumber"],
                    AnonymousPan               = request.Form["anonymousPan"],
                    Message                    = request.Form["message"],
                    Expiry                     = request.Form["expiry"],
                    Cardholder                 = request.Form["cardholder"],
                    MaskedPan                  = request.Form["maskedPan"],
                    GatewayReferenceNumber     = request.Form["gatewayReferenceNumber"],
                    GatewayContractNumber      = request.Form["gatewayContractNumber"],
                    IDealConsumerName          = request.Form["idealConsumerName"],
                    IDealConsumerCity          = request.Form["idealConsumerCity"],
                    IDealConsumerAccountNumber = request.Form["idealConsumerAccountNumber"],
                    PayPalPayerID              = request.Form["paypalPayerID"],
                    PayPalPayerEMail           = request.Form["paypalPayerEmail"],
                    PayPalPayerLastName        = request.Form["paypalPayerLastName"],
                    PayPalPayerFirstName       = request.Form["paypalPayerFirstName"]
                };

                if (request.Form["authenticated"] != null)
                {
                    success.Authenticated = (request.Form["authenticated"].ToUpper() == "YES");
                }

                success.IsValid = FingerprintBuilder.VerifyFingerprint(WireCard.QPayCustomerSecret, request.Form);

                result = success;
            }
            else if (request.Form["paymentState"] == "FAILURE")
            {
                result = new CheckoutFailureResponse {
                    PaymentState = PaymentState.Failure
                };

                (result as CheckoutFailureResponse).Message = request.Form["message"];
            }
            else if (request.Form["paymentState"] == "CANCEL")
            {
                result = new CheckoutCancelResponse {
                    PaymentState = PaymentState.Cancel
                };
            }

            foreach (string key in request.Form.AllKeys)
            {
                if (!ReservedParameters.Contains(key))
                {
                    result.CustomParameters.Add(key, request.Form[key]);
                }
            }

            return(result);
        }