/// <summary>
        /// Get Error id
        /// </summary>
        /// <param name="responseStatus"></param>
        /// <returns>int</returns>
        public static int GetErrorId(int responseCode, PaymentCommandType CommandType)
        {
            switch (responseCode)
            {
            case (int)PayfortResponseMessageEnum.TechnicalProblem:
                return((int)CheckOutBookingError.TechnicalProblem);

            case (int)PayfortResponseMessageEnum.AuthenticationFailed:
                return((int)CheckOutBookingError.AuthenticationFailed);

            case (int)PayfortResponseMessageEnum.InsufficientFunds:
                return((int)CheckOutBookingError.InsufficientFunds);

            case (int)PayfortResponseMessageEnum.TokenNameDoesNotExist:
                return((int)CheckOutBookingError.TokenNameDoesNotExist);

            case (int)PayfortResponseMessageEnum.TransactionDeclined:
                return((int)CheckOutBookingError.TransactionDeclined);

            default:
                if (CommandType == PaymentCommandType.AUTHORIZATION)
                {
                    return((int)CheckOutBookingError.AuthorizationFailed);
                }
                else
                {
                    return((int)CheckOutBookingError.CaptureFailed);
                }
            }
        }
        /// <summary>
        /// Payfort Error Info
        /// </summary>
        /// <param name="errInfo"></param>
        /// <returns>PayfortErrorInfo</returns>
        public static PaymentResponse GetPayfortExceptionResponseInfo(PaymentResponse errInfo, PaymentCommandType CommandType)
        {
            if (CommandType == PaymentCommandType.AUTHORIZATION)
            {
                errInfo.ErrorId = (int)CheckOutBookingError.AuthorizationException;
            }
            else if (CommandType == PaymentCommandType.VOID_AUTHORIZATION)
            {
                errInfo.ErrorId = (int)CheckOutBookingError.AuthorizationException;
            }
            else
            {
                errInfo.ErrorId = (int)CheckOutBookingError.CaptureException;
            }
            errInfo.ErrorTypeId          = (int)ErrorType.Payment;
            errInfo.ErrorTypeDescription = GetEnumDescription((CheckOutBookingError)errInfo.ErrorId);

            return(errInfo);
        }
Exemplo n.º 3
0
        private async Task <Result <CreditCardPaymentResult> > MakePayment(CreditCardPaymentRequest request, PaymentCommandType commandType)
        {
            try
            {
                var requestContent = GetSignedContent();
                var client         = _clientFactory.CreateClient(HttpClientNames.Payfort);
                using var response = await client.PostAsync(_options.PaymentUrl, requestContent);

                return(await GetContent(response)
                       .Bind(GetJObject)
                       .Bind(_payfortResponseParser.ParsePaymentResponse));
            }
            catch (Exception ex)
            {
                _logger.LogPayfortClientException(ex);
                return(Result.Failure <CreditCardPaymentResult>("Payment error"));
            }


            HttpContent GetSignedContent()
            {
                var paymentRequest = new PayfortPaymentRequest(
                    signature: string.Empty,
                    accessCode: _options.AccessCode,
                    merchantIdentifier: _options.Identifier,
                    merchantReference: request.MerchantReference,
                    amount: ToPayfortAmount(request.Amount, request.Currency),
                    currency: request.Currency.ToString(),
                    customerName: request.CustomerName,
                    customerEmail: request.CustomerEmail,
                    customerIp: request.CustomerIp,
                    language: request.LanguageCode,
                    returnUrl: _options.ReturnUrl,
                    settlementReference: request.ReferenceCode,
                    tokenName: request.Token.Code,
                    rememberMe: ToPayfortBoolean(request.Token.Type == PaymentTokenTypes.Stored),
                    cardSecurityCode: GetSecurityCode(),
                    command: GetCommand()
                    );

                var jObject = JObject.FromObject(paymentRequest, PayfortSerializationSettings.Serializer);

                var(_, _, signature, _) = _signatureService.Calculate(jObject, SignatureTypes.Request);
                paymentRequest          = new PayfortPaymentRequest(paymentRequest, signature);
                var json = JsonConvert.SerializeObject(paymentRequest, PayfortSerializationSettings.SerializerSettings);

                return(new StringContent(json, Encoding.UTF8, "application/json"));


                // Is not needed for new card.
                string GetSecurityCode() => request.IsNewCard ? null : request.SecurityCode;

                string GetCommand() => commandType == PaymentCommandType.Purchase ? "PURCHASE" : "AUTHORIZATION";
            }
        }