Beispiel #1
0
        /* bool processResponse (string response)
         *
         * Parses the gateway's response with XmlToArray() and places the important values in the this._response array. Indicates whether the transaction has succeeded or not, and fills this._error with a reason for failure if appropriate.
         *
         * string response: gateway response in XML format as a string
         * Returns boolean true for successful transaction and successful parse else false
         */
        private bool processResponse(string response)
        {
            XmlToDictionary xml_parser = new XmlToDictionary();
            Dictionary<string, string> result = new Dictionary<string, string>();
            result = xml_parser.Parse(response);

            this._response = new Dictionary<string, string>();

            string apr;
            string path;

            this._approved = false;
            this._response["response"] = response;

            if(this._request == REQUEST_PERIODIC)
            {
                apr = "successful";
                path = "Periodic_PeriodicList_PeriodicItem";
            }
            else // if (this._request == REQUEST_PAYMENT)
            {
                apr = "approved";
                path = "Payment_TxnList_Txn";
            }

            try
            {
                this._response["status"] = result["SecurePayMessage_Status_statusCode"];
                this._response["status_desc"] = result["SecurePayMessage_Status_statusDescription"];
                this._response["approved"] = result.ContainsKey("SecurePayMessage_" + path + "_" + apr) ? result["SecurePayMessage_" + path + "_" + apr] : "No";

                this._response["response_code"] = result.ContainsKey("SecurePayMessage_" + path + "_responseCode") ? result["SecurePayMessage_" + path + "_responseCode"] : this._response["status"];
                this._response["response_text"] = result.ContainsKey("SecurePayMessage_" + path + "_responseText") ? result["SecurePayMessage_" + path + "_responseText"] : this._response["status_desc"];

                if(this._response["approved"].ToUpper() == "YES")
                {
                    this._approved = true;
                }
                else
                {
                    this._approved = false;
                }
            }
            catch(Exception e)
            {
                this._error = ERROR_RESPONSE_INVALID;
                Console.WriteLine("error occured: " + e.Message);
                return false;
            }

            try
            {
                this._response["message_id"] = result["SecurePayMessage_MessageInfo_messageID"];
                this._response["timestamp"] = result["SecurePayMessage_MessageInfo_messageTimestamp"];
                this._response["api"] = result["SecurePayMessage_MessageInfo_apiVersion"];
                this._response["merch_id"] = result["SecurePayMessage_MerchantInfo_merchantID"];

                if(this._request == REQUEST_PAYMENT)
                {
                    this._response["transaction_id"] = result["SecurePayMessage_" + path + "_txnID"];
                    this._response["settlement"] = result["SecurePayMessage_" + path + "_settlementDate"];
                    this._response["type"] = result["SecurePayMessage_" + path + "_txnType"];

                    if(this._transaction_type == TXN_PREAUTH)
                    {
                        this._response["preauth_id"] = result["SecurePayMessage_" + path + "_preauthID"];
                    }
                }

                if(this._transaction_type == TXN_STANDARD || this._transaction_type == TXN_PREAUTH)
                {
                    this._response["cc_pan"] = result["SecurePayMessage_" + path + "_CreditCardInfo_pan"];
                    this._response["cc_expiry"] = result["SecurePayMessage_" + path + "_CreditCardInfo_expiryDate"];
                }

                if(this._transaction_type == TXN_STANDARD || this._transaction_type == TXN_ADVICE || this._transaction_type == TXN_REFUND || this._transaction_type == TXN_REVERSE)
                {
                    this._response["amount"] = result["SecurePayMessage_" + path + "_amount"];
                }
            }
            catch(Exception e)
            {
                if(this._approved)
                {
                    throw e;
                }
            }

            if(this._approved == false)
            {
                this._error = string.Format("{0} ({1}): {2}", ERROR_TXN_DECLINED, this._response["response_code"], this._response["response_text"]);
                return false;
            }

            return true;
        }
Beispiel #2
0
        /* bool processResponse (string response)
         * 
         * Parses the gateway's response with XmlToArray() and places the important values in the this._response array. Indicates whether the transaction has succeeded or not, and fills this._error with a reason for failure if appropriate.
         * 
         * string response: gateway response in XML format as a string
         * Returns boolean true for successful transaction and successful parse else false
         */
        private bool processResponse(string response)
        {
            XmlToDictionary xml_parser = new XmlToDictionary();
            Dictionary<string, string> result = new Dictionary<string, string>();
            result = xml_parser.Parse(response);

            this._response = new Dictionary<string, string>();

            string apr;
            string path;

            this._approved = false;
            this._response["response"] = response;

            if(this._request == REQUEST_PERIODIC)
            {
                apr = "successful";
                path = "Periodic_PeriodicList_PeriodicItem";
            }
            else // if (this._request == REQUEST_PAYMENT)
            {
                apr = "approved";
                path = "Payment_TxnList_Txn";
            }

            try
            {
                this._response["status"] = result["SecurePayMessage_Status_statusCode"];
                this._response["status_desc"] = result["SecurePayMessage_Status_statusDescription"];
                this._response["approved"] = result.ContainsKey("SecurePayMessage_" + path + "_" + apr) ? result["SecurePayMessage_" + path + "_" + apr] : "No";

                this._response["response_code"] = result.ContainsKey("SecurePayMessage_" + path + "_responseCode") ? result["SecurePayMessage_" + path + "_responseCode"] : this._response["status"];
                this._response["response_text"] = result.ContainsKey("SecurePayMessage_" + path + "_responseText") ? result["SecurePayMessage_" + path + "_responseText"] : this._response["status_desc"];

                if(this._response["approved"].ToUpper() == "YES")
                {
                    this._approved = true;
                }
                else
                {
                    this._approved = false;
                }
            }
            catch(Exception e)
            {
                this._error = ERROR_RESPONSE_INVALID;
                Console.WriteLine("error occured: " + e.Message);
                return false;
            }

            try
            {
                this._response["message_id"] = result["SecurePayMessage_MessageInfo_messageID"];
                this._response["timestamp"] = result["SecurePayMessage_MessageInfo_messageTimestamp"];
                this._response["api"] = result["SecurePayMessage_MessageInfo_apiVersion"];
                this._response["merch_id"] = result["SecurePayMessage_MerchantInfo_merchantID"];

                if(this._request == REQUEST_PAYMENT)
                {
                    this._response["transaction_id"] = result["SecurePayMessage_" + path + "_txnID"];
                    this._response["settlement"] = result["SecurePayMessage_" + path + "_settlementDate"];
                    this._response["type"] = result["SecurePayMessage_" + path + "_txnType"];

                    if(this._transaction_type == TXN_PREAUTH)
                    {
                        this._response["preauth_id"] = result["SecurePayMessage_" + path + "_preauthID"];
                    }
                }

                if(this._transaction_type == TXN_STANDARD || this._transaction_type == TXN_PREAUTH)
                {
                    this._response["cc_pan"] = result["SecurePayMessage_" + path + "_CreditCardInfo_pan"];
                    this._response["cc_expiry"] = result["SecurePayMessage_" + path + "_CreditCardInfo_expiryDate"];
                }

                if(this._transaction_type == TXN_STANDARD || this._transaction_type == TXN_ADVICE || this._transaction_type == TXN_REFUND || this._transaction_type == TXN_REVERSE)
                {
                    this._response["amount"] = result["SecurePayMessage_" + path + "_amount"];
                }
            }
            catch(Exception e)
            {
                if(this._approved)
                {
                    throw e;
                }
            }

            if(this._approved == false)
            {
                this._error = string.Format("{0} ({1}): {2}", ERROR_TXN_DECLINED, this._response["response_code"], this._response["response_text"]);
                return false;
            }

            return true;
        }