예제 #1
0
        public async Task <ASquare_Payment> GetPaymentAsync(long squarePaymentId)
        {
            using var log = BeginFunction(nameof(SquareAdminService), nameof(GetPaymentAsync), squarePaymentId);
            try
            {
                await Assert(SecurityPolicy.IsPrivileged).ConfigureAwait(false);

                var mPayment = await SquareMicroService.GetSquarePaymentAsync(squarePaymentId);

                var result = await GetPaymentDetails(mPayment);

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }
예제 #2
0
        public async Task <UCart_Cart> GetCartAsync(string userId)
        {
            using var log = BeginFunction(nameof(CartUserService), nameof(GetCartAsync), userId);
            try
            {
                // HACK: Review logic
                //AssertIsEndUser(userId);
                //await Assert(SecurityPolicy.IsAuthorized, userId).ConfigureAwait(false);

                var ordererReference = CreateOrdererReference.FromUserId(userId);
                var ordererId        = await OrderMicroService.AllocateOrdererAsync(ordererReference);

                var mOrder = await OrderMicroService.GetCartOrderAsync(ordererId).ConfigureAwait(false);

                if (mOrder == null)
                {
                    return(null);
                }

                var mProjectOrder = OrderUserService.Create.UOrder_Order(mOrder, null);

                var squareCustomerReference = CreateSquareCustomerReference.FromUserId(userId);
                var squareCustomerId        = await SquareMicroService.AllocateSquareCustomerAsync(squareCustomerReference);

                var squarePaymentReference = CreateSquarePaymentReference.FromOrderId(mOrder.OrderId);
                var squarePaymentId        = await SquareMicroService.AllocateSquarePaymentAsync(squarePaymentReference, squareCustomerId);

                var mSquarePayment = await SquareMicroService.GetSquarePaymentAsync(squarePaymentId);

                var mWebPaymentRequest = mSquarePayment.WebPaymentRequests.Where(r =>
                                                                                 r.WebRequestTypeCode == SquarePaymentWebRequestTypeCodes.Payment &&
                                                                                 r.ProcessingStatusCode != SquareProcessingStatusCodes.Cancelled).SingleOrDefault();

                Cart_PaymentStatus paymentStatus;
                if (mWebPaymentRequest == null)
                {
                    paymentStatus = Cart_PaymentStatus.Required;
                }
                else
                {
                    switch (mWebPaymentRequest.ProcessingStatusCode)
                    {
                    case SquareProcessingStatusCodes.Rejected:
                        paymentStatus = Cart_PaymentStatus.Required;
                        break;

                    case SquareProcessingStatusCodes.Processed:
                        paymentStatus = Cart_PaymentStatus.Complete;
                        break;

                    case SquareProcessingStatusCodes.Pending:
                    case SquareProcessingStatusCodes.Processing:
                    case SquareProcessingStatusCodes.Transmitting:
                    case SquareProcessingStatusCodes.Transmitted:
                    case SquareProcessingStatusCodes.Exception:
                        paymentStatus = Cart_PaymentStatus.InProgress;
                        break;

                    default:
                        // Includes SquarePaymentWebRequestStatusTypes.Cancelled - should have been filtered out above.
                        //
                        throw new InvalidOperationException($"Unknown payment transaction status type {mWebPaymentRequest.ProcessingStatusCode}.");
                    }
                }

                var result = new UCart_Cart()
                {
                    Order         = mProjectOrder,
                    PaymentStatus = paymentStatus
                };

                log.Result(result);

                return(result);
            }
            catch (Exception ex)
            {
                log.Exception(ex);
                throw;
            }
        }