예제 #1
0
        /// <summary>
        /// Do API request Redeem and send response back to the client
        /// </summary>
        /// <param name="doc">request XML</param>
        /// <param name="client">client that send the request</param>
        /// <param name="message">The message containing the request</param>
        private void Redeem(XmlDocument doc)
        {
            // Extract parameters from request
            int merchant_id = Convert.ToInt32(doc.DocumentElement.GetAttribute("mid"));
            int coupon_id = Convert.ToInt32(doc.DocumentElement.GetAttribute("deal"));
            string terminal_id = doc.DocumentElement.GetAttribute("tid");

            POSRedeemRequest request = new POSRedeemRequest(merchant_id, coupon_id, terminal_id);

            HttpStatusCode code = HttpStatusCode.NotFound;
            // Call posredeemcoupon
            POSRedeemResult response = api.Redeem(request, ref code);

            BuildAndSendResponse(code, response, (writer) =>
            {
                /*
                 * Example:
                 *
                 * <rsp code="0" seq="" dsp="" prt="" />
                 */

                //writer.WriteAttributeString("dsp", "Redeemed successfully!");
                //writer.WriteAttributeString("prt", "Yay!");
            });
        }
예제 #2
0
        /// <summary>
        /// Redeem a coupon
        /// </summary>
        /// <param name="req">Request parameters to do the request to Viking Spots</param>
        /// <param name="callback">Delegate that handles the callback</param>
        public POSRedeemResult Redeem(POSRedeemRequest req, ref HttpStatusCode code)
        {
            // This is a POST
            RestRequest request = new RestRequest(string.Format("posredeemcoupon/"), Method.POST);

            // We're posting a JSON structure in the body.
            request.RequestFormat = DataFormat.Json;

            // Note, RestSharp automatically serializes classes into JSON
            request.AddBody(req);

            IRestResponse response = apiClient.Post(request);

            code = response.StatusCode;

            // Check that we received a status we expect
            if (response.StatusCode == HttpStatusCode.OK ||
                response.StatusCode == HttpStatusCode.BadRequest ||
                response.StatusCode == HttpStatusCode.InternalServerError ||
                response.StatusCode == HttpStatusCode.PaymentRequired)
            {
                // Deserialize JSON into a manageable object
                return JsonConvert.DeserializeObject<POSRedeemResult>(response.Content);
            }

            return null;
        }