예제 #1
0
 /// <inheritdoc />
 public override Task <IPaymentRefundResult> RefundAsync(InvoiceContext context, Money amount, CancellationToken cancellationToken = default)
 {
     return(PaymentRefundResult.Failed("The Refund operation is not supported by this gateway.").ToInterfaceAsync());
 }
예제 #2
0
        public static async Task <IPaymentRefundResult> CreateRefundResult(InvoiceContext context, HttpResponseMessage responseMessage, MessagesOptions messagesOptions)
        {
            if (!responseMessage.IsSuccessStatusCode)
            {
                return(PaymentRefundResult.Failed($"Operation failed. Http Status: {responseMessage.StatusCode}"));
            }

            var response = await responseMessage.Content.ReadAsStringAsync().ConfigureAwaitFalse();

            var result = JsonConvert.DeserializeObject <VerificationRollbackResponseModel>(response);

            if (result == null)
            {
                return(PaymentRefundResult.Failed(messagesOptions.InvalidDataReceivedFromGateway));
            }

            if (result.Status.IsNullOrWhiteSpace())
            {
                return(PaymentRefundResult.Failed(messagesOptions.InvalidDataReceivedFromGateway));
            }

            PaymentRefundResultStatus status;
            string message;

            switch (result.Status.ToLower())
            {
            case "ok":
                if (!long.TryParse(result.ReturnId, out var amount))
                {
                    message = $"{messagesOptions.InvalidDataReceivedFromGateway} Cannot parse the amount. Amount: {result.ReturnId}";
                    status  = PaymentRefundResultStatus.Failed;
                }
                else if (amount != (long)context.Payment.Amount)
                {
                    status  = PaymentRefundResultStatus.Failed;
                    message = $"{messagesOptions.PaymentFailed} The amount that received from the gateway and the actual invoice amount are not equal. Invoice amount: {(long)context.Payment.Amount}. Received amount: {result.ReturnId}";
                }
                else
                {
                    status  = PaymentRefundResultStatus.Succeed;
                    message = messagesOptions.PaymentSucceed;
                }

                break;

            case "nok":
                status  = PaymentRefundResultStatus.Failed;
                message = SepehrGatewayResultTranslator.Translate(result.ReturnId, messagesOptions);
                if (message.IsNullOrEmpty())
                {
                    message = messagesOptions.PaymentFailed;
                }
                break;

            case "duplicate":
                status  = PaymentRefundResultStatus.AlreadyRefunded;
                message = !result.Message.IsNullOrWhiteSpace() ? result.Message : "The invoice has been already refunded before.";
                break;

            default:
                status  = PaymentRefundResultStatus.Failed;
                message = $"{messagesOptions.InvalidDataReceivedFromGateway} Operation failed. Status value is not valid.";
                break;
            }

            return(new PaymentRefundResult
            {
                Status = status,
                Message = message
            });
        }
예제 #3
0
 /// <inheritdoc />
 public override Task <IPaymentRefundResult> RefundAsync(InvoiceContext context, Money amount, CancellationToken cancellationToken = default)
 {
     return(PaymentRefundResult.Failed(Resources.RefundNotSupports).ToInterfaceAsync());
 }
예제 #4
0
 /// <inheritdoc />
 public override Task <IPaymentRefundResult> RefundAsync(VerifyContext context, Money amount, CancellationToken cancellationToken = default)
 {
     return(PaymentRefundResult.Succeed().ToInterfaceAsync());
 }
예제 #5
0
 public virtual Task <IPaymentRefundResult> RefundAsync(Payment payment, Money amount, CancellationToken cancellationToken = default)
 {
     return(PaymentRefundResult.Failed(Resources.RefundNotSupports).ToInterfaceAsync());
 }