예제 #1
0
        /// <summary>
        /// Acknowledge a payment
        /// </summary>
        /// <param name="req">Request parameters to do the request to Viking Spots</param>
        /// <param name="callback">Delegate that handles the callback</param>
        public POSPaymentAcknowledgeResult PaymentAcknowledge(POSPaymentAcknowledgeRequest req, ref HttpStatusCode code)
        {
            // This is a POST
            RestRequest request = new RestRequest(string.Format("posacknowledgepayment/"), 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<POSPaymentAcknowledgeResult>(response.Content);
            }

            return null;
        }
예제 #2
0
        /// <summary>
        /// Do API request AcknowledgePayment 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 AcknowledgePayment(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");
            string amountString = doc.DocumentElement.GetAttribute("amt");
            amountString = amountString.Insert(amountString.Length - 2, ".");
            IFormatProvider culture = new CultureInfo("en-us");
            double amount = Convert.ToDouble(amountString, culture);
            string card_pan = doc.DocumentElement.GetAttribute("pan");
            string payment_type = doc.DocumentElement.GetAttribute("pmt");

            POSPaymentAcknowledgeRequest request = new POSPaymentAcknowledgeRequest(terminal_id, coupon_id, merchant_id, amount, card_pan, payment_type);

            HttpStatusCode code = HttpStatusCode.NotFound;
            // Call posacknowledgepayment
            POSPaymentAcknowledgeResult response = api.PaymentAcknowledge(request, ref code);

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

                //writer.WriteAttributeString("dsp", "Successfully acknowledged payment!");
                //writer.WriteAttributeString("prt", "Yay!");
            });
        }