private static CheckoutResponse HandleCustomParameters(HttpRequestBase request, CheckoutResponse checkoutResponse) { // handling custom user defined parameters , wirecard pipes your own parameters back and forth if (checkoutResponse != null) { foreach (var key in request.Form.AllKeys) { if (!string.IsNullOrEmpty(key) && !ReservedParameters.Contains(key)) { checkoutResponse.CustomParameters.Add(key, request.Form[key]); } } } return(checkoutResponse); }
/// <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); }
/// <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); }