예제 #1
0
        /*
         * Sends a CNP request asynchronously.
         */
        private async Task <cnpOnlineResponse> SendToCnpAsync(cnpOnlineRequest request, CancellationToken cancellationToken)
        {
            var xmlRequest  = request.Serialize(this.config.GetVersion());
            var xmlResponse = await this.communication.HttpPostAsync(xmlRequest, this.config, cancellationToken).ConfigureAwait(false);

            return(this.DeserializeResponse(xmlResponse));
        }
예제 #2
0
        /*
         * Creates a CNP Online request.
         */
        private cnpOnlineRequest CreateCnpOnlineRequest()
        {
            // Create the request.
            var request = new cnpOnlineRequest();

            request.merchantId  = this.config.GetValue("merchantId");
            request.version     = this.config.GetVersion().ToString();
            request.merchantSdk = CnpVersion.CurrentCNPSDKVersion;

            // Add the schema.
            if (this.config.GetVersion() < new XMLVersion(12, 0))
            {
                request.SetAdditionalAttribute("xmlns", LITLE_NAMESPACE);
            }
            else
            {
                request.SetAdditionalAttribute("xmlns", CNP_NAMESPACE);
            }

            // Create and add the authentication.
            var authentication = new authentication();

            authentication.password = this.config.GetValue("password");
            authentication.user     = this.config.GetValue("username");
            request.authentication  = authentication;

            // Return the request.
            return(request);
        }
예제 #3
0
        /*
         * Sends a CNP request.
         */
        private cnpOnlineResponse SendToCnp(cnpOnlineRequest request)
        {
            var xmlRequest  = XML_HEADER + request.Serialize(this.config.GetVersion());
            var xmlResponse = this.communication.HttpPost(xmlRequest, config);

            return(this.DeserializeResponse(xmlResponse));
        }
예제 #4
0
        private async Task <cnpOnlineResponse> SendToCnpAsync(cnpOnlineRequest request, CancellationToken cancellationToken)
        {
            string xmlRequest  = request.Serialize();
            string xmlResponse = await _communication.HttpPostAsync(xmlRequest, _config, cancellationToken).ConfigureAwait(false);

            return(DeserializeResponse(xmlResponse));
        }
        private cnpOnlineResponse SendToCnp(cnpOnlineRequest request)
        {
            var xmlRequest  = request.Serialize();
            var xmlResponse = _communication.HttpPost(xmlRequest, _config);

            try
            {
                var cnpOnlineResponse = DeserializeObject(xmlResponse);
                Console.WriteLine(cnpOnlineResponse.response);
                if (!"0".Equals(cnpOnlineResponse.response))
                {
                    if ("2".Equals(cnpOnlineResponse.response) || "3".Equals(cnpOnlineResponse.response))
                    {
                        throw new CnpInvalidCredentialException(cnpOnlineResponse.message);
                    }
                    else if ("4".Equals(cnpOnlineResponse.response))
                    {
                        throw new CnpConnectionLimitExceededException(cnpOnlineResponse.message);
                    }
                    else if ("5".Equals(cnpOnlineResponse.response))
                    {
                        throw new CnpObjectionableContentException(cnpOnlineResponse.message);
                    }
                    else
                    {
                        throw new CnpOnlineException(cnpOnlineResponse.message);
                    }
                }
                return(cnpOnlineResponse);
            }
            catch (InvalidOperationException ioe)
            {
                throw new CnpOnlineException("Error validating xml data against the schema", ioe);
            }
        }
예제 #6
0
        public static string SerializeObject(cnpOnlineRequest req)
        {
            var serializer = new XmlSerializer(typeof(cnpOnlineRequest));
            var ms         = new MemoryStream();

            serializer.Serialize(ms, req);
            return(Encoding.UTF8.GetString(ms.GetBuffer()));//return string is UTF8 encoded.
        }// serialize the xml
예제 #7
0
        private cnpOnlineRequest CreateCnpOnlineRequest()
        {
            var request = new cnpOnlineRequest();

            request.merchantId  = _config["merchantId"];
            request.merchantSdk = "DotNet;12.7.1";
            var authentication = new authentication();

            authentication.password = _config["password"];
            authentication.user     = _config["username"];
            request.authentication  = authentication;
            return(request);
        }
예제 #8
0
        virtual public String SerializeObject(cnpOnlineRequest req)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(cnpOnlineRequest));
            MemoryStream  ms         = new MemoryStream();

            try
            {
                serializer.Serialize(ms, req);
            }
            catch (XmlException e)
            {
                throw new CnpOnlineException("Error in sending request to Cnp!", e);
            }
            return(Encoding.UTF8.GetString(ms.GetBuffer()));//return string is UTF8 encoded.
        }// serialize the xml
예제 #9
0
        private cnpOnlineResponse SendToCnp(cnpOnlineRequest request)
        {
            var xmlRequest  = request.Serialize();
            var xmlResponse = _communication.HttpPost(xmlRequest, _config);

            if (xmlResponse == null)
            {
                throw new WebException("Could not retrieve response from server for given request");
            }
            try
            {
                var cnpOnlineResponse = DeserializeObject(xmlResponse);
                if (_config.ContainsKey("printxml") && Convert.ToBoolean(_config["printxml"]))
                {
                    Console.WriteLine(cnpOnlineResponse.response);
                }
                if (!"0".Equals(cnpOnlineResponse.response))
                {
                    if ("2".Equals(cnpOnlineResponse.response) || "3".Equals(cnpOnlineResponse.response))
                    {
                        throw new CnpInvalidCredentialException(cnpOnlineResponse.message);
                    }
                    else if ("4".Equals(cnpOnlineResponse.response))
                    {
                        throw new CnpConnectionLimitExceededException(cnpOnlineResponse.message);
                    }
                    else if ("5".Equals(cnpOnlineResponse.response))
                    {
                        throw new CnpObjectionableContentException(cnpOnlineResponse.message);
                    }
                    else
                    {
                        throw new CnpOnlineException(cnpOnlineResponse.message);
                    }
                }
                return(cnpOnlineResponse);
            }
            catch (InvalidOperationException ioe)
            {
                throw new CnpOnlineException("Error validating xml data against the schema", ioe);
            }
        }
예제 #10
0
        private cnpOnlineRequest CreateRequest(transactionRequest transaction)
        {
            cnpOnlineRequest request = CreateCnpOnlineRequest();

            if (transaction is transactionTypeWithReportGroup)
            {
                FillInReportGroup((transactionTypeWithReportGroup)transaction);
            }
            else if (transaction is transactionTypeWithReportGroupAndPartial)
            {
                FillInReportGroup((transactionTypeWithReportGroupAndPartial)transaction);
            }
            if (transaction is authorization)
            {
                request.authorization = (authorization)transaction;
            }
            else if (transaction is authReversal)
            {
                request.authReversal = (authReversal)transaction;
            }
            else if (transaction is capture)
            {
                request.capture = (capture)transaction;
            }
            else if (transaction is captureGivenAuth)
            {
                request.captureGivenAuth = (captureGivenAuth)transaction;
            }
            else if (transaction is credit)
            {
                request.credit = (credit)transaction;
            }
            else if (transaction is echeckCredit)
            {
                request.echeckCredit = (echeckCredit)transaction;
            }
            else if (transaction is echeckRedeposit)
            {
                request.echeckRedeposit = (echeckRedeposit)transaction;
            }
            else if (transaction is echeckSale)
            {
                request.echeckSale = (echeckSale)transaction;
            }
            else if (transaction is echeckVerification)
            {
                request.echeckVerification = (echeckVerification)transaction;
            }
            else if (transaction is forceCapture)
            {
                request.forceCapture = (forceCapture)transaction;
            }
            else if (transaction is sale)
            {
                request.sale = (sale)transaction;
            }
            else if (transaction is registerTokenRequestType)
            {
                request.registerTokenRequest = (registerTokenRequestType)transaction;
            }
            else if (transaction is voidTxn)
            {
                request.voidTxn = (voidTxn)transaction;
            }
            else if (transaction is echeckVoid)
            {
                request.echeckVoid = (echeckVoid)transaction;
            }
            else if (transaction is updateCardValidationNumOnToken)
            {
                request.updateCardValidationNumOnToken = (updateCardValidationNumOnToken)transaction;
            }
            else if (transaction is cancelSubscription)
            {
                request.cancelSubscription = (cancelSubscription)transaction;
            }
            else if (transaction is updateSubscription)
            {
                request.updateSubscription = (updateSubscription)transaction;
            }
            else if (transaction is activate)
            {
                request.activate = (activate)transaction;
            }
            else if (transaction is deactivate)
            {
                request.deactivate = (deactivate)transaction;
            }
            else if (transaction is load)
            {
                request.load = (load)transaction;
            }
            else if (transaction is unload)
            {
                request.unload = (unload)transaction;
            }
            else if (transaction is balanceInquiry)
            {
                request.balanceInquiry = (balanceInquiry)transaction;
            }
            else if (transaction is createPlan)
            {
                request.createPlan = (createPlan)transaction;
            }
            else if (transaction is updatePlan)
            {
                request.updatePlan = (updatePlan)transaction;
            }
            else if (transaction is refundReversal)
            {
                request.refundReversal = (refundReversal)transaction;
            }
            else if (transaction is depositReversal)
            {
                request.depositReversal = (depositReversal)transaction;
            }
            else if (transaction is activateReversal)
            {
                request.activateReversal = (activateReversal)transaction;
            }
            else if (transaction is deactivateReversal)
            {
                request.deactivateReversal = (deactivateReversal)transaction;
            }
            else if (transaction is loadReversal)
            {
                request.loadReversal = (loadReversal)transaction;
            }
            else if (transaction is unloadReversal)
            {
                request.unloadReversal = (unloadReversal)transaction;
            }
            else if (transaction is fraudCheck)
            {
                request.fraudCheck = (fraudCheck)transaction;
            }
            else if (transaction is giftCardAuthReversal)
            {
                request.giftCardAuthReversal = (giftCardAuthReversal)transaction;
            }
            else if (transaction is giftCardCapture)
            {
                request.giftCardCapture = (giftCardCapture)transaction;
            }
            else if (transaction is giftCardCredit)
            {
                request.giftCardCredit = (giftCardCredit)transaction;
            }
            else if (transaction is queryTransaction)
            {
                request.queryTransaction = (queryTransaction)transaction;
            }
            else if (transaction is fastAccessFunding)
            {
                request.fastAccessFunding = (fastAccessFunding)transaction;
            }
            else if (transaction is payFacCredit)
            {
                request.payFacCredit = (payFacCredit)transaction;
            }
            else if (transaction is payFacDebit)
            {
                request.payFacDebit = (payFacDebit)transaction;
            }
            else if (transaction is physicalCheckCredit)
            {
                request.physicalCheckCredit = (physicalCheckCredit)transaction;
            }
            else if (transaction is physicalCheckDebit)
            {
                request.physicalCheckDebit = (physicalCheckDebit)transaction;
            }
            else if (transaction is reserveCredit)
            {
                request.reserveCredit = (reserveCredit)transaction;
            }
            else if (transaction is reserveDebit)
            {
                request.reserveDebit = (reserveDebit)transaction;
            }
            else if (transaction is submerchantCredit)
            {
                request.submerchantCredit = (submerchantCredit)transaction;
            }
            else if (transaction is submerchantDebit)
            {
                request.submerchantDebit = (submerchantDebit)transaction;
            }
            else if (transaction is vendorCredit)
            {
                request.vendorCredit = (vendorCredit)transaction;
            }
            else if (transaction is translateToLowValueTokenRequest)
            {
                request.translateToLowValueTokenRequest = (translateToLowValueTokenRequest)transaction;
            }
            else if (transaction is vendorDebit)
            {
                request.vendorDebit = (vendorDebit)transaction;
            }
            else
            {
                throw new NotImplementedException("Support for type: " + transaction.GetType().Name +
                                                  " not implemented.");
            }
            return(request);
        }