Пример #1
0
        static string BuildMessage(PaymentErrorResponse errors)
        {
            PaymentResponse payment = errors?.PaymentResult?.Payment;

            if (payment != null)
            {
                return("declined payment '" + payment.Id + "' with status '" + payment.Status + "'");
            }
            return("the payment platform returned a declined payment response");
        }
Пример #2
0
        static string BuildMessage(PaymentErrorResponse errors, string responseBody)
        {
            Payment payment = errors?.PaymentResult?.Payment;

            if (payment != null)
            {
                return("declined payment '" + payment.Id + "' with status '" + payment.Status + "'");
            }
            return("the Ingenico ePayments platform returned a declined refund response");
        }
Пример #3
0
        public TerminalResponseDTO Pay(BankRequestDTO model)
        {
            TerminalResponseDTO terminalResponse = new TerminalResponseDTO()
            {
                Success = false,
                Message = "unhandled exception occurred"
            };

            try
            {
                long?id = CreateRequest(model);
                if (id.HasValue)
                {
                    PaymentRequestVm request = new PaymentRequestVm()
                    {
                        amount       = model.amount,
                        callback_url = model.callBackUrl,
                        description  = model.additionalData,
                        email        = "",
                        mobile       = "",
                        merchant_id  = model.TerminalID
                    };

                    var jsonBody        = JsonConvert.SerializeObject(request);
                    var content         = new StringContent(jsonBody, Encoding.UTF8, "application/json");
                    var response        = _client.PostAsync(Configuration.GetGatewayInfo("Request_Url"), content).Result;
                    var responseContent = response.Content.ReadAsStringAsync().Result;


                    try
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            PaymentResponseVm res = JsonConvert.DeserializeObject <PaymentResponseVm>
                                                        (responseContent);
                            if (res.data.code == 100)
                            {
                                if (AddPaymentAuthority(res, id.Value))
                                {
                                    terminalResponse.Message   = res.data.message;
                                    terminalResponse.Url       = Configuration.GetGatewayInfo("StartPayment_Url") + res.data.authority;
                                    terminalResponse.Reference = res.data.authority;
                                    terminalResponse.StatusID  = res.data.code;
                                    terminalResponse.Success   = true;
                                }
                            }
                        }
                    }
                    catch
                    {
                        PaymentErrorResponse err = JsonConvert.DeserializeObject <PaymentErrorResponse>
                                                       (responseContent);

                        terminalResponse.Success  = false;
                        terminalResponse.Message  = err.errors.message;
                        terminalResponse.Url      = response.RequestMessage.RequestUri.AbsoluteUri;
                        terminalResponse.StatusID = err.errors.code;
                    }

                    return(terminalResponse);
                }
                return(terminalResponse);
            }
            catch
            {
                return(terminalResponse);
            }
        }
Пример #4
0
 public DeclinedPaymentException(System.Net.HttpStatusCode statusCode, string responseBody, PaymentErrorResponse errorResponse)
     : base(BuildMessage(errorResponse), statusCode, responseBody, errorResponse?.ErrorId, errorResponse?.Errors)
 {
     _errorResponse = errorResponse;
 }
Пример #5
0
        protected Exception CreateException(System.Net.HttpStatusCode statusCode, string responseBody, object errorObject, CallContext context)
        {
            if (errorObject is PaymentErrorResponse && ((PaymentErrorResponse)errorObject).PaymentResult != null)
            {
                return(new DeclinedPaymentException(statusCode, responseBody, (PaymentErrorResponse)errorObject));
            }
            if (errorObject is PayoutErrorResponse && ((PayoutErrorResponse)errorObject).PayoutResult != null)
            {
                return(new DeclinedPayoutException(statusCode, responseBody, (PayoutErrorResponse)errorObject));
            }
            if (errorObject is RefundErrorResponse && ((RefundErrorResponse)errorObject).RefundResult != null)
            {
                return(new DeclinedRefundException(statusCode, responseBody, (RefundErrorResponse)errorObject));
            }

            string           errorId;
            IList <APIError> errors;

            if (errorObject is PaymentErrorResponse)
            {
                PaymentErrorResponse paymentErrorResponse = (PaymentErrorResponse)errorObject;
                errorId = paymentErrorResponse.ErrorId;
                errors  = paymentErrorResponse.Errors;
            }
            else if (errorObject is PayoutErrorResponse)
            {
                PayoutErrorResponse payoutErrorResponse = (PayoutErrorResponse)errorObject;
                errorId = payoutErrorResponse.ErrorId;
                errors  = payoutErrorResponse.Errors;
            }
            else if (errorObject is RefundErrorResponse)
            {
                RefundErrorResponse refundErrorResponse = (RefundErrorResponse)errorObject;
                errorId = refundErrorResponse.ErrorId;
                errors  = refundErrorResponse.Errors;
            }
            else if (errorObject is ErrorResponse)
            {
                ErrorResponse errorResponse = (ErrorResponse)errorObject;
                errorId = errorResponse.ErrorId;
                errors  = errorResponse.Errors;
            }
            else
            {
                throw new ArgumentException("unsupported error object type: " + errorObject.GetType().ToString());
            }

            switch (statusCode)
            {
            case HttpStatusCode.BadRequest:
                return(new ValidationException(statusCode, responseBody, errorId, errors));

            case HttpStatusCode.Forbidden:
                return(new AuthorizationException(statusCode, responseBody, errorId, errors));

            case HttpStatusCode.NotFound:
                return(new ReferenceException(statusCode, responseBody, errorId, errors));

            case HttpStatusCode.Conflict:
                if (IsIdempotenceError(errors, context))
                {
                    string idempotenceKey = context.IdempotenceKey;
                    long?  idempotenceRequestTimestamp = context.IdempotenceRequestTimestamp;
                    return(new IdempotenceException(idempotenceKey, idempotenceRequestTimestamp, statusCode, responseBody, errorId, errors));
                }
                return(new ReferenceException(statusCode, responseBody, errorId, errors));

            case HttpStatusCode.Gone:
                return(new ReferenceException(statusCode, responseBody, errorId, errors));

            case HttpStatusCode.InternalServerError:
                return(new GlobalCollectException(statusCode, responseBody, errorId, errors));

            case HttpStatusCode.BadGateway:
                return(new GlobalCollectException(statusCode, responseBody, errorId, errors));

            case HttpStatusCode.ServiceUnavailable:
                return(new GlobalCollectException(statusCode, responseBody, errorId, errors));

            default:
                return(new ApiException(statusCode, responseBody, errorId, errors));
            }
        }