Example #1
0
 /// <summary>
 /// Captures the specified request.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns></returns>
 public async Task <CaptureResponseModel> Capture(CaptureRequestModel request)
 {
     try
     {
         return(new CaptureResponseModel());
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #2
0
 /// <summary>
 /// Routes the capture.
 /// </summary>
 /// <param name="captureRequestModel">The capture request model.</param>
 /// <returns></returns>
 public async Task <CaptureResponseModel> RouteCapture(CaptureRequestModel captureRequestModel)
 {
     try
     {
         return(await _paymentProcessor(captureRequestModel.Engine).Capture(captureRequestModel));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Error - {ex.Message}  occurred while routing Capture for Engine-{((PaymentEngine)captureRequestModel.Engine).ToString()}");
         throw ex;
     }
 }
 /// <summary>
 /// Converts to capture request model.
 /// </summary>
 /// <param name="captureRequestModel">The capture request model.</param>
 /// <returns></returns>
 public PayfortCaptureInfoRequestModel ConvertToCaptureRequestModel(CaptureRequestModel captureRequestModel)
 {
     try
     {
         return(new PayfortCaptureInfoRequestModel()
         {
             RequestPhrase = PayfortConfigurationModel.RequestPhrase,
             AccessCode = PayfortConfigurationModel.AccessCode,
             Amount = captureRequestModel.Amount.ToString(),
             Command = PaymentCommandType.CAPTURE.ToString(),
             Currency = captureRequestModel.Currency,
             FortId = captureRequestModel.GatewayIdentifier,
             Language = "en",
             MerchantIdentifier = PayfortConfigurationModel.MerchantIdentifier,
             Url = PayfortConfigurationModel.URL
         });
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        /// <summary>
        /// Captures the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        public async Task <CaptureResponseModel> Capture(CaptureRequestModel request)
        {
            try
            {
                var payfortRequest = _payfortRequestParser.ConvertToCaptureRequestModel(request);

                var stopwatch = new Stopwatch();

                stopwatch.Start();

                var gatewayResponse = _payfortService.Capture(payfortRequest);

                //Add profiler

                return(_payfortResponseParser.MapCaptureResponse(gatewayResponse));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception occured in authorize process in payfort ");
                throw ex;
            }
        }
Example #5
0
        public async Task <CaptureResponseModel> Capture(CaptureRequestModel request)
        {
            var securityUrl     = request.Settings["SecurityUrl"];
            var userName        = request.Settings["UserName"];
            var password        = request.Settings["Password"];
            var confirmationUrl = request.Settings["ConfirmationUrl"];
            var merchantId      = request.Settings["MerchantId"];

            var token = await this._visaNetSecurityTokenService.GetToken(securityUrl, userName, password);

            var requestMessage = new
            {
                channel     = "web",
                captureType = "manual",
                order       = new
                {
                    purchaseNumber   = request.OrderNumber,
                    amount           = request.Amount,
                    authorizedAmount = request.AuthorizedAmount,
                    currency         = request.CurrencyIsoCode,
                    transactionId    = request.TransactionId
                }
            };

            var headers = new Dictionary <string, string>();

            headers.Add("authorization", token);

            using (var proxy = new HttpClient())
            {
                var httpRequest = new HttpRequestMessage(HttpMethod.Post, $"{confirmationUrl}/confirmation/ecommerce/{merchantId}");

                foreach (var h in headers)
                {
                    httpRequest.Headers.TryAddWithoutValidation(h.Key, h.Value);
                }

                var json = Newtonsoft.Json.JsonConvert.SerializeObject(requestMessage);

                httpRequest.Content = new StringContent(json, Encoding.UTF8, "application/json");

                var response = await proxy.SendAsync(httpRequest);

                if (response.IsSuccessStatusCode)
                {
                    var data = Newtonsoft.Json.JsonConvert.DeserializeObject <AuthorizeResultModel>(await response.Content.ReadAsStringAsync());

                    var result = new CaptureResponseModel
                    {
                        Success = true
                    };

                    return(result);
                }

                var errorData = Newtonsoft.Json.JsonConvert.DeserializeObject <CaptureFailedResultModel>(await response.Content.ReadAsStringAsync());

                return(new CaptureResponseModel
                {
                    Success = false,
                    Errors = new List <TransactionErrorResponseModel> {
                        new TransactionErrorResponseModel {
                            Code = errorData.ErrorCode, Message = $"Code: ({errorData.Data.ACTION_CODE}) {errorData.Data.ACTION_DESCRIPTION}. {errorData.ErrorMessage}"
                        }
                    }
                });
            }
        }