public async Task HandleShipmentEventAsync(MFulfillment_ShipmentEvent eventData)
        {
            using var log = BeginFunction(nameof(FulfillmentEventMicroService), nameof(HandleShipmentEventAsync), eventData);
            try
            {
                using var ctx = CreateQuiltContext();

                switch (eventData.EventType)
                {
                case MFulfillment_ShipmentEventTypes.Process:
                {
                    var fulfillableIds = new HashSet <long>();
                    foreach (var shipmentRequestId in eventData.ShipmentRequestIds)
                    {
                        var mShipmentRequest = await FullfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId).ConfigureAwait(false);

                        foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems)
                        {
                            var mFulfillable = await FullfillmentMicroService.GetFulfillableByItemAsync(mShipmentRequestItem.FulfillableItemId).ConfigureAwait(false);

                            var fulfillableId = mFulfillable.FulfillableId;
                            if (fulfillableIds.Contains(fulfillableId))
                            {
                                _ = fulfillableIds.Add(fulfillableId);

                                if (TryParseOrderId.FromFulfillableReference(mFulfillable.FulfillableReference, out var orderId))
                                {
                                    var mOrder = await OrderMicroService.GetOrderAsync(orderId).ConfigureAwait(false);

                                    var userId = ParseUserId.FromOrdererReference(mOrder.OrdererReference);

                                    var participantReference = CreateParticipantReference.FromUserId(userId);
                                    var participantId        = await CommunicationMicroService.AllocateParticipantAsync(participantReference).ConfigureAwait(false);

                                    var topicReference = CreateTopicReference.FromOrderId(orderId);
                                    var topicId        = await CommunicationMicroService.AllocateTopicAsync(topicReference, null).ConfigureAwait(false);

                                    await CommunicationMicroService.SendNotification(participantId, NotificationTypeCodes.OrderShipped, topicId).ConfigureAwait(false);
                                }
                            }
                        }
                    }
                }
                break;
                }

                await Task.CompletedTask.ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
예제 #2
0
        private async Task HandlePaymentEventAsync(MSquare_Event eventData)
        {
            var funderReference = CreateFunderReference.FromSquarePaymentId(eventData.SquarePaymentId);
            var funderId        = await FundingMicroService.AllocateFunderAsync(funderReference).ConfigureAwait(false);

            if (TryParseOrderId.FromSquarePaymentReference(eventData.SquarePaymentReference, out var orderId))
            {
                var fundableReference = CreateFundableReference.FromOrderId(orderId);

                await FundingMicroService.SetFundsReceivedAsync(funderId, fundableReference, eventData.PaymentAmount, eventData.UnitOfWork).ConfigureAwait(false);

                await FundingMicroService.SetProcessingFeeAsync(funderId, fundableReference, eventData.ProcessingFeeAmount, eventData.UnitOfWork).ConfigureAwait(false);

                await FundingMicroService.SetFundsRefundedAsync(funderId, fundableReference, eventData.RefundAmount, eventData.UnitOfWork).ConfigureAwait(false);
            }
        }
예제 #3
0
        public async Task HandleFundableEventAsync(MFunding_FundableEvent eventData)
        {
            using var log = BeginFunction(nameof(FundingEventMicroService), nameof(HandleFundableEventAsync), eventData);
            try
            {
                using var ctx = CreateQuiltContext();

                if (eventData.FundsReceived != 0)
                {
                    if (TryParseOrderId.FromFundableReference(eventData.FundableReference, out var orderId))
                    {
                        _ = await OrderMicroService.SetFundsReceivedAsync(orderId, eventData.FundsReceived, eventData.UnitOfWork).ConfigureAwait(false);
                    }
                }
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }