ReBill Payment (recurring payments)
Inheritance: EpayMessage
        /// <summary>
        /// Do the post to the gateway and retrieve the response
        /// </summary>
        /// <param name="paymentRequest">Payment details</param>
        /// <returns>true or false</returns>
        public bool ProcessRequest(RebillPaymentMessage paymentRequest)
        {
            var request = (HttpWebRequest)WebRequest.Create(Uri);
            request.Method = "POST";
            request.Timeout = ConnectionTimeout;
            request.ContentType = "application/x-www-form-urlencoded";
            request.KeepAlive = false;

            var requestBytes = System.Text.Encoding.ASCII.GetBytes(paymentRequest.AsXml());
            request.ContentLength = requestBytes.Length;

            // Send the data out over the wire

            var requestStream = request.GetRequestStream();
            requestStream.Write(requestBytes, 0, requestBytes.Length);
            requestStream.Close();

            HttpWebResponse response = null;

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException wex)
            {
                // for timeouts etc
                if (response == null)
                {
                    throw new EPayGatewayException { Exception = wex, Error = "Suspected Timeout" };
                }

                // try and get the error text
                var error = ReadResponseStream(response);

                throw new EPayGatewayException { Exception = wex, Error = error };
            }

            // get the response
            if (response == null || response.StatusCode != HttpStatusCode.OK)
            {
                return false;
            }

            Response = new RebillResponse(ReadResponseStream(response));

            return true;
        }
Esempio n. 2
0
        public bool Subscribe(string customerId, RebillPaymentMessage recurringPaymentDetails)
        {
            recurringPaymentDetails.CustomerRef = customerId;

            return _gateway.ProcessRequest(recurringPaymentDetails);
        }