示例#1
0
        public async Task CreateNewPaymentRequest()
        {
            PaymentRequest payment = new PaymentRequest();
            PayRequestOM   result  = await payment.CreateNewPaymentRequest("fiiitFmH9Cqk5B9gTH3LqZzBtqb8pxgHJ7sVqY", "abc", 10000, "test");

            Assert.IsNotNull(result);
        }
        public static async Task <ApiResponse> CreateNewPaymentRequest(string tag, long amount, string comment)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                Accounts       accounts    = new Accounts();
                PaymentRequest request     = new PaymentRequest();
                PayRequest     pay         = new PayRequest();
                AccountInfoOM  accountInfo = await accounts.GetNewAddress(tag);

                PayRequestOM result = await request.CreateNewPaymentRequest(accountInfo.Address, tag, amount, comment);

                if (result != null)
                {
                    pay.AccountId   = result.AccountId;
                    pay.Amount      = result.Amount;
                    pay.Comment     = result.Comment;
                    pay.Id          = result.Id;
                    pay.Tag         = result.Tag;
                    pay.Timestamp   = result.Timestamp;
                    response.Result = Newtonsoft.Json.Linq.JToken.FromObject(pay);
                }
                else
                {
                    response.Result = null;
                }
            }
            catch (ApiCustomException ex)
            {
                Logger.Singleton.Error(ex.Message);
                response.Error = new ApiError(ex.ErrorCode, ex.Message);
            }
            catch (Exception ex)
            {
                Logger.Singleton.Error(ex.Message);
                response.Error = new ApiError(ex.HResult, ex.Message);
            }
            return(response);
        }