Beispiel #1
0
        public static DepositSummary MapDepositSummary(JsonDoc doc)
        {
            var summary = new DepositSummary {
                DepositId   = doc.GetValue <string>("id"),
                DepositDate = doc.GetValue <DateTime>("time_created"),
                Status      = doc.GetValue <string>("status"),
                Type        = doc.GetValue <string>("funding_type"),
                Amount      = doc.GetValue <string>("amount").ToAmount(),
                Currency    = doc.GetValue <string>("currency"),

                MerchantNumber    = doc.Get("system")?.GetValue <string>("mid"),
                MerchantHierarchy = doc.Get("system")?.GetValue <string>("hierarchy"),
                MerchantName      = doc.Get("system")?.GetValue <string>("name"),
                MerchantDbaName   = doc.Get("system")?.GetValue <string>("dba"),

                SalesTotalCount  = doc.Get("sales")?.GetValue <int>("count") ?? default(int),
                SalesTotalAmount = doc.Get("sales")?.GetValue <string>("amount").ToAmount(),

                RefundsTotalCount  = doc.Get("refunds")?.GetValue <int>("count") ?? default(int),
                RefundsTotalAmount = doc.Get("refunds")?.GetValue <string>("amount").ToAmount(),

                ChargebackTotalCount  = doc.Get("disputes")?.Get("chargebacks")?.GetValue <int>("count") ?? default(int),
                ChargebackTotalAmount = doc.Get("disputes")?.Get("chargebacks")?.GetValue <string>("amount").ToAmount(),

                AdjustmentTotalCount  = doc.Get("disputes")?.Get("reversals")?.GetValue <int>("count") ?? default(int),
                AdjustmentTotalAmount = doc.Get("disputes")?.Get("reversals")?.GetValue <string>("amount").ToAmount(),

                FeesTotalAmount = doc.Get("fees")?.GetValue <string>("amount").ToAmount(),
            };

            return(summary);
        }
Beispiel #2
0
        public HashSet <MyTextValue> GetDepositSummaryList()
        {
            string key = "DEPOSIT_SUMMARY";

            if (null == _Cache[key])
            {
                HashSet <MyTextValue> categories = new HashSet <MyTextValue>();
                CacheItemPolicy       policy     = CreateCacheItemPolicy();

                var query =
                    DepositSummary.GetAll()
                    .Select(x => new MyTextValue
                {
                    Text     = x.Text,
                    Value    = x.Value,
                    Disabled = true
                }
                            ).ToList();

                categories = new HashSet <MyTextValue>(query);
                _Cache.Set(key, categories, policy);
            }

            return((HashSet <MyTextValue>)_Cache[key]);
        }
        public void ReportDepositDetail()
        {
            string         depositId = "DEP_2342423423";
            DepositSummary response  = ReportingService.DepositDetail(depositId)
                                       .Execute();

            Assert.IsNotNull(response);
            Assert.IsTrue(response is DepositSummary);
            Assert.AreEqual(depositId, response.DepositId);
        }
Beispiel #4
0
        public void MapDepositSummaryTest_NullDates()
        {
            // Arrange
            string rawJson = "{\"id\":\"DEP_2342423423\",\"time_created\":\"\",\"status\":\"FUNDED\",\"funding_type\":\"CREDIT\",\"amount\":\"11400\",\"currency\":\"USD\",\"aggregation_model\":\"H-By Date\",\"bank_transfer\":{\"masked_account_number_last4\":\"XXXXXX9999\",\"bank\":{\"code\":\"XXXXX0001\"}},\"system\":{\"mid\":\"101023947262\",\"hierarchy\":\"055-70-024-011-019\",\"name\":\"XYZ LTD.\",\"dba\":\"XYZ Group\"},\"sales\":{\"count\":4,\"amount\":\"12400\"},\"refunds\":{\"count\":1,\"amount\":\"-1000\"},\"discounts\":{\"count\":0,\"amount\":\"\"},\"tax\":{\"count\":0,\"amount\":\"\"},\"disputes\":{\"chargebacks\":{\"count\":0,\"amount\":\"\"},\"reversals\":{\"count\":0,\"amount\":\"\"}},\"fees\":{\"amount\":\"\"},\"action\":{\"id\":\"ACT_TWdmMMOBZ91iQX1DcvxYermuVJ6E6h\",\"type\":\"DEPOSIT_SINGLE\",\"time_created\":\"\",\"result_code\":\"SUCCESS\",\"app_id\":\"JF2GQpeCrOivkBGsTRiqkpkdKp67Gxi0\",\"app_name\":\"test_app\"}}";

            JsonDoc doc = JsonDoc.Parse(rawJson);

            // Act
            DepositSummary deposit = GpApiMapping.MapDepositSummary(doc);

            // Assert
            Assert.AreEqual(doc.GetValue <string>("id"), deposit.DepositId);
            Assert.IsNull(deposit.DepositDate);
            Assert.AreEqual(doc.GetValue <string>("status"), deposit.Status);
            Assert.AreEqual(doc.GetValue <string>("funding_type"), deposit.Type);
            Assert.AreEqual(doc.GetValue <string>("amount").ToAmount(), deposit.Amount);
            Assert.AreEqual(doc.GetValue <string>("currency"), deposit.Currency);

            Assert.AreEqual(doc.Get("system")?.GetValue <string>("mid"), deposit.MerchantNumber);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("hierarchy"), deposit.MerchantHierarchy);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("name"), deposit.MerchantName);
            Assert.AreEqual(doc.Get("system")?.GetValue <string>("dba"), deposit.MerchantDbaName);

            Assert.AreEqual(doc.Get("sales")?.GetValue <int>("count") ?? default(int), deposit.SalesTotalCount);
            Assert.AreEqual(doc.Get("sales")?.GetValue <string>("amount").ToAmount(), deposit.SalesTotalAmount);

            Assert.AreEqual(doc.Get("refunds")?.GetValue <int>("count") ?? default(int), deposit.RefundsTotalCount);
            Assert.AreEqual(doc.Get("refunds")?.GetValue <string>("amount").ToAmount(), deposit.RefundsTotalAmount);

            Assert.AreEqual(doc.Get("disputes")?.Get("chargebacks")?.GetValue <int>("count") ?? default(int), deposit.ChargebackTotalCount);
            Assert.AreEqual(doc.Get("disputes")?.Get("chargebacks")?.GetValue <string>("amount").ToAmount(), deposit.ChargebackTotalAmount);

            Assert.AreEqual(doc.Get("disputes")?.Get("reversals")?.GetValue <int>("count") ?? default(int), deposit.AdjustmentTotalCount);
            Assert.AreEqual(doc.Get("disputes")?.Get("reversals")?.GetValue <string>("amount").ToAmount(), deposit.AdjustmentTotalAmount);

            Assert.AreEqual(doc.Get("fees")?.GetValue <string>("amount").ToAmount(), deposit.FeesTotalAmount);
        }
Beispiel #5
0
        private T MapResponse <T>(string response, ReportType reportType)
        {
            var doc = JsonDoc.Parse(response);

            if (doc.Has("error"))
            {
                var error        = doc.Get("error");
                var errorType    = error.GetValue <string>("errorType");
                var errorCode    = error.GetValue <string>("errorCode");
                var errorMessage = error.GetValue <string>("errorMsg");

                // If it's 1205, then it's no data... which is not an error
                if (errorCode != "1205")
                {
                    throw new GatewayException(errorMessage, errorCode, errorType);
                }
            }

            Func <string, DateTime?> formatDate = (date) => {
                if (!string.IsNullOrEmpty(date))
                {
                    var pattern = "yyyy-MM-dd";
                    if (date.Contains(" "))
                    {
                        pattern += " hh:mm:ss";
                    }

                    return(DateTime.ParseExact(date, pattern, CultureInfo.InvariantCulture));
                }
                return(null);
            };

            T rvalue = Activator.CreateInstance <T>();

            if (reportType.HasFlag(ReportType.FindTransactions))
            {
                Func <JsonDoc, TransactionSummary> hydrateTransactionSummary = (root) => {
                    var summary = new TransactionSummary {
                        MerchantHierarchy    = root.GetValue <string>("merchantHierarchy"),
                        MerchantName         = root.GetValue <string>("merchantName"),
                        MerchantDbaName      = root.GetValue <string>("merchantDbaName"),
                        MerchantNumber       = root.GetValue <string>("merchantNumber"),
                        MerchantCategory     = root.GetValue <string>("merchantCategory"),
                        DepositDate          = formatDate(root.GetValue <string>("transactionDepositDate")),
                        DepositReference     = root.GetValue <string>("transactionDepositReference"),
                        DepositType          = root.GetValue <string>("transactionDepositType"),
                        ServiceName          = root.GetValue <string>("transactionType"),
                        OrderId              = root.GetValue <string>("transactionOrderId"),
                        TransactionLocalDate = formatDate(root.GetValue <string>("transactionLocalTime")),
                        TransactionDate      = formatDate(root.GetValue <string>("transactionTime")),
                        Amount                 = root.GetValue <string>("transactionAmount").ToAmount(),
                        Currency               = root.GetValue <string>("transactionCurrency"),
                        DepositAmount          = root.GetValue <string>("transactionMerchantAmount").ToAmount(),
                        DepositCurrency        = root.GetValue <string>("transactionMerchantCurrency"),
                        MerchantId             = root.GetValue <string>("transactionMid"),
                        TerminalId             = root.GetValue <string>("transactionTid"),
                        BatchSequenceNumber    = root.GetValue <string>("transactionBatchReference"),
                        EntryMode              = root.GetValue <string>("transactionEntryMode"),
                        AquirerReferenceNumber = root.GetValue <string>("transactionArn"),
                        ReferenceNumber        = root.GetValue <string>("transactionReferenceNumber"),
                        CardType               = root.GetValue <string>("transactionCardType"),
                        MaskedCardNumber       = root.GetValue <string>("transactionCardNo"),
                        AuthCode               = root.GetValue <string>("transactionAuthcode"),
                        SchemeReferenceData    = root.GetValue <string>("transactionSrd"),
                        AdjustmentAmount       = root.GetValue <string>("transactionAdjustAmount").ToAmount(),
                        AdjustmentCurrency     = root.GetValue <string>("transactionAdjustCurrency"),
                        AdjustmentReason       = root.GetValue <string>("transactionAdjustReason")
                    };

                    return(summary);
                };

                if (rvalue is IEnumerable <TransactionSummary> )
                {
                    var list = rvalue as List <TransactionSummary>;
                    if (doc.Has("merchantTransactionDetails"))
                    {
                        foreach (var transaction in doc.GetEnumerator("merchantTransactionDetails"))
                        {
                            list.Add(hydrateTransactionSummary(transaction));
                        }
                    }
                }
            }
            else if (reportType.HasFlag(ReportType.FindDeposits))
            {
                Func <JsonDoc, DepositSummary> hydrateDepositSummary = (root) => {
                    var summary = new DepositSummary {
                        MerchantHierarchy = root.GetValue <string>("merchantHierarchy"),
                        MerchantName      = root.GetValue <string>("merchantName"),
                        MerchantDbaName   = root.GetValue <string>("merchantDba"),
                        MerchantNumber    = root.GetValue <string>("merchantNumber"),
                        MerchantCategory  = root.GetValue <string>("merchantCategory"),
                        DepositDate       = DateTime.Parse(root.GetValue <string>("depositDate")),
                        Reference         = root.GetValue <string>("depositReference"),
                        Amount            = root.GetValue <string>("depositPaymentAmount").ToAmount(),
                        Currency          = root.GetValue <string>("depositPaymentCurrency"),
                        Type                       = root.GetValue <string>("depositType"),
                        RoutingNumber              = root.GetValue <string>("depositRoutingNumber"),
                        AccountNumber              = root.GetValue <string>("depositAccountNumber"),
                        Mode                       = root.GetValue <string>("depositMode"),
                        SummaryModel               = root.GetValue <string>("depositSummaryModel"),
                        SalesTotalCount            = root.GetValue <int>("salesTotalNo"),
                        SalesTotalAmount           = root.GetValue <string>("salesTotalAmount").ToAmount(),
                        SalesTotalCurrency         = root.GetValue <string>("salesTotalCurrency"),
                        RefundsTotalCount          = root.GetValue <int>("refundsTotalNo"),
                        RefundsTotalAmount         = root.GetValue <string>("refundsTotalAmount").ToAmount(),
                        RefundsTotalCurrency       = root.GetValue <string>("refundsTotalCurrency"),
                        ChargebackTotalCount       = root.GetValue <int>("disputeCbTotalNo"),
                        ChargebackTotalAmount      = root.GetValue <string>("disputeCbTotalAmount").ToAmount(),
                        ChargebackTotalCurrency    = root.GetValue <string>("disputeCbTotalCurrency"),
                        RepresentmentTotalCount    = root.GetValue <int>("disputeRepresentmentTotalNo"),
                        RepresentmentTotalAmount   = root.GetValue <string>("disputeRepresentmentTotalAmount").ToAmount(),
                        RepresentmentTotalCurrency = root.GetValue <string>("disputeRepresentmentTotalCurrency"),
                        FeesTotalAmount            = root.GetValue <string>("feesTotalAmount").ToAmount(),
                        FeesTotalCurrency          = root.GetValue <string>("feesTotalCurrency"),
                        AdjustmentTotalCount       = root.GetValue <int>("adjustmentTotalNumber"),
                        AdjustmentTotalAmount      = root.GetValue <string>("adjustmentTotalAmount").ToAmount(),
                        AdjustmentTotalCurrency    = root.GetValue <string>("adjustmentTotalCurrency")
                    };
                    return(summary);
                };

                if (rvalue is IEnumerable <DepositSummary> )
                {
                    var list = rvalue as List <DepositSummary>;
                    if (doc.Has("merchantDepositDetails"))
                    {
                        foreach (var deposit in doc.GetEnumerator("merchantDepositDetails"))
                        {
                            list.Add(hydrateDepositSummary(deposit));
                        }
                    }
                }
            }
            else if (reportType.HasFlag(ReportType.FindDisputes))
            {
                Func <JsonDoc, DisputeSummary> hydrateDisputeSummary = (root) => {
                    var summary = new DisputeSummary {
                        MerchantHierarchy = root.GetValue <string>("merchantHierarchy"),
                        MerchantName      = root.GetValue <string>("merchantName"),
                        MerchantDbaName   = root.GetValue <string>("merchantDba"),
                        MerchantNumber    = root.GetValue <string>("merchantNumber"),
                        MerchantCategory  = root.GetValue <string>("merchantCategory"),
                        DepositDate       = formatDate(root.GetValue <string>("disputeDepositDate")),
                        DepositReference  = root.GetValue <string>("disputeDepositReference"),
                        DepositType       = root.GetValue <string>("disputeDepositType"),
                        Type                        = root.GetValue <string>("disputeType"),
                        CaseAmount                  = root.GetValue <string>("disputeCaseAmount").ToAmount(),
                        CaseCurrency                = root.GetValue <string>("disputeCaseCurrency"),
                        CaseStatus                  = root.GetValue <string>("disputeCaseStatus"),
                        CaseDescription             = root.GetValue <string>("disputeCaseDescription"),
                        TransactionOrderId          = root.GetValue <string>("disputeTransactionOrderId"),
                        TransactionLocalTime        = formatDate(root.GetValue <string>("disputeTransactionLocalTime")),
                        TransactionTime             = formatDate(root.GetValue <string>("disputeTransactionTime")),
                        TransactionType             = root.GetValue <string>("disputeTransactionType"),
                        TransactionAmount           = root.GetValue <string>("disputeTransactionAmount").ToAmount(),
                        TransactionCurrency         = root.GetValue <string>("disputeTransactionCurrency"),
                        CaseNumber                  = root.GetValue <string>("disputeCaseNo"),
                        CaseTime                    = formatDate(root.GetValue <string>("disputeCaseTime")),
                        CaseId                      = root.GetValue <string>("disputeCaseId"),
                        CaseIdTime                  = formatDate(root.GetValue <string>("disputeCaseIdTime")),
                        CaseMerchantId              = root.GetValue <string>("disputeCaseMid"),
                        CaseTerminalId              = root.GetValue <string>("disputeCaseTid"),
                        TransactionARN              = root.GetValue <string>("disputeTransactionARN"),
                        TransactionReferenceNumber  = root.GetValue <string>("disputeTransactionReferenceNumber"),
                        TransactionSRD              = root.GetValue <string>("disputeTransactionSRD"),
                        TransactionAuthCode         = root.GetValue <string>("disputeTransactionAuthcode"),
                        TransactionCardType         = root.GetValue <string>("disputeTransactionCardType"),
                        TransactionMaskedCardNumber = root.GetValue <string>("disputeTransactionCardNo"),
                        Reason                      = root.GetValue <string>("disputeReason"),
                        IssuerComment               = root.GetValue <string>("disputeIssuerComment"),
                        IssuerCaseNumber            = root.GetValue <string>("disputeIssuerCaseNo"),
                        DisputeAmount               = root.GetValue <string>("disputeAmount").ToAmount(),
                        DisputeCurrency             = root.GetValue <string>("disputeCurrency"),
                        DisputeCustomerAmount       = root.GetValue <string>("disputeCustomerAmount").ToAmount(),
                        DisputeCustomerCurrency     = root.GetValue <string>("disputeCustomerCurrency"),
                        RespondByDate               = formatDate(root.GetValue <string>("disputeRespondByDate")),
                        CaseOriginalReference       = root.GetValue <string>("disputeCaseOriginalReference")
                    };
                    return(summary);
                };

                if (rvalue is IEnumerable <DisputeSummary> )
                {
                    var list = rvalue as List <DisputeSummary>;
                    if (doc.Has("merchantDisputeDetails"))
                    {
                        foreach (var dispute in doc.GetEnumerator("merchantDisputeDetails"))
                        {
                            list.Add(hydrateDisputeSummary(dispute));
                        }
                    }
                }
            }

            return(rvalue);
        }