Пример #1
0
        static string BuildMessage(RefundErrorResponse errorResponse)
        {
            RefundResponse refund = errorResponse?.RefundResult;

            if (refund != null)
            {
                return("declined refund '" + refund.Id + "' with status '" + refund.Status + "'");
            }
            return("the payment platform returned a declined refund response");
        }
        static string BuildMessage(RefundErrorResponse errors)
        {
            RefundResult refund = errors != null ? errors.RefundResult : null;

            if (refund != null)
            {
                return("declined refund '" + refund.Id + "' with status '" + refund.Status + "'");
            }
            return("the Ingenico ePayments platform returned a declined refund response");
        }
Пример #3
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));
            }
        }
Пример #4
0
 public DeclinedRefundException(System.Net.HttpStatusCode statusCode, string responseBody, RefundErrorResponse errorResponse)
     : base(BuildMessage(errorResponse), statusCode, responseBody, errorResponse?.ErrorId, errorResponse?.Errors)
 {
     this._errorResponse = errorResponse;
 }
        public static EntityMock<RefundErrorResponse> CreateRefundErrorResponse()
        {
            var errorResponse = new RefundErrorResponse()
            {
                TransactionType = TransactionTypes.Refund,
                Status = "error",
                ResponseCode = "57",
                UniqueId = "2515db3cf16d04fa35afb140b84b99d4",
                TransactionId = "119643941047503772d9caa",
                Code = ErrorCodes.ReferenceNotFoundError,
                TechnicalMessage = "no approved reference transaction found",
                Message = "no approved reference transaction found",
                Mode = "live",
                ProxyTime = "2007-11-30T16:16:53Z",
                Descriptor = "some desc 1",
                Amount = 90,
                Currency = Iso4217CurrencyCodes.USD,
            };

            var errorResponseXml =
                                  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                  "<payment_response>" +
                                  "<transaction_type>refund</transaction_type>" +
                                  "<status>error</status>" +
                                  "<response_code>57</response_code>" +
                                  "<unique_id>2515db3cf16d04fa35afb140b84b99d4</unique_id>" +
                                  "<transaction_id>119643941047503772d9caa</transaction_id>" +
                                  "<code>410</code>" +
                                  "<technical_message>no approved reference transaction found</technical_message>" +
                                  "<message>no approved reference transaction found</message>" +
                                  "<mode>live</mode>" +
                                  "<timestamp>2007-11-30T16:16:53Z</timestamp>" +
                                  "<descriptor>some desc 1</descriptor>" +
                                  "<amount>9000</amount>" +
                                  "<currency>USD</currency>" +
                                  "</payment_response>";

            return new EntityMock<RefundErrorResponse>(errorResponse, errorResponseXml);
        }