static StripeRefundTransaction StripeRefundToStripeTransaction(StripeRefund r)
        {
            var trans = new StripeRefundTransaction()
            {
                RefundId                    = r.Id,
                TransactionType             = r.Object,
                Amount                      = (-1) * r.Amount / 100m,
                Reason                      = r.Reason,
                Status                      = r.Status,
                BalanceTransactionId        = r.BalanceTransactionId,
                BalanceTransaction          = JsonConvert.SerializeObject(r.BalanceTransaction),
                FailureBalanceTransactionId = r.FailureBalanceTransactionId,
                FailureBalanceTransaction   = processNull(JsonConvert.SerializeObject(r.FailureBalanceTransaction)),
                FailureReason               = r.FailureReason,
                ChargeID                    = r.ChargeId,
                Charge                      = JsonConvert.SerializeObject(r.Charge),
                CreatedTime                 = r.Created.ToUniversalTime(),
                Currency                    = r.Currency,
                Description                 = r.Description,
                Metadata                    = JsonConvert.SerializeObject(r.Metadata),
                ReceiptNumber               = r.ReceiptNumber
            };

            return(trans);
        }
        public static void UpsertStripeRefunds(StripeRefundTransaction trans, TraceWriter log)
        {
            try
            {
                var cnnString = ConfigurationManager.ConnectionStrings["PP_ConnectionString"].ConnectionString;

                using (var connection = new SqlConnection(cnnString))
                {
                    connection.Open();


                    using (SqlCommand cmd = new SqlCommand(upsertCommand, connection))
                    {
                        cmd.Parameters.Add("@RefundID", SqlDbType.VarChar, 50).Value        = trans.RefundId ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@TransactionType", SqlDbType.VarChar, 25).Value = trans.TransactionType ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@Amount", SqlDbType.Decimal).Value = trans.Amount ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@Reason", SqlDbType.VarChar).Value = trans.Reason ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = trans.Status ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@BalanceTransactionId", SqlDbType.VarChar).Value        = trans.BalanceTransactionId ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@BalanceTransaction", SqlDbType.VarChar).Value          = trans.BalanceTransaction ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@FailureBalanceTransactionId", SqlDbType.VarChar).Value = trans.FailureBalanceTransactionId ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@FailureBalanceTransaction", SqlDbType.VarChar).Value   = trans.FailureBalanceTransaction ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@FailureReason", SqlDbType.VarChar).Value           = trans.FailureReason ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@ChargeID", SqlDbType.VarChar, 50).Value            = trans.ChargeID ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@Charge", SqlDbType.NVarChar).Value                 = trans.Charge ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@CreatedTime", SqlDbType.DateTime2).Value           = trans.CreatedTime;
                        cmd.Parameters.Add("@Currency", SqlDbType.VarChar, 10).Value            = trans.Currency ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@Description", SqlDbType.NVarChar).Value            = trans.Description ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@Metadata", SqlDbType.NVarChar).Value               = trans.Metadata ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@ReceiptNumber", SqlDbType.VarChar, 50).Value       = trans.ReceiptNumber ?? (object)DBNull.Value;
                        cmd.Parameters.Add("@RecordUpdatedDate", SqlDbType.DateTime2, 50).Value = DateTime.UtcNow;
                        var resultCount = cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("InsertStripeTransaction error", ex);
            }
        }