Ejemplo n.º 1
0
    /// <summary>
    /// Return object is object
    ///
    /// </summary>
    /// <param name="orderId"></param>
    /// <param name="payment"></param>
    /// <returns></returns>
    public object CreatePayment(string orderId, BaseComGatePayment payment, params object[] args)
    {
        Payer customer = new Payer();

        string buyerMail = null;

        if (args.Length == 0)
        {
            try
            {
                ThrowExceptions.Custom(Exc.GetStackTrace(), type, Exc.CallingMethod(), "args was empty. Is used " + CmConsts.Email);
            }
            catch (Exception)
            {
            }
            buyerMail = CmConsts.Email;
        }
        else
        {
            buyerMail = args[0].ToString();
        }

        customer.Contact = new Contact()
        {
            Email = buyerMail,
            Name  = buyerMail
        };

        //var payment = CreateBasePayment(orderId);
        payment.PrepareOnly = true;

        // CreatePaymentAsync,CreatePayment - working in Cmd
        // CreatePayment - working in APp, CreatePaymentAsync - not working in APp

        ApiResponse <PaymentResponse> response = comGateAPI.CreatePayment(payment, customer, CmConsts.api);

        if (response.Response == null)
        {
            var m = response.Message;

            if (m.StartsWith(ComgateNotTranslateAble.afulStart))
            {
                var uriManage = ComgateNotTranslateAble.uriManage;
                var ip        = m.Replace(ComgateNotTranslateAble.afulStart, string.Empty);
                ip = ip.Replace(ComgateNotTranslateAble.afulEnd, string.Empty);
                //Clipboard.SetText(ip);
                Process.Start(uriManage);

                Debug.WriteLine("Insert " + ip + " to " + uriManage);
                //Access from unauthorized location [37. 188.150.241]!
            }
        }
        var pc = new CreatePaymentResult {
            pc = response.Response, error = response.Message
        };

        // cant here check for null, coz there is not ErrorCapture (webforms)

        return(pc);
    }
 public static Api.Contracts.Models.CreatePaymentResult ToContract(this CreatePaymentResult result)
 {
     return(new Contracts.Models.CreatePaymentResult
     {
         Method = result.Method,
         TransactionId = result.TransactionId,
         Url = result.Url,
         PaReq = result.PaReq,
         TransactionStatus = result.TransactionStatus
     });
 }
Ejemplo n.º 3
0
 private void HandleDeclinedPayment(CreatePaymentResult createPaymentResult)
 {
     // handle the result here
 }
Ejemplo n.º 4
0
        public CreatePaymentResult CreatePayment(Payment payment)
        {
            var result = new CreatePaymentResult {
                TransactionId = payment.AuthorizationCode
            };

            if (string.IsNullOrEmpty(payment.TransactionType))
            {
                result.Message = "Transaction type is required";
                return(result);
            }

            var orderForm = _orderRepository.Orders.SelectMany(o => o.OrderForms)
                            .ExpandAll().Expand("OrderGroup/OrderAddresses")
                            .First(of => of.OrderFormId == payment.OrderFormId);

            var transactionType = (TransactionType)Enum.Parse(typeof(TransactionType), payment.TransactionType);

            if (transactionType == TransactionType.Credit)
            {
                var totalSales = orderForm.Payments.Where(
                    p => p.Status == PaymentStatus.Completed.ToString() &&
                    p.TransactionType == TransactionType.Sale.ToString()).Sum(p => p.Amount);

                if (payment.Amount > totalSales)
                {
                    result.Message = string.Format("Payment amount exceeds total sales amount {0} {1}", totalSales,
                                                   orderForm.OrderGroup.BillingCurrency);
                    return(result);
                }
            }

            var paymentMethod = _paymentMethodRepository.PaymentMethods
                                .Expand("PaymentGateway")
                                .Expand("PaymentMethodPropertyValues")
                                .ExpandAll()
                                .FirstOrDefault(p => p.PaymentMethodId.Equals(payment.PaymentMethodId));

            if (paymentMethod == null)
            {
                result.Message = String.Format("Specified payment method \"{0}\" has not been defined.", payment.PaymentMethodId);
                return(result);
            }


            if ((((TransactionType)paymentMethod.PaymentGateway.SupportedTransactionTypes) & transactionType) != transactionType)
            {
                result.Message = String.Format("Transaction type {0} is not supported by payment gateway", payment.TransactionType);
                return(result);
            }

            Debug.WriteLine(String.Format("Getting the type \"{0}\".", paymentMethod.PaymentGateway.ClassType));
            var type = Type.GetType(paymentMethod.PaymentGateway.ClassType);

            if (type == null)
            {
                result.Message = String.Format("Specified payment method class \"{0}\" can not be created.", paymentMethod.PaymentGateway.ClassType);
                return(result);
            }

            var provider = (IPaymentGateway)Activator.CreateInstance(type);

            provider.Settings = CreateSettings(paymentMethod);

            payment.Status = PaymentStatus.Pending.ToString();

            var message = "";

            Debug.WriteLine(String.Format("Processing the payment."));

            try
            {
                //Save changes before process

                payment.OrderForm = null;
                orderForm.Payments.Add(payment);
                _orderRepository.UnitOfWork.Commit();

                payment.OrderForm = orderForm;

                result.IsSuccess     = provider.ProcessPayment(payment, ref message);
                result.Message       = message;
                result.TransactionId = payment.AuthorizationCode;

                Debug.WriteLine(String.Format("Payment processed."));
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
                payment.Status = PaymentStatus.Failed.ToString();
                Trace.TraceError(ex.Message);
            }
            finally
            {
                PostProcessPayment(payment);
                _orderRepository.Update(payment);
                _orderRepository.UnitOfWork.Commit();
            }
            return(result);
        }
Ejemplo n.º 5
0
		public CreatePaymentResult CreatePayment(Payment payment)
		{
			var result = new CreatePaymentResult { TransactionId = payment.AuthorizationCode };

			if (string.IsNullOrEmpty(payment.TransactionType))
			{
				result.Message = "Transaction type is required";
				return result;
			}

			var orderForm = _orderRepository.Orders.SelectMany(o => o.OrderForms)
				.ExpandAll().Expand("OrderGroup/OrderAddresses")
				.First(of => of.OrderFormId == payment.OrderFormId);

			var transactionType = (TransactionType)Enum.Parse(typeof(TransactionType), payment.TransactionType);

			if (transactionType == TransactionType.Credit)
			{
				var totalSales = orderForm.Payments.Where(
					p => p.Status == PaymentStatus.Completed.ToString() &&
                         (p.TransactionType == TransactionType.Sale.ToString() 
                         || p.TransactionType == TransactionType.Capture.ToString())).Sum(p => p.Amount);

				if (payment.Amount > totalSales)
				{
					result.Message = string.Format("Payment amount exceeds total sales amount {0} {1}", totalSales,
					                               orderForm.OrderGroup.BillingCurrency);
					return result;
				}
			}

			var paymentMethod = _paymentMethodRepository.PaymentMethods
									.Expand("PaymentGateway")
									.Expand("PaymentMethodPropertyValues")
									.ExpandAll()
									.FirstOrDefault(p => p.PaymentMethodId.Equals(payment.PaymentMethodId));

			if (paymentMethod == null)
			{
				result.Message = String.Format("Specified payment method \"{0}\" has not been defined.", payment.PaymentMethodId);
				return result;
			}


			if ((((TransactionType)paymentMethod.PaymentGateway.SupportedTransactionTypes) & transactionType) != transactionType)
			{
				result.Message = String.Format("Transaction type {0} is not supported by payment gateway", payment.TransactionType);
				return result;
			}

			Debug.WriteLine(String.Format("Getting the type \"{0}\".", paymentMethod.PaymentGateway.ClassType));
			var type = Type.GetType(paymentMethod.PaymentGateway.ClassType);
			if (type == null)
			{
				result.Message = String.Format("Specified payment method class \"{0}\" can not be created.", paymentMethod.PaymentGateway.ClassType);
				return result;
			}

			var provider = (IPaymentGateway)Activator.CreateInstance(type);
			provider.Settings = CreateSettings(paymentMethod);

			payment.Status = PaymentStatus.Pending.ToString();

			var message = "";
            Debug.WriteLine(String.Format("Processing the payment."));

			try
			{
				//Save changes before process
				
				payment.OrderForm = null;
				orderForm.Payments.Add(payment);
				_orderRepository.UnitOfWork.Commit();

				payment.OrderForm = orderForm;

				result.IsSuccess = provider.ProcessPayment(payment, ref message);
				result.Message = message;
				result.TransactionId = payment.AuthorizationCode;

                Debug.WriteLine(String.Format("Payment processed."));
			}
			catch (Exception ex)
			{
				result.Message = ex.Message;
				payment.Status = PaymentStatus.Failed.ToString();
				Trace.TraceError(ex.Message);
			}
			finally
			{
				PostProcessPayment(payment);
				_orderRepository.Update(payment);
				_orderRepository.UnitOfWork.Commit();
			}
			return result;
		}
        public async Task Test()
        {
            CreatePaymentRequest body = new CreatePaymentRequest();

            Order order = new Order();

            AmountOfMoney amountOfMoney = new AmountOfMoney();

            amountOfMoney.CurrencyCode = ("EUR");
            amountOfMoney.Amount       = (100L);
            order.AmountOfMoney        = (amountOfMoney);

            Customer customer = new Customer();

            customer.Locale = ("en");

            Address billingAddress = new Address();

            billingAddress.CountryCode = ("NL");
            customer.BillingAddress    = (billingAddress);

            order.Customer = (customer);
            body.Order     = (order);

            RedirectionData redirectionData = new RedirectionData();

            redirectionData.ReturnUrl = ("http://example.com/");

            RedirectPaymentMethodSpecificInput paymentMethodSpecificInput = new RedirectPaymentMethodSpecificInput();

            paymentMethodSpecificInput.RedirectionData  = redirectionData;
            paymentMethodSpecificInput.PaymentProductId = (809);

            RedirectPaymentProduct809SpecificInput paymentProductSpecificInput = new RedirectPaymentProduct809SpecificInput();

            paymentProductSpecificInput.IssuerId = ("INGBNL2A");
            paymentMethodSpecificInput.PaymentProduct809SpecificInput = (paymentProductSpecificInput);

            body.RedirectPaymentMethodSpecificInput = (paymentMethodSpecificInput);

            string      idempotenceKey = Guid.NewGuid().ToString();
            CallContext context        = new CallContext().WithIdempotenceKey(idempotenceKey);

            using (Client client = GetClient())
            {
                CreatePaymentResult result = await doCreatePayment(client, body, context);

                string paymentId = result.Payment.Id;
                string status    = result.Payment.Status;

                Assert.AreEqual(idempotenceKey, context.IdempotenceKey);
                Assert.Null(context.IdempotenceRequestTimestamp);

                result = await doCreatePayment(client, body, context);

                Assert.AreEqual(paymentId, result.Payment.Id);
                Assert.AreEqual(status, result.Payment.Status);

                Assert.AreEqual(idempotenceKey, context.IdempotenceKey);
                Assert.NotNull(context.IdempotenceRequestTimestamp);
            }
        }