Exemplo n.º 1
0
        /// <summary>
        /// Get Card Token
        /// </summary>
        /// <param name="formData">Form data</param>
        /// <param name="aqToken">Aq token</param>
        /// <returns>Card Token</returns>
        private async Task <string> GetCardToken(YachtPaymentInfo formData, string aqToken)
        {
            var request = new RequestGetTokenCardStripe()
            {
                name       = formData.name,
                cardNumber = formData.cardNumber,
                exp_Month  = formData.exp_Month,
                exp_Year   = formData.exp_Year,
                cvc        = formData.cvc,
                address1   = string.Empty,
                address2   = string.Empty,
                province   = string.Empty,
                country    = string.Empty,
                zipCode    = string.Empty
            };

            var response = await _yachtPaymentService
                           .GetTokenFromApiPayment <RequestGetTokenCardStripe, ResponseGetTokenResultStripe>(request, aqToken);

            return(response.IsValidResponse() ? response.ResponseData.Data : string.Empty);
        }
Exemplo n.º 2
0
        public async Task <JsonResult> ProcessYachtPayment([FromBody] YachtPaymentInfo formData)
        {
            var    charteringUniqueId   = string.Empty;
            var    paymentProvider      = "STRIPE";
            double totalBillAmount      = 0;
            var    currencyCode         = string.Empty;
            var    aqToken              = string.Empty;
            var    transactionId        = string.Empty;
            var    paymentToken         = string.Empty;
            var    stripePaymentRequest = new RequestPaymentStripe();
            var    createdUser          = string.Empty;

            // Validate Form Data
            var isSuccess = (formData != null) && ModelState.IsValid;

            // Calculate total price and save chartering info
            if (isSuccess)
            {
                charteringUniqueId = await SaveCharterInformation(formData.data, paymentProvider);

                isSuccess = (string.IsNullOrEmpty(charteringUniqueId) == false);
            }

            // Get total price and culture code
            if (isSuccess)
            {
                var yachtCharteringViewModel = await GetCharterInformation(charteringUniqueId);

                totalBillAmount = yachtCharteringViewModel.PrepaidValue;
                currencyCode    = yachtCharteringViewModel.CurrencyCode;
            }

            // Get aq token
            if (isSuccess)
            {
                aqToken = await GetAqToken();

                isSuccess = (string.IsNullOrEmpty(aqToken) == false);
            }

            // Create transaction
            if (isSuccess)
            {
                transactionId = await CreateTransaction(stripePaymentRequest, charteringUniqueId, totalBillAmount, currencyCode, aqToken);

                isSuccess = (string.IsNullOrEmpty(transactionId) == false);
            }

            // Get card token from api
            if (isSuccess)
            {
                paymentToken = await GetCardToken(formData, aqToken);

                isSuccess = (string.IsNullOrEmpty(paymentToken) == false);
            }

            // Process payment api
            if (isSuccess)
            {
                var request = new RequestProccessPaymentStripe()
                {
                    ID               = stripePaymentRequest.ID,
                    OrderId          = charteringUniqueId,
                    OrderAmount      = (decimal)totalBillAmount,
                    PaymentMethod    = "Full",
                    Currency         = currencyCode,
                    Description      = "",
                    BackUrl          = "/Yacht",
                    PaymentCardToken = paymentToken
                };
                isSuccess = await ProcessStripePayment(request, aqToken, "STRIPE");
            }

            #region Get current transaction and update status, log
            // Get current transaction
            if (isSuccess)
            {
                var response = await _yachtPaymentService.GetTransaction <ResponseTransactionResultStripe>(transactionId, aqToken);

                isSuccess   = response.IsValidResponse();
                createdUser = response.ResponseData.Data.CreatedUser;
            }

            // Update transaction status
            if (isSuccess)
            {
                var response = await _yachtCharteringService.UpdateCharterStatus(charteringUniqueId, Convert.ToInt32(YachtCharterStatusEnum.Paid));

                isSuccess = response.IsValidResponse();
            }

            // Update payment log
            if (isSuccess)
            {
                // Get current payment log
                var response =
                    await _yachtCharteringService.GetCharteringPaymentLogByCharteringUniqueId(charteringUniqueId, Convert.ToInt32(YachtCharterStatusEnum.Waiting));

                isSuccess = response.IsValidResponse();

                if (isSuccess)
                {
                    var paymentLog = response.ResponseData;
                    paymentLog.PaymentBy  = createdUser;
                    paymentLog.PaymentRef = transactionId;
                    paymentLog.StatusFid  = Convert.ToInt32(YachtCharterStatusEnum.Paid);

                    // Update payment log
                    var resultUpdate =
                        await _yachtCharteringService.UpdateCharterPrivatePaymentLogByCharteringUniqueId(paymentLog, charteringUniqueId);

                    isSuccess = resultUpdate.IsValidResponse();
                }
            }
            #endregion

            return(Json(new { Success = isSuccess }));
        }