Example #1
0
        public RefundResponse PartialRefund(long paymentId, double amount)
        {
            RefundResponse refund        = null;
            PartialRefund  partialRefund = new PartialRefund();

            try
            {
                partialRefund.amount = Convert.ToInt64(amount * 100);
            }
            catch (Exception ex)
            {
                throw new ResponseException(ex.Message);
            }


            RestResponse result = this.restClient.Post(String.Format("payments/{0}/refunds", paymentId.ToString()), Model.PartialRefund.toJson(partialRefund));

            if (result.StatusCode == STATUS_CREATED && !String.IsNullOrEmpty(result.Response))
            {
                refund = JsonConvert.DeserializeObject <RefundResponse>(result.Response);
            }
            else
            {
                if (isErrorResponse(result.StatusCode))
                {
                    throw new ResponseException(result.StatusCode.ToString(), JsonConvert.DeserializeObject <ErrorResponse>(result.Response));
                }
                else
                {
                    throw new ResponseException(result.StatusCode + " - " + result.Response);
                }
            }

            return(refund);
        }
Example #2
0
        public void toJsonTest()
        {
            PartialRefund refund = new PartialRefund();

            refund.amount = 1000;

            string result = PartialRefund.toJson(refund);

            Assert.AreEqual("{\"amount\":1000}", result);
        }