public ICancelTransactionResponse Parse(string dataCashResponse)
        {
            var document = XDocument.Parse(dataCashResponse);

            var response = new CancelTransactionResponse(document);

            string transactionReference;

            if (document.TryGetXPathValue("Response/datacash_reference", out transactionReference))
            {
                response.TransactionReference = transactionReference;
            }

            var dataCashStatus = int.Parse(document.XPathValue("Response/status"));

            response.Status = dataCashStatus == DataCashStatus.Success
                                  ? PaymentStatus.Successful
                                  : PaymentStatus.Failed;

            if (response.Status == PaymentStatus.Failed)
            {
                response.IsSystemFailure = DataCashStatus.IsSystemFailure(dataCashStatus);
                var failureReason = DataCashStatus.FailureReason(dataCashStatus);
                response.FailureMessage = failureReason.Message;
            }

            return(response);
        }
        public I3DSecureResponse Parse(string dataCashResponse)
        {
            var document = XDocument.Parse(dataCashResponse);

            var response = new DataCash3DSecurePaymentResponse(document);

            string transactionReference;

            if (document.TryGetXPathValue("Response/datacash_reference", out transactionReference))
            {
                response.TransactionReference = transactionReference;
            }

            string avsCv2Result;

            if (document.TryGetXPathValue("Response/CardTxn/Cv2Avs/cv2avs_status", out avsCv2Result))
            {
                response.AvsCv2Result = avsCv2Result;
            }

            var dataCashStatus = int.Parse(document.XPathValue("Response/status"));

            switch (dataCashStatus)
            {
            case DataCashStatus.Success:
                response.Status = PaymentStatus.Successful;
                break;

            case DataCashStatus.RequiresThreeDSecureAuthentication:
                response.Status = PaymentStatus.Pending;
                response.Requires3DSecurePayerVerification = true;
                response.PAReq  = document.XPathValue("Response/CardTxn/ThreeDSecure/pareq_message");
                response.ACSUrl = document.XPathValue("Response/CardTxn/ThreeDSecure/acs_url");
                break;

            default:
                if (DataCashStatus.CanImmediatelyAuthorise(dataCashStatus))
                {
                    Log.Warn("Response status of '{0}' was returned for DataCash txn reference '{1}'. This txn can be immediately authorised.", dataCashStatus, transactionReference);
                    response.Status = PaymentStatus.Pending;
                }
                else
                {
                    response.Status          = PaymentStatus.Failed;
                    response.IsSystemFailure = DataCashStatus.IsSystemFailure(dataCashStatus);
                    var failureReason = DataCashStatus.FailureReason(dataCashStatus);
                    response.FailureMessage = failureReason.Message;
                    response.FailureType    = failureReason.Type;
                }
                break;
            }

            return(response);
        }
Example #3
0
        public void SetPaymentValues(XDocument document, CardPaymentPaymentResponse response)
        {
            string transactionReference;

            if (document.TryGetXPathValue("Response/datacash_reference", out transactionReference))
            {
                response.TransactionReference = transactionReference;
            }

            string avsCv2Result;

            if (document.TryGetXPathValue("Response/CardTxn/Cv2Avs/cv2avs_status", out avsCv2Result))
            {
                response.AvsCv2Result = avsCv2Result;
            }

            string auth_code;

            if (document.TryGetXPathValue("Response/CardTxn/authcode", out auth_code))
            {
                response.AuthCode = auth_code;
            }

            var dataCashStatus = int.Parse(document.XPathValue("Response/status"));

            response.Status = dataCashStatus == DataCashStatus.Success
                                  ? PaymentStatus.Successful
                                  : PaymentStatus.Failed;

            if (response.Status == PaymentStatus.Failed)
            {
                string reason;
                document.TryGetXPathValue("Response/reason", out reason);
                response.IsSystemFailure = DataCashStatus.IsSystemFailure(dataCashStatus);
                var failureReason = DataCashStatus.FailureReason(dataCashStatus);
                response.FailureMessage = failureReason.Message + (string.IsNullOrEmpty(reason) ? "" : $" [{reason}]");
                response.FailureType    = failureReason.Type;
            }
        }