private void PushPaymentReleaseAndUpdateSync(ShopifyTransaction transactionRecord)
        {
            try
            {
                // Workarounds for Acumatica bug that prevents storage of Payment Nbr
                //
                var acumaticaPayment = RetrievePaymentWithMissingId(transactionRecord);

                // Release the actual Payment
                //
                _paymentClient.ReleasePayment(acumaticaPayment.AcumaticaRefNbr, acumaticaPayment.AcumaticaDocType);
                _syncOrderRepository.PaymentIsReleased(acumaticaPayment.ShopifyTransactionMonsterId);
                _syncOrderRepository.ResetOrderErrorCount(transactionRecord.ShopifyOrderId);
            }
            catch (Exception ex)
            {
                _systemLogger.Error(ex);
                _logService.Log($"Encounter error syncing {transactionRecord.LogDescriptor()}");
                _syncOrderRepository.IncreaseOrderErrorCount(transactionRecord.ShopifyOrderId);
                return;
            }
        }
Example #2
0
 public static string ReleasingTransaction(ShopifyTransaction transaction)
 {
     return($"Releasing Acumatica record for {transaction.LogDescriptor()}");
 }
Example #3
0
 public static string CreateAcumaticaCustomerRefund(ShopifyTransaction transaction)
 {
     return($"Creating Acumatica Customer Refund from {transaction.LogDescriptor()}");
 }
Example #4
0
 public static string UpdateAcumaticaPayment(ShopifyTransaction transaction)
 {
     return($"Updating Acumatica Payment from {transaction.LogDescriptor()}");
 }
Example #5
0
 public static string DetectedNewShopifyTransaction(ShopifyTransaction transaction)
 {
     return($"Detected new {transaction.LogDescriptor()}");
 }
        private void PushPaymentAndWriteSync(ShopifyTransaction transactionRecord, PaymentWrite payment)
        {
            // Push to Acumatica
            //
            string resultJson;

            try
            {
                resultJson = _paymentClient.WritePayment(payment.SerializeToJson());
                _syncOrderRepository.ResetOrderErrorCount(transactionRecord.ShopifyOrderId);
            }
            catch (Exception ex)
            {
                _systemLogger.Error(ex);
                _logService.Log($"Encounter error syncing {transactionRecord.LogDescriptor()}");
                _syncOrderRepository.IncreaseOrderErrorCount(transactionRecord.ShopifyOrderId);
                return;
            }

            var resultPayment  = resultJson.DeserializeFromJson <PaymentWrite>();
            var existingRecord = _syncOrderRepository.RetreivePayment(transactionRecord.MonsterId);

            if (existingRecord == null)
            {
                // Create Monster Sync Record
                //
                var paymentRecord = new AcumaticaPayment();
                paymentRecord.ShopifyTransactionMonsterId = transactionRecord.MonsterId;

                if (resultPayment == null)
                {
                    // Workaround for Acumatica Bug
                    //
                    paymentRecord.AcumaticaRefNbr = AcumaticaSyncConstants.UnknownRefNbr;
                }
                else
                {
                    paymentRecord.AcumaticaRefNbr = resultPayment.ReferenceNbr.value;
                }

                paymentRecord.AcumaticaDocType        = payment.Type.value;
                paymentRecord.AcumaticaAmount         = (decimal)payment.PaymentAmount.value;
                paymentRecord.AcumaticaAppliedToOrder = (decimal)payment.AmountAppliedToOrder;

                if (transactionRecord.IsRefund())
                {
                    if (transactionRecord.NeedManualApply())
                    {
                        // Users are tasked with creating their Return for Credit
                        //
                        paymentRecord.NeedRelease     = false;
                        paymentRecord.NeedManualApply = true;
                    }
                    else
                    {
                        paymentRecord.NeedRelease     = true;
                        paymentRecord.NeedManualApply = false;
                    }
                }

                if (!transactionRecord.IsRefund())
                {
                    paymentRecord.NeedRelease     = true;
                    paymentRecord.NeedManualApply = false;
                }

                paymentRecord.DateCreated = DateTime.UtcNow;
                paymentRecord.LastUpdated = DateTime.UtcNow;
                _syncOrderRepository.InsertPayment(paymentRecord);
            }
            else
            {
                existingRecord.AcumaticaAppliedToOrder = (decimal)payment.AmountAppliedToOrder;
                existingRecord.LastUpdated             = DateTime.UtcNow;
                _syncOrderRepository.SaveChanges();
            }

            _syncOrderRepository.UpdateShopifyOriginalPaymentNeedPut(transactionRecord.ShopifyOrderMonsterId, false);
            _syncOrderRepository.ResetOrderErrorCount(transactionRecord.ShopifyOrderId);
        }