public async Task <ActionResult> Post() { var requestBinary = await ReadRequestBodyAsync(Request.Body); var requestAscii = Encoding.ASCII.GetString(requestBinary); if (string.IsNullOrEmpty(requestAscii)) { requestAscii = "<EMPTY>"; } try { var squarePayloadId = await SquareMicroService.CreateWebhookPayloadAsync(requestAscii).ConfigureAwait(false); await SquareMicroService.ProcessWebhookPayloadAsync(squarePayloadId); _ = await EventProcessorMicroService.ProcessPendingEvents(); } catch (Exception) { // Load exception. } return(StatusCode(StatusCodes.Status200OK)); }
public async Task TransferPrepayment() { Console.WriteLine("TransferPrepayment"); var logger = ServiceScope.ServiceProvider.GetService <ILogger <FundingTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); var incomeAmount = 100m; var salesTaxAmount = 5m; var totalAmount = incomeAmount + salesTaxAmount; var salesTaxJurisdiction = "XX"; // Create references. // var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow()); logger.LogInformation($"Funder reference = {funderReference}"); var fundableReference = CreateFundableReference.FromTimestamp(GetUniqueNow()); logger.LogInformation($"Fundable reference = {fundableReference}"); // Create funder and set funds received. // var funderId = await FundingMicroService.AllocateFunderAsync(funderReference); logger.LogInformation($"Funder ID = {funderId}"); await FundingMicroService.SetFundsReceivedAsync(funderId, fundableReference, totalAmount, unitOfWork.Next()); logger.LogInformation($"Set {totalAmount:c} funds received."); var eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); // Create fundable and set funds required. // var fundableId = await FundingMicroService.AllocateFundableAsync(fundableReference); logger.LogInformation($"Fundable ID = {fundableId}"); await FundingMicroService.SetFundsRequiredAsync(fundableId, incomeAmount, salesTaxAmount, salesTaxJurisdiction, unitOfWork.Next()); logger.LogInformation($"Set {incomeAmount:c} + {salesTaxAmount:c} funds required."); eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); // Ensure funds transferred. // var fundable = await FundingMicroService.GetFundableAsync(fundableId); Assert.IsNotNull(fundable); logger.LogInformation($"Fundable retrieved. Fundable reference = {fundable.FundableReference}"); Assert.AreEqual(fundableReference, fundable.FundableReference); Assert.AreEqual(fundable.FundsRequiredTotal, totalAmount); Assert.AreEqual(fundable.FundsReceived, totalAmount); }
public async Task <long> SubmitCartOrderAsync(string userId) { using var log = BeginFunction(nameof(CartUserService), nameof(SubmitCartOrderAsync), userId); try { //AssertIsEndUser(userId); await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false); var ordererReference = CreateOrdererReference.FromUserId(userId); var ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference).ConfigureAwait(false); var orderId = await OrderMicroService.SubmitCartAsync(ordererId).ConfigureAwait(false); var result = orderId; _ = await EventProcessorMicroService.ProcessPendingEvents().ConfigureAwait(false); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task CreateShipment() { var logger = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); int maxQuantity = 10; var mShipmentRequest = await SetupShipmentRequest(unitOfWork, maxQuantity); var mCreateShipmentItems = new List <MFulfillment_CreateShipmentItem>(); foreach (var mShipmentRequestItem in mShipmentRequest.ShipmentRequestItems) { mCreateShipmentItems.Add(new MFulfillment_CreateShipmentItem() { ShipmentRequestItemId = mShipmentRequestItem.ShipmentRequestItemId, Quantity = mShipmentRequestItem.Quantity }); } var mCreateShipment = new MFulfillment_CreateShipment() { ShipmentDateTimeUtc = DateTime.Today, TrackingCode = "1234567890", ShippingVendorId = "USPS", CreateShipmentItems = mCreateShipmentItems }; var shipmentId = await FulfillmentMicroService.CreateShipmentAsync(mCreateShipment); logger.LogInformation($"Shipment {shipmentId} created."); var eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); await FulfillmentMicroService.PostShipmentAsync(shipmentId); logger.LogInformation($"Shipment {shipmentId} posted."); eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); await FulfillmentMicroService.ProcessShipmentAsync(shipmentId); logger.LogInformation($"Shipment {shipmentId} processed."); eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); }
public async Task CancelShipmentAsync(long shipmentId) { using var log = BeginFunction(nameof(ShipmentAdminService), nameof(CancelShipmentAsync), shipmentId); try { await Assert(SecurityPolicy.AllowEditFulfillment); await FulfillmentMicroService.CancelShipmentAsync(shipmentId); _ = await EventProcessorMicroService.ProcessPendingEvents().ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task CancelReturnAsync(long returnId) { using var log = BeginFunction(nameof(ReturnAdminService), nameof(CancelReturnAsync), returnId); try { await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false); await FulfillmentMicroService.CancelReturnAsync(returnId).ConfigureAwait(false); _ = await EventProcessorMicroService.ProcessPendingEvents().ConfigureAwait(false); } catch (Exception ex) { log.Exception(ex); throw; } }
public async Task CreateReturn() { var logger = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); int maxQuantity = 10; var mReturnRequest = await SetupReturnRequest(unitOfWork, maxQuantity); var mCreateReturn = new MFulfillment_CreateReturn() { CreateDateTimeUtc = DateTime.Now, CreateReturnItems = mReturnRequest.ReturnRequestItems .Select(r => new MFulfillment_CreateReturnItem() { ReturnRequestItemId = r.ReturnRequestItemId, Quantity = r.Quantity }).ToList() }; var returnId = await FulfillmentMicroService.CreateReturnAsync(mCreateReturn); logger.LogInformation($"Return {returnId} created."); var eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); await FulfillmentMicroService.PostReturnAsync(returnId); logger.LogInformation($"Return {returnId} posted."); eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); await FulfillmentMicroService.ProcessReturnAsync(returnId); logger.LogInformation($"Return {returnId} processed."); eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); }
public async Task CreateReturnRequest() { var logger = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); int maxQuantity = 10; var mShipment = await SetupShipment(unitOfWork, maxQuantity); var mCreateReturnRequestItems = new List <MFulfillment_CreateReturnRequestItem>(); foreach (var mShipmentItem in mShipment.ShipmentItems) { mCreateReturnRequestItems.Add(new MFulfillment_CreateReturnRequestItem() { FulfillableItemId = mShipmentItem.FulfillableItemId, Quantity = mShipmentItem.Quantity }); } var mCreateReturnRequest = new MFulfillment_CreateReturnRequest() { ReturnRequestType = MFulfillment_ReturnRequestTypes.Return, ReturnRequestReasonCode = "ITEM-DEFECTIVE", Notes = "Notes", CreateReturnRequestItems = mCreateReturnRequestItems }; var returnRequestId = await FulfillmentMicroService.CreateReturnRequestAsync(mCreateReturnRequest); logger.LogInformation($"Return request {returnRequestId} created."); var eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); await FulfillmentMicroService.PostReturnRequestAsync(returnRequestId); logger.LogInformation($"Return request {returnRequestId} posted."); eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); }
public async Task CreateFulfillable() { var logger = ServiceScope.ServiceProvider.GetService <ILogger <FulfillmentTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); var allocateFulfillableResponse = await FulfillmentMicroService.AllocateFulfillableAsync(RandomFulfillable()); var fulfillableId = allocateFulfillableResponse.FulfillableId; logger.LogInformation($"Fulfillable ID = {fulfillableId}"); foreach (var allowcateFulfillableItemResponse in allocateFulfillableResponse.FulfillableItemResponses) { var fulfillableItemId = allowcateFulfillableItemResponse.FulfillableItemId; logger.LogInformation($"Fulfillable Item ID = {fulfillableItemId}"); } var eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); foreach (var allowcateFulfillableItemResponse in allocateFulfillableResponse.FulfillableItemResponses) { var quantity = Random.Next(9) + 1; var fulfillableItemId = allowcateFulfillableItemResponse.FulfillableItemId; logger.LogInformation($"Fulfillable Item ID = {fulfillableItemId}"); await FulfillmentMicroService.SetFulfillmentRequestQuantity(fulfillableItemId, quantity, unitOfWork.Next()); logger.LogInformation($"Fulfillment item {fulfillableItemId} required quantity updated to {quantity}."); } eventCount = await EventProcessorMicroService.ProcessPendingEvents(); logger.LogInformation($"{eventCount} events processed."); var mShipmentRequestSummaryList = await FulfillmentMicroService.GetShipmentRequestSummariesAsync(MFulfillment_ShipmentRequestStatus.Pending, null); Assert.IsTrue(mShipmentRequestSummaryList.Summaries.Any(r => r.FulfillableId == fulfillableId)); }
public async Task CreateAndShipOrder() { var services = ServiceScope.ServiceProvider; var logger = services.GetService <ILogger <OrderTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); // Get the user ID. // string userId; { var identityUser = await UserManager.FindByNameAsync("*****@*****.**"); userId = identityUser.Id; logger.LogInformation("User ID = {0}", userId); } // Get the orderer ID. // long ordererId; { var ordererReference = CreateOrdererReference.FromTimestamp(GetUniqueNow()); ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference); logger.LogInformation("Orderer ID = {0}", ordererId); } // Get the funder ID. // long funderId; { var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow()); funderId = await FundingMicroService.AllocateFunderAsync(funderReference); logger.LogInformation("Funder ID = {0}", funderId); } // Create the design. // Guid designId; { var designData = Factory.CreateDesign(); designId = await DesignAjaxService.SaveDesignAsync(userId, designData); logger.LogInformation($"Design ID = {designId}"); } // Create the project. // string projectId; { projectId = await ProjectUserService.CreateProjectAsync(userId, ProjectUserService.ProjectType_Kit, "Test Project", designId); logger.LogInformation($"Project ID = {projectId}"); } // Create the orderable ID. // long orderableId; { var projectSnapshotId = await ProjectMicroService.GetCurrentSnapshotIdAsync(Guid.Parse(projectId)); var mProjectSnapshotDetail = await ProjectMicroService.GetProjectSnapshotAsync(projectSnapshotId); var mAllocateOrderable = MicroDataFactory.MOrder_AllocateOrderable(mProjectSnapshotDetail); var mAllocateOrderableResponseData = await OrderMicroService.AllocateOrderableAsync(mAllocateOrderable); orderableId = mAllocateOrderableResponseData.OrderableId; logger.LogInformation($"Orderable ID = {orderableId}"); } var shippingAddress = new MCommon_Address() { Name = "RICH TODD", AddressLine1 = "17340 W 156 TER", City = "OLATHE", StateCode = "KS", PostalCode = "66062", CountryCode = "US" }; // Create the order. // long orderId; { // Add item to cart. // _ = await OrderMicroService.AddCartItemAsync(ordererId, orderableId, 2); // Update shipping address. // _ = await OrderMicroService.UpdateShippingAddressAsync(ordererId, shippingAddress); // Submit order. // orderId = await OrderMicroService.SubmitCartAsync(ordererId); logger.LogInformation($"Order ID = {orderId}"); } _ = await EventProcessorMicroService.ProcessPendingEvents(); // Create fundable for order. // long fundableId; { var fundableReference = CreateFundableReference.FromOrderId(orderId); fundableId = await FundingMicroService.AllocateFundableAsync(fundableReference); logger.LogInformation($"Fundable ID = {fundableId}"); } // Retrieve the fundable detail. // MFunding_Fundable fundableDetail; { fundableDetail = await FundingMicroService.GetFundableAsync(fundableId); logger.LogInformation($"Fundable Detail = {fundableDetail}"); } // Post a receipt for the order. // { var fundsRequiredDelta = fundableDetail.FundsRequiredTotal - fundableDetail.FundsReceived; await FundingMicroService.SetFundsReceivedAsync(funderId, fundableDetail.FundableReference, fundableDetail.FundsRequiredTotal, unitOfWork.Next()); //await fundingService.TransferFundsAsync(funderId, fundableId, fundsRequiredDelta); logger.LogInformation($"{fundsRequiredDelta} funds applied."); } _ = await EventProcessorMicroService.ProcessPendingEvents(); // Lookup fulfillable. // long fulfillableId; { var fulfillableReference = CreateFulfillableReference.FromOrderId(orderId); fulfillableId = (await FulfillmentMicroService.LookupFulfillableAsync(fulfillableReference)).Value; await FulfillmentMicroService.SetFulfillableShippingAddress(fulfillableId, shippingAddress); logger.LogInformation($"Fulfillable ID = {fulfillableId}"); } // Lookup pending shipment request. // long?shipmentRequestId; { shipmentRequestId = await FulfillmentMicroService.GetPendingShipmentRequestAsync(fulfillableId); logger.LogInformation($"Shipment Request ID = {shipmentRequestId}"); } // Open it. // { await FulfillmentMicroService.OpenShipmentRequestAsync(shipmentRequestId.Value); } // Lookup shipment request. // MFulfillment_ShipmentRequest shipmentRequestDetail; { shipmentRequestDetail = await FulfillmentMicroService.GetShipmentRequestAsync(shipmentRequestId.Value); logger.LogInformation($"Shipment Request Detail = {shipmentRequestDetail}"); } // Create shipment. // long shipmentId; { var items = new List <MFulfillment_CreateShipmentItem>(); foreach (var shipmentRequestItemDetail in shipmentRequestDetail.ShipmentRequestItems) { items.Add(new MFulfillment_CreateShipmentItem() { ShipmentRequestItemId = shipmentRequestItemDetail.ShipmentRequestItemId, Quantity = shipmentRequestItemDetail.Quantity }); } var data = new MFulfillment_CreateShipment() { ShippingVendorId = ShippingVendorIds.Usps, ShipmentDateTimeUtc = Locale.GetUtcNow(), TrackingCode = "123123", CreateShipmentItems = items }; shipmentId = await FulfillmentMicroService.CreateShipmentAsync(data); await FulfillmentMicroService.PostShipmentAsync(shipmentId); await FulfillmentMicroService.ProcessShipmentAsync(shipmentId); logger.LogInformation($"Shipment ID = {shipmentId}"); } _ = await EventProcessorMicroService.ProcessPendingEvents(); }
public async Task CreateOrder() { var services = ServiceScope.ServiceProvider; var logger = services.GetService <ILogger <OrderTest> >(); var unitOfWork = CreateUnitOfWork.Timestamp(GetUniqueNow()); // Get the user ID. // string userId; { var identityUser = await UserManager.FindByNameAsync("*****@*****.**"); userId = identityUser.Id; logger.LogInformation("User ID = {0}", userId); } // Get the orderer ID. // long ordererId; { var ordererReference = CreateOrdererReference.FromTimestamp(GetUniqueNow()); ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference); logger.LogInformation("Orderer ID = {0}", ordererId); } // Get the funder ID. // long funderId; { var funderReference = CreateFunderReference.FromTimestamp(GetUniqueNow()); funderId = await FundingMicroService.AllocateFunderAsync(funderReference); logger.LogInformation("Funder ID = {0}", funderId); } // Create the design. // Guid designId; { var designData = Factory.CreateDesign(); designId = await DesignAjaxService.SaveDesignAsync(userId, designData); logger.LogInformation($"Design ID = {designId}"); } for (int idx = 0; idx < 3; ++idx) { // Create the project. // string projectId; { projectId = await ProjectUserService.CreateProjectAsync(userId, ProjectUserService.ProjectType_Kit, "Test Project", designId); logger.LogInformation($"Project ID = {projectId}"); } // Create the orderable ID. // long orderableId; { var projectSnapshotId = await ProjectMicroService.GetCurrentSnapshotIdAsync(Guid.Parse(projectId)); var mProjectSnapshotDetail = await ProjectMicroService.GetProjectSnapshotAsync(projectSnapshotId); var mAllocateOrderable = MicroDataFactory.MOrder_AllocateOrderable(mProjectSnapshotDetail); var mAllocateOrderableResponseData = await OrderMicroService.AllocateOrderableAsync(mAllocateOrderable); orderableId = mAllocateOrderableResponseData.OrderableId; logger.LogInformation($"Orderable ID = {orderableId}"); } // Add orderable to cart // { // Add item to cart. // _ = await OrderMicroService.AddCartItemAsync(ordererId, orderableId, (idx + 1) * 2); } } var shippingAddress = new MCommon_Address() { Name = "RICH TODD", AddressLine1 = "17340 W 156 TER", City = "OLATHE", StateCode = "KS", PostalCode = "66062", CountryCode = "US" }; // Create the order. // long orderId; { // Update shipping address. // _ = await OrderMicroService.UpdateShippingAddressAsync(ordererId, shippingAddress); // Submit order. // orderId = await OrderMicroService.SubmitCartAsync(ordererId); logger.LogInformation($"Order ID = {orderId}"); } _ = await EventProcessorMicroService.ProcessPendingEvents(); // Create fundable for order. // long fundableId; { var fundableReference = CreateFundableReference.FromOrderId(orderId); fundableId = await FundingMicroService.AllocateFundableAsync(fundableReference); logger.LogInformation($"Fundable ID = {fundableId}"); } // Retrieve the fundable detail. // MFunding_Fundable fundableDetail; { fundableDetail = await FundingMicroService.GetFundableAsync(fundableId); logger.LogInformation($"Fundable Detail = {fundableDetail}"); } // Post a receipt for the order. // { var fundsRequiredDelta = fundableDetail.FundsRequiredTotal - fundableDetail.FundsReceived; await FundingMicroService.SetFundsReceivedAsync(funderId, fundableDetail.FundableReference, fundableDetail.FundsRequiredTotal, unitOfWork.Next()); //await fundingService.TransferFundsAsync(funderId, fundableId, fundsRequiredDelta); logger.LogInformation($"{fundsRequiredDelta} funds applied."); } _ = await EventProcessorMicroService.ProcessPendingEvents(); }
public async Task <UCart_CreateSquarePaymentResponse> CreateSquarePaymentAsync(string userId, decimal paymentAmount, string nonce) { using var log = BeginFunction(nameof(CartUserService), nameof(CreateSquarePaymentAsync), userId, paymentAmount, nonce); try { var ordererReference = CreateOrdererReference.FromUserId(userId); var ordererId = await OrderMicroService.AllocateOrdererAsync(ordererReference); var uOrder = await GetCartOrderAsync(userId); if (uOrder == null) { throw new InvalidOperationException("Shopping cart is empty."); } var squareCustomerReference = CreateSquareCustomerReference.FromUserId(userId); var squareCustomerId = await SquareMicroService.AllocateSquareCustomerAsync(squareCustomerReference); var squarePaymentReference = CreateSquarePaymentReference.FromOrderId(uOrder.MOrder.OrderId); var squarePaymentId = await SquareMicroService.AllocateSquarePaymentAsync(squarePaymentReference, squareCustomerId); var squareWebPaymentRequestId = await SquareMicroService.CreateSquareWebPaymentRequestAsync(squarePaymentId, paymentAmount, nonce); var mProcessWebPaymentTransactionResponse = await SquareMicroService.ProcessWebPaymentRequestAsync(squareWebPaymentRequestId); IList <Cart_CreateSquarePaymentResponseErrorData> errors; if (mProcessWebPaymentTransactionResponse.Errors == null) { errors = null; _ = await OrderMicroService.SubmitCartAsync(ordererId); } else { errors = new List <Cart_CreateSquarePaymentResponseErrorData>(); foreach (var mError in mProcessWebPaymentTransactionResponse.Errors) { errors.Add(new Cart_CreateSquarePaymentResponseErrorData() { Category = mError.Category, Code = mError.Code, Detail = mError.Detail, Field = mError.Field }); } } var result = new UCart_CreateSquarePaymentResponse() { Errors = errors }; _ = await EventProcessorMicroService.ProcessPendingEvents().ConfigureAwait(false); log.Result(result); return(result); } catch (Exception ex) { log.Exception(ex); throw; } }