Ejemplo n.º 1
0
        public void WritePayoutTransaction(
            ShopifyPayoutTransaction transaction)
        {
            var transObject = transaction.Json.DeserializeFromJson <PayoutTransaction>();

            if (transObject.type == "payout")
            {
                _logger.Info(
                    $"Skipping Transaction Payout Id: {transaction.ShopifyPayoutId} - " +
                    $"Transaction Id: {transaction.ShopifyPayoutTransId} " +
                    $"- type = payout");
                return;
            }

            var receipt     = transObject.amount > 0 ? transObject.amount : 0;
            var disbursment = transObject.amount < 0 ? transObject.amount : 0;

            // *** Careful about juggling all of this
            var tranDesc   = $"Shopify Payout Id: {transObject.payout_id} - Payout Trans Id: {transObject.id}";
            var invoiceNbr = $"Shopify Order Trans Id: {transObject.source_order_transaction_id}";
            var extTranID  = $"Shopify Order Id: {transObject.source_order_id}";
            var extRefNbr  = $"Shopify Payout Trans Id: {transObject.id}";

            var schema = PX.Soap.Helper.GetSchema <CA306500Content>(_screen);

            var commands
                = new List <Command>()
                  .AddCommand(schema.Details.ServiceCommands.NewRow)
                  .AddCommand(schema.Details.ExtTranID, extTranID)
                  .AddCommand(schema.Details.ExtRefNbr, extRefNbr)
                  .AddCommand(schema.Details.TranDesc, tranDesc)
                  .AddCommand(schema.Details.InvoiceNbr, invoiceNbr)
                  .AddCommand(schema.Details.Receipt, receipt.ToString())
                  .AddCommand(schema.Details.Disbursement, disbursment.ToString())
                  .AddCommand(schema.Actions.Save);

            var results = _screen.CA306500Submit(commands.ToArray());

            //_persistRepository
            //    .UpdatePayoutHeaderAcumaticaImport(
            //            transaction.ShopifyPayoutId,
            //            transaction.ShopifyPayoutTransId,
            //            DateTime.UtcNow,
            //            extRefNbr);

            _logger.Info(
                $"Created Transaction Payout Id: {transaction.ShopifyPayoutId} - " +
                $"Transaction Id: {transaction.ShopifyPayoutTransId} " +
                $" in Acumatica");
        }
        public void UpsertPayoutTransactions(
            PayoutDetail transactions, long shopifyPayoutId)
        {
            var filteredTransactions
                = transactions
                  .transactions
                  .Where(x => x.payout_id == shopifyPayoutId).ToList();

            var payoutHeader = _persistRepository.RetrievePayout(shopifyPayoutId);

            foreach (var transaction in filteredTransactions)
            {
                var existingRecord =
                    _persistRepository.RetrievePayoutTransaction(
                        transaction.payout_id.Value, transaction.id);

                if (existingRecord != null)
                {
                    _logger.Debug(
                        $"Transaction already exists for " +
                        $"Payout Id: {transaction.payout_id} - " +
                        $"(Transaction) Id {transaction.id}");

                    existingRecord.Json        = transaction.SerializeToJson();
                    existingRecord.LastUpdated = DateTime.UtcNow;
                }
                else
                {
                    _logger.Debug(
                        $"Creating Transcation for " +
                        $"Payout Id: {transaction.payout_id} - " +
                        $"(Transaction) Id {transaction.id}");

                    var newTransaction = new ShopifyPayoutTransaction()
                    {
                        MonsterParentId      = payoutHeader.Id,
                        ShopifyPayoutId      = transaction.payout_id.Value,
                        ShopifyPayoutTransId = transaction.id,
                        ShopifyOrderId       = transaction.source_order_id,
                        Type        = transaction.type,
                        Json        = transaction.SerializeToJson(),
                        CreatedDate = DateTime.UtcNow,
                        LastUpdated = DateTime.UtcNow,
                    };

                    _persistRepository.InsertPayoutTransaction(newTransaction);
                }
            }
        }
Ejemplo n.º 3
0
 public void InsertPayoutTransaction(
     ShopifyPayoutTransaction transaction)
 {
     Entities.ShopifyPayoutTransactions.Add(transaction);
     Entities.SaveChanges();
 }