public override RefundProcessPaymentResult RefundProcessPayment(RefundProcessPaymentEvaluationContext context)
        {
            if (context == null || context.Payment == null)
            {
                throw new ArgumentNullException("paymentEvaluationContext");
            }

            RefundProcessPaymentResult retVal = new RefundProcessPaymentResult();

            if (context.Payment.IsApproved && (context.Payment.PaymentStatus == PaymentStatus.Paid || context.Payment.PaymentStatus == PaymentStatus.Cancelled))
            {
                try
                {
                    var config  = GetConfigMap();
                    var service = new PayPalAPIInterfaceServiceService(config);
                    RefundTransactionReq refundTransctionRequest = GetRefundTransactionRequest(context.Payment);
                    service.RefundTransaction(refundTransctionRequest);
                }
                catch (Exception ex)
                {
                    retVal.ErrorMessage = ex.Message;
                }
            }

            return(new RefundProcessPaymentResult {
                ErrorMessage = "Not implemented yet"
            });
        }
예제 #2
0
        public override RefundProcessPaymentResult RefundProcessPayment(RefundProcessPaymentEvaluationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.Payment == null)
            {
                throw new ArgumentNullException("context.Payment");
            }

            var retVal = new RefundProcessPaymentResult();

            if (context.Payment.IsApproved && (context.Payment.PaymentStatus == PaymentStatus.Paid || context.Payment.PaymentStatus == PaymentStatus.Cancelled))
            {
                if (KlarnaApi == null)
                {
                    InitializeKlarnaApi();
                }

                var result = KlarnaApi.CreditInvoice(context.Payment.OuterId);

                if (!string.IsNullOrEmpty(result))
                {
                    retVal.NewPaymentStatus       = context.Payment.PaymentStatus = PaymentStatus.Refunded;
                    context.Payment.CancelledDate = DateTime.UtcNow;
                    context.Payment.IsCancelled   = true;
                    retVal.IsSuccess = true;
                }
            }

            return(retVal);
        }
        public override RefundProcessPaymentResult RefundProcessPayment(RefundProcessPaymentEvaluationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.Payment == null)
            {
                throw new ArgumentNullException("context.Payment");
            }

            var retVal = new RefundProcessPaymentResult();

            if (context.Payment.IsApproved && (context.Payment.PaymentStatus == PaymentStatus.Paid || context.Payment.PaymentStatus == PaymentStatus.Cancelled))
            {
                Configuration configuration = new Configuration(Country.Code.SE, Language.Code.SV, Currency.Code.SEK, Encoding.Sweden)
                {
                    Eid        = Convert.ToInt32(AppKey),
                    Secret     = AppSecret,
                    IsLiveMode = false
                };
                Api.Api api = new Api.Api(configuration);

                var result = api.CreditInvoice(context.Payment.OuterId);
            }

            return(retVal);
        }
        public void TestRefund()
        {
            var context = new RefundProcessPaymentEvaluationContext
            {
                Order = new CustomerOrder
                {
                    Number   = "",
                    Currency = "USD"
                },
                Payment = new PaymentIn
                {
                    OuterId      = "",
                    Sum          = 0M,
                    Transactions = new List <PaymentGatewayTransaction>()
                },
                Parameters = new NameValueCollection
                {
                    { "RefundAmount", (-5.33M).ToString(CultureInfo.InvariantCulture) }
                }
            };

            var endpoint = "https://api.sandbox.datatrans.com";
            var username = "";
            var password = "";
            var hmacKey  = "";

            var datatransClient = CreateDatatransClient(endpoint, username, password);

            var datatransClientFactory = CreateDatatransClientFactory(datatransClient);

            var datatransCheckoutService       = CreateDatatransCheckoutService();
            var datatransCapturePaymentService = CreateDatatransCapturePaymentService();

            var datatransCheckoutPaymentMethod = CreateDatatransCheckoutPaymentMethod(
                datatransCheckoutService.Object,
                datatransClientFactory,
                datatransCapturePaymentService.Object,
                CreateSignProvider(hmacKey));

            datatransCheckoutPaymentMethod.Settings = new List <SettingEntry>
            {
                new SettingEntry
                {
                    Name  = "Datatrans.Checkout.MerchantId",
                    Value = ""
                }
            };

            var result = datatransCheckoutPaymentMethod.RefundProcessPayment(context);
        }
예제 #5
0
 public override RefundProcessPaymentResult RefundProcessPayment(RefundProcessPaymentEvaluationContext context)
 {
     throw new NotImplementedException();
 }
예제 #6
0
 public abstract RefundProcessPaymentResult RefundProcessPayment(RefundProcessPaymentEvaluationContext context);
 private int GetNormalizedAmountForRefund(RefundProcessPaymentEvaluationContext context, PaymentIn payment)
 {
     return(GetAmountForRefund(context, payment).NormalizeDecimal().ToInt());
 }
 private decimal GetAmountForRefund(RefundProcessPaymentEvaluationContext context, PaymentIn payment)
 {
     return(IsPartialRefund(context.Parameters)
         ? GetPartialRefundAmount(context.Parameters)
         : payment.Sum);
 }
        public override RefundProcessPaymentResult RefundProcessPayment(RefundProcessPaymentEvaluationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.Payment == null)
            {
                throw new InvalidOperationException(nameof(context.Payment));
            }

            if (context.Order == null)
            {
                throw new InvalidOperationException(nameof(context.Order));
            }

            if (string.IsNullOrEmpty(context.Payment.OuterId))
            {
                throw new InvalidOperationException(nameof(context.Payment.OuterId));
            }

            if (string.IsNullOrEmpty(context.Order.Currency))
            {
                throw new InvalidOperationException(nameof(context.Order.Currency));
            }

            if (string.IsNullOrEmpty(context.Order.Number))
            {
                throw new InvalidOperationException(nameof(context.Payment.OuterId));
            }

            var result = new RefundProcessPaymentResult();

            var payment = context.Payment;

            var request = new DatatransRefundRequest
            {
                TransactionId   = payment.OuterId,
                Amount          = GetNormalizedAmountForRefund(context, payment),
                Currency        = context.Order.Currency,
                MerchantId      = MerchantId,
                ReferenceNumber = context.Order.Number,
                Sign            = GetSignProvider(HMACHex).Sign(MerchantId, GetNormalizedAmountForRefund(context, payment), context.Order.Currency, context.Order.Number)
            };

            var datatransClient = CreateDatatransClient(ServerToServerApi);

            var response = datatransClient.Refund(request);

            var transaction = new PaymentGatewayTransaction();

            payment.Transactions.Add(transaction);

            transaction.ResponseData = response.ResponseData;

            if (!response.ErrorMessage.IsNullOrEmpty())
            {
                transaction.ProcessError = response.ErrorMessage;

                result.ErrorMessage = GetErrorMessage(response.ErrorCode, response.ErrorMessage);
                result.IsSuccess    = false;
                return(result);
            }

            transaction.Amount        = GetAmountForRefund(context, payment);
            transaction.CurrencyCode  = payment.Currency;
            transaction.IsProcessed   = true;
            transaction.Note          = "Datatrans refund";
            transaction.ResponseCode  = response.ResponseCode;
            transaction.Status        = response.ResponseMessage;
            transaction.ProcessedDate = DateTime.Now;

            result.NewPaymentStatus = IsPartialRefund(context.Parameters) ? PaymentStatus.PartiallyRefunded : PaymentStatus.Refunded;
            result.IsSuccess        = true;

            return(result);
        }