Exemple #1
0
        /// <summary>
        /// Charges the specified Payment Payload.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <param name="accessToken">The access token.</param>
        /// <returns></returns>
        public PaymentResult Charge(PaymentPayload payload, string accessToken)
        {
            string url = string.Format(Config.PAYMENT_ENDPOINT, Config.API_VERSION);

            var collection = new NameValueCollection
            {
                { "amount", payload.Amount },
                { "description", payload.Description },
                { "endUserId", payload.Number },
                { "referenceCode", payload.ReferenceCode },
                { "access_token", accessToken },
                { "transactionOperationStatus", Config.TRANSACTION_CHARGED }
            };

            string data = this.Post(url, Config.CONTENT_TYPE_FORM, collection);

            var result = new PaymentResult();

            if (data.Contains(Config.ERROR))
            {
                var jsonResponse = JsonConvert.DeserializeObject <ErrorResponse>(data);
                result.Result = null;
                result.Status = this.ResponseStatus;
                result.Status.StatusDescription = jsonResponse.Error;
                result.Status.StatusCode        = (int)HttpStatusCode.BadRequest;
            }
            else
            {
                var jsonPayment = string.IsNullOrEmpty(data) ? null : JsonConvert.DeserializeObject <PaymentResponse>(data);
                result.Result = jsonPayment;
                result.Status = this.ResponseStatus;
            }

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Charges the specified Payment Payload.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <param name="accessToken">The access token.</param>
        /// <returns></returns>
        public PaymentResult Charge(PaymentPayload payload, string accessToken)
        {
            string url = string.Format(Config.PAYMENT_ENDPOINT, Config.API_VERSION);

            var collection = new NameValueCollection
            {
                { "amount", payload.Amount },
                { "description", payload.Description },
                { "endUserId", payload.Number },
                { "referenceCode", payload.ReferenceCode},
                { "access_token", accessToken},
                { "transactionOperationStatus", Config.TRANSACTION_CHARGED }
            };

            string data = this.Post(url, Config.CONTENT_TYPE_FORM, collection);
            
            var result = new PaymentResult();

            if (data.Contains(Config.ERROR))
            {
                var jsonResponse = JsonConvert.DeserializeObject<ErrorResponse>(data);
                result.Result = null;
                result.Status = this.ResponseStatus;
                result.Status.StatusDescription = jsonResponse.Error;
                result.Status.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            else
            {
                var jsonPayment = string.IsNullOrEmpty(data) ? null : JsonConvert.DeserializeObject<PaymentResponse>(data);
                result.Result = jsonPayment;
                result.Status = this.ResponseStatus;
            }

            return result;
        }
Exemple #3
0
        static void TestPaymentService(string accessToken)
        {
            L("Payment Service Testing");
            GlobeLabs api = new GlobeLabs(accessToken);

            var payload = new PaymentPayload
            {
                Amount = "0.00",
                Description = "Charging API",
                Number = "9171234567",
                ReferenceCode = "45750000001"
            };

            /*
             * TIPS for Reference Code:
             * - Fetch the latest count for payment reference in your database
             * - Store it in a variable or update your table that holds the last reference count
             * - IMPORTANT: Make sure that your reference code is unique. Bad Request will occur if code is repeating
             */
            // If your short code is 21554575, then your reference code prefix is 4575 + 7digit numbers

            var result = api.Charge(payload);
            L("Data: " + result);            
        }
Exemple #4
0
 /// <summary>
 /// Charges the specified payload.
 /// </summary>
 /// <param name="payload">The payload.</param>
 /// <returns></returns>
 public PaymentResult Charge(PaymentPayload payload)
 {
     return(PaymentService.Instance.Charge(payload, this.AccessToken));
 }
Exemple #5
0
 /// <summary>
 /// Charges the specified payload.
 /// </summary>
 /// <param name="payload">The payload.</param>
 /// <returns></returns>
 public PaymentResult Charge(PaymentPayload payload)
 {
     return PaymentService.Instance.Charge(payload, this.AccessToken);
 }