示例#1
0
        public VoidResponse VoidTransaction(string authorizationId)
        {
            VoidResponse response;

            if (_repo.TryGetAuthorization(authorizationId, out var authorization))
            {
                if (authorization.IsVoid)
                {
                    response = new VoidResponse(authorization.Currency, authorization.AmountCaptured)
                    {
                        IsError = true, Message = $"{authorization.CardNumber}: Unable to void transaction as it is already void"
                    };
                }
                else
                {
                    _repo.VoidTransaction(authorizationId);
                    response = new VoidResponse(authorization.Currency, authorization.AmountCaptured)
                    {
                        Message = $"{authorization.CardNumber}: Transaction voided successfully"
                    };
                }
            }
            else
            {
                response = new VoidResponse(string.Empty, -1)
                {
                    IsError = true, Message = $"Invalid authorization Id - {authorizationId}"
                };
            }

            return(response);
        }
示例#2
0
        public CaptureResponse Capture(CaptureRequest captureRequest)
        {
            CaptureResponse respose;

            if (_repo.TryGetAuthorization(captureRequest.AuthorizationId, out var authorization))
            {
                if (IsCaptureAllowed(authorization))
                {
                    if (authorization.AmountCaptured + captureRequest.Amount <= authorization.AmountAuthorized)
                    {
                        _repo.UpdateCapture(captureRequest.AuthorizationId, captureRequest.Amount);
                        respose = new CaptureResponse(authorization.Currency, captureRequest.Amount)
                        {
                            Message = $"{authorization.CardNumber} - Successfully captured {authorization.Currency} {captureRequest.Amount}"
                        };
                    }
                    else
                    {
                        respose = new CaptureResponse(authorization.Currency, captureRequest.Amount)
                        {
                            IsError = true, Message = $"{authorization.CardNumber} - Failed to capture {authorization.Currency} {captureRequest.Amount} as it exceeds authorized amount"
                        };
                    }
                }
                else
                {
                    respose = new CaptureResponse(authorization.Currency, captureRequest.Amount)
                    {
                        IsError = true, Message = $"{authorization.CardNumber} - Capture not allowed on a void/refunded transaction"
                    };
                }

                return(respose);
            }
            else
            {
                respose = new CaptureResponse(string.Empty, captureRequest.Amount)
                {
                    IsError = true, Message = $"Capture failed. Invalid authorization Id: {captureRequest.AuthorizationId}"
                };
                return(respose);
            }
        }
示例#3
0
        public RefundResponse Refund(RefundRequest refundRequest)
        {
            RefundResponse response;

            if (_repo.TryGetAuthorization(refundRequest.AuthorizationId, out var authorization))
            {
                if (authorization.IsVoid)
                {
                    response = new RefundResponse(authorization.Currency, authorization.AmountAuthorized)
                    {
                        IsError = true, Message = $"{authorization.CardNumber} - Refund failed as transaction is void"
                    };
                    return(response);
                }

                if (refundRequest.Amount <= authorization.AmountAuthorized)
                {
                    _repo.UpdateRefund(refundRequest.AuthorizationId, refundRequest.Amount);
                    response = new RefundResponse(authorization.Currency, refundRequest.Amount)
                    {
                        Message = $"{authorization.CardNumber} - Successfully processed refund for {authorization.Currency} {refundRequest.Amount}"
                    };
                }
                else
                {
                    response = new RefundResponse(authorization.Currency, refundRequest.Amount)
                    {
                        IsError = true, Message = $"{authorization.CardNumber} - Failed to process refund as amount is higher than captured amount"
                    };
                }

                return(response);
            }
            else
            {
                response = new RefundResponse(string.Empty, refundRequest.Amount)
                {
                    IsError = true, Message = $"Refund failed. Invalid authorization Id: {refundRequest.AuthorizationId}"
                };
                return(response);
            }
        }