Exemplo n.º 1
0
        public AcumaticaCustomer CreateAcumaticaCustomerRecord(ShopifyCustomer shopifyRecord, Customer acumaticaCustomer)
        {
            using (var transaction = _acumaticaOrderRepository.BeginTransaction())
            {
                var newRecord = new AcumaticaCustomer();

                newRecord.AcumaticaCustomerId       = acumaticaCustomer.CustomerID.value;
                newRecord.AcumaticaMainContactEmail = acumaticaCustomer.MainContact.Email.value;
                newRecord.DateCreated = DateTime.UtcNow;
                newRecord.LastUpdated = DateTime.UtcNow;

                shopifyRecord.AcumaticaCustomer = newRecord;
                shopifyRecord.NeedsCustomerPut  = false;

                _acumaticaOrderRepository.InsertCustomer(newRecord);

                _acumaticaJsonService.Upsert(
                    AcumaticaJsonType.Customer,
                    acumaticaCustomer.CustomerID.value,
                    acumaticaCustomer.SerializeToJson());

                transaction.Commit();
                return(newRecord);
            }
        }
Exemplo n.º 2
0
        // Create new Sales Order
        //
        private SalesOrder BuildNewSalesOrder(ShopifyOrder shopifyOrderRecord, AcumaticaCustomer customer)
        {
            // Get the Shopify Order
            //
            var shopifyOrder = _shopifyJsonService.RetrieveOrder(shopifyOrderRecord.ShopifyOrderId);

            // Header
            //
            var salesOrder = BuildNewSalesOrderHeader(shopifyOrderRecord, shopifyOrder, customer);

            // Detail
            //
            salesOrder.Details = BuildSalesOrderDetail(shopifyOrder);

            // Billing Address & Contact
            //
            salesOrder.BillToContactOverride = true.ToValue();
            salesOrder.BillToContact         = BuildContact(shopifyOrder, shopifyOrder.billing_address);
            salesOrder.BillToAddressOverride = true.ToValue();
            salesOrder.BillToAddress         = BuildAddress(shopifyOrder.billing_address);

            // Shipping Address & Contact
            //
            salesOrder.ShipToContactOverride = true.ToValue();
            salesOrder.ShipToContact         = BuildContact(shopifyOrder, shopifyOrder.shipping_address);
            salesOrder.ShipToAddressOverride = true.ToValue();
            salesOrder.ShipToAddress         = BuildAddress(shopifyOrder.shipping_address);

            if (!shopifyOrder.MaybeShippingRateTitle.IsNullOrEmpty())
            {
                var carrierToShipVia
                    = _settingsRepository.RetrieveRateToShipVia(shopifyOrder.MaybeShippingRateTitle);

                if (carrierToShipVia != null)
                {
                    salesOrder.ShipVia = carrierToShipVia.AcumaticaShipViaId.ToValue();
                }
            }

            // Payment optimization *** FAIL - PENDING ACUMATICA SUPPORT ***
            //
            //var payment = _acumaticaOrderPaymentPut.BuildPaymentForCreate(shopifyOrderRecord.PaymentTransaction());
            //salesOrder.Payments = new List<object> { payment };

            salesOrder.PaymentRef = shopifyOrderRecord.PaymentTransaction().ShopifyTransactionId.ToString().ToValue();

            return(salesOrder);
        }
Exemplo n.º 3
0
 public void InsertCustomer(AcumaticaCustomer customer)
 {
     Entities.AcumaticaCustomers.Add(customer);
     Entities.SaveChanges();
 }
Exemplo n.º 4
0
        private SalesOrder BuildNewSalesOrderHeader(
            ShopifyOrder shopifyOrderRecord, Order shopifyOrder, AcumaticaCustomer customer)
        {
            var transactionRecord = shopifyOrderRecord.PaymentTransaction();
            var payment           = _shopifyJsonService.RetrieveTransaction(transactionRecord.ShopifyTransactionId);

            var settings = _settingsRepository.RetrieveSettings();
            var gateway  = _settingsRepository.RetrievePaymentGatewayByShopifyId(payment.gateway);

            var salesOrder = new SalesOrder();

            salesOrder.Details = new List <SalesOrderDetail>();

            salesOrder.OrderType = SalesOrderType.SO.ToValue();

            var createdAtUtc  = shopifyOrder.created_at.UtcDateTime;
            var acumaticaDate = _acumaticaTimeZoneService.ToAcumaticaTimeZone(createdAtUtc);

            salesOrder.Date = acumaticaDate.Date.ToValue();

            salesOrder.CustomerOrder = $"{shopifyOrder.id}".ToValue();
            salesOrder.ExternalRef   = $"{shopifyOrder.id}".ToValue();
            salesOrder.Status        = SalesOrderStatus.Open.ToValue();
            salesOrder.Hold          = false.ToValue();
            salesOrder.Description   = $"Shopify Order #{shopifyOrder.order_number}".ToValue();
            salesOrder.CustomerID    = customer.AcumaticaCustomerId.ToValue();

            salesOrder.PaymentMethod = gateway.AcumaticaPaymentMethod.ToValue();
            salesOrder.CashAccount   = gateway.AcumaticaCashAccount.ToValue();

            // Shipping Settings
            //
            salesOrder.ShippingSettings = new ShippingSettings
            {
                ShipSeparately = true.ToValue(),
                ShippingRule   = ShippingRules.BackOrderAllowed.ToValue(),
            };


            // Freight Price and Taxes
            //
            salesOrder.FreightPrice = ((double)shopifyOrder.NetShippingPrice).ToValue();

            salesOrder.OverrideFreightPrice = true.ToValue();
            salesOrder.FreightTaxCategory   = shopifyOrder.IsShippingTaxable
                ? settings.AcumaticaTaxableCategory.ToValue()
                : settings.AcumaticaTaxExemptCategory.ToValue();

            // Taxes
            //
            salesOrder.FinancialSettings = new FinancialSettings()
            {
                OverrideTaxZone = true.ToValue(),
                CustomerTaxZone = settings.AcumaticaTaxZone.ToValue(),
                Branch          = _acumaticaHttpContext.AcumaticaBranch.ToValue()
            };

            var taxTransfer = shopifyOrder.ToSerializedAndZippedTaxTransfer();

            salesOrder.custom = new SalesOrderUsrTaxSnapshot(taxTransfer);

            return(salesOrder);
        }