public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			var config = GetConfigMap();

			var service = new AdaptivePaymentsService(config);

			var response = service.PaymentDetails(new PaymentDetailsRequest
			{
				payKey = context.OuterId,
				requestEnvelope = new RequestEnvelope { errorLanguage = "en_US" }
			});

			if (response.status == "COMPLETED")
			{
				retVal.IsSuccess = true;
				retVal.NewPaymentStatus = PaymentStatus.Paid;
			}
			else if (response.status == "INCOMPLETE" && response.status == "ERROR" && response.status == "REVERSALERROR")
			{
				if (response.error != null && response.error.Count > 0)
				{
					var sb = new StringBuilder();
					foreach (var error in response.error)
					{
						sb.AppendLine(error.message);
					}
					retVal.Error = sb.ToString();
				}
				else
				{
					retVal.Error = "payment canceled";
				}

				retVal.NewPaymentStatus = PaymentStatus.Voided;
			}
			else
			{
				retVal.NewPaymentStatus = PaymentStatus.Pending;
			}

			return retVal;
		}
		public IHttpActionResult PostProcessPayment(string orderId)
		{
			var order = _customerOrderService.GetById(orderId, CustomerOrderResponseGroup.Full);
			if (order == null)
			{
				throw new NullReferenceException("order");
			}

			var store = _storeService.GetById(order.StoreId);
			var paymentMethod = store.PaymentMethods.Where(x => x.IsActive).FirstOrDefault(x => x.ValidatePostProcessRequest(HttpContext.Current.Request.QueryString).IsSuccess);
			if (paymentMethod != null)
			{
				var paymentOuterId = paymentMethod.ValidatePostProcessRequest(HttpContext.Current.Request.QueryString).OuterId;

				var payment = order.InPayments.FirstOrDefault(x => x.OuterId == paymentOuterId);
				if (payment == null)
				{
					throw new NullReferenceException("payment");
				}

				if (payment == null)
				{
					throw new NullReferenceException("appropriate paymentMethod not found");
				}

				var context = new PostProcessPaymentEvaluationContext
				{
					Order = order,
					Payment = payment,
					Store = store,
					OuterId = paymentOuterId
				};

				PostProcessPaymentResult retVal;
				if (!payment.IsApproved)
				{
					retVal = paymentMethod.PostProcessPayment(context);

					if (retVal != null && retVal.NewPaymentStatus == PaymentStatus.Paid)
					{
						payment.IsApproved = true;
						_customerOrderService.Update(new CustomerOrder[] { order });
					}
				}
				else
				{
					retVal = new PostProcessPaymentResult
					{
						IsSuccess = true,
						NewPaymentStatus = PaymentStatus.Paid,
						OrderId = orderId
					};
				}

				return Ok(retVal);
			}

			return Ok(new PostProcessPaymentResult { Error = "cancel payment" });
		}
		public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			if (context == null && context.Payment == null)
				throw new ArgumentNullException("paymentEvaluationContext");

			if (context.Order == null)
				throw new NullReferenceException("no order with this id");

			retVal.OrderId = context.Order.Id;

			if (!(context.Store != null && !string.IsNullOrEmpty(context.Store.Url)))
				throw new NullReferenceException("no store with this id");

			var config = GetConfigMap(context.Store);

			var service = new PayPalAPIInterfaceServiceService(config);

		    var getExpressCheckoutDetailsRequest = GetGetExpressCheckoutDetailsRequest(context.OuterId);
			try
			{
				var response = service.GetExpressCheckoutDetails(getExpressCheckoutDetailsRequest);

				CheckResponse(response);

				var status = response.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus;

				if (!status.Equals("PaymentActionCompleted"))
				{
					var doExpressCheckoutPaymentRequest = GetDoExpressCheckoutPaymentRequest(response, context.OuterId);
					var doResponse = service.DoExpressCheckoutPayment(doExpressCheckoutPaymentRequest);

					CheckResponse(doResponse);

					response = service.GetExpressCheckoutDetails(getExpressCheckoutDetailsRequest);
					status = response.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus;
				}
				if (status.Equals("PaymentActionCompleted"))
				{
					retVal.IsSuccess = true;
					retVal.NewPaymentStatus = PaymentStatus.Paid;
				}
			}
			catch (System.Exception ex)
			{
				retVal.Error = ex.Message;
				retVal.NewPaymentStatus = PaymentStatus.Pending;
			}

			return retVal;
		}
        public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
        {
            var retVal = new PostProcessPaymentResult();

            var transactionId = context.Parameters["x_split_tender_id"] ?? context.Parameters["x_trans_id"];
            var invoiceNumber = context.Parameters["x_invoice_num"];
            var authorizationCode = context.Parameters["x_auth_code"];
            var totalPrice = context.Parameters["x_amount"];
            var responseCode = context.Parameters["x_response_code"];
            var responseReasonCode = context.Parameters["x_response_reason_code"];
            var responseReasonText = context.Parameters["x_response_reason_text"];
            var method = context.Parameters["x_method"];
            var hash = context.Parameters["x_MD5_Hash"];

            var hashMD5 = GetMD5Hash(MD5Hash + ApiLogin + transactionId + totalPrice);

            if (!string.IsNullOrEmpty(hash) && !string.IsNullOrEmpty(hashMD5) && string.Equals(hashMD5, hash, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(responseCode) && responseCode.Equals("1"))
            {
                if (PaymentActionType == "Sale")
                {
                    retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
                    context.Payment.CapturedDate = DateTime.UtcNow;
                    context.Payment.IsApproved = true;
                }
                else if (PaymentActionType == "Authorization/Capture")
                {
                    retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Authorized;
                    context.Payment.OuterId = transactionId;
                }

                retVal.OuterId = context.Payment.OuterId = transactionId;
                context.Payment.AuthorizedDate = DateTime.UtcNow;
                retVal.IsSuccess = true;
                retVal.ReturnUrl = string.Format("{0}/{1}?id={2}", context.Store.Url, ThankYouPageRelativeUrl, context.Order.Id);
            }

            return retVal;
        }
        public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
        {
            var transactionId = context.Parameters["transact"];

            var retVal = new PostProcessPaymentResult();
            retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
            context.Payment.CapturedDate = DateTime.UtcNow;
            context.Payment.IsApproved = true;
            retVal.OuterId = context.Payment.OuterId = transactionId;
            context.Payment.AuthorizedDate = DateTime.UtcNow;
            retVal.OrderId = context.Order.Number;
            retVal.IsSuccess = ValidatePostProcessRequest(context.Parameters).IsSuccess;

            return retVal;
        }
Esempio n. 6
0
		public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			return retVal;
		}
		public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
		{
			if (context.Order == null)
				throw new ArgumentNullException("context.Order is null");
			if (context.Payment == null)
				throw new ArgumentNullException("context.Payment is null");
			if (context.Store == null)
				throw new ArgumentNullException("context.Store is null");
			if (string.IsNullOrEmpty(context.Store.Url))
				throw new NullReferenceException("url of store not set");

			var retVal = new PostProcessPaymentResult();

			retVal.OrderId = context.Order.Id;

			var config = GetConfigMap();

			var service = new PayPalAPIInterfaceServiceService(config);

		    var getExpressCheckoutDetailsRequest = GetGetExpressCheckoutDetailsRequest(context.OuterId);
			try
			{
				var response = service.GetExpressCheckoutDetails(getExpressCheckoutDetailsRequest);

				CheckResponse(response);

				var status = response.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus;

				if (!status.Equals("PaymentActionCompleted"))
				{
					var doExpressCheckoutPaymentRequest = GetDoExpressCheckoutPaymentRequest(response, context.OuterId);
					var doResponse = service.DoExpressCheckoutPayment(doExpressCheckoutPaymentRequest);

					CheckResponse(doResponse);

					response = service.GetExpressCheckoutDetails(getExpressCheckoutDetailsRequest);
					status = response.GetExpressCheckoutDetailsResponseDetails.CheckoutStatus;
				}
				if (status.Equals("PaymentActionCompleted"))
				{
					retVal.IsSuccess = true;
					retVal.OuterId = response.GetExpressCheckoutDetailsResponseDetails.PaymentDetails[0].TransactionId;
					if(PaypalPaymentActionType == PaymentActionCodeType.AUTHORIZATION)
					{
						retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Authorized;
						context.Payment.OuterId = retVal.OuterId;
						context.Payment.AuthorizedDate = DateTime.UtcNow;
					}
					else if (PaypalPaymentActionType == PaymentActionCodeType.SALE)
					{
						retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
						context.Payment.OuterId = retVal.OuterId;
						context.Payment.IsApproved = true;
						context.Payment.CapturedDate = DateTime.UtcNow;
					}
				}
				else
				{
					retVal.ErrorMessage = "Payment process not successfully ends";
				}
			}
			catch (System.Exception ex)
			{
				retVal.ErrorMessage = ex.Message;
			}

			return retVal;
		}
		private PostProcessPaymentResult PostProcessKlarnaOrder(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			Uri resourceUri = new Uri(string.Format("{0}/{1}", _euroTestBaseUrl, context.OuterId));

			var connector = Connector.Create(AppSecret);

			Order order = new Order(connector, resourceUri)
			{
				ContentType = _contentType
			};

			order.Fetch();
			var status = order.GetValue("status") as string;

			if (status == "checkout_complete")
			{
				var data = new Dictionary<string, object> { { "status", "created" } };
				order.Update(data);
				order.Fetch();
				status = order.GetValue("status") as string;
			}

			if (status == "created" && IsSale())
			{
				var result = CaptureProcessPayment(new CaptureProcessPaymentEvaluationContext { Payment = context.Payment });

				retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
				context.Payment.OuterId = retVal.OuterId;
				context.Payment.IsApproved = true;
				context.Payment.CapturedDate = DateTime.UtcNow;
				retVal.IsSuccess = true;
			}
			else if (status == "created")
			{
				retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Authorized;
				context.Payment.OuterId = retVal.OuterId = context.OuterId;
				context.Payment.AuthorizedDate = DateTime.UtcNow;
				retVal.IsSuccess = true;
			}
			else
			{
				retVal.ErrorMessage = "order not created";
			}

			retVal.OrderId = context.Order.Id;

			return retVal;
		}
		public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			var localization = GetLocalization(context.Order.Currency.ToString(), null);

			retVal = PostProcessKlarnaOrder(context);

			return retVal;
		}
Esempio n. 10
0
		private PostProcessPaymentResult NewRegisterKlarnaOrder(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			var connector = ConnectorFactory.Create(
				AppKey,
				AppSecret,
				Client.TestBaseUrl);

			Client client = new Client(connector);
			var order = client.NewOrder(context.OuterId);
			OrderData orderData = order.Fetch();

			if (orderData.Status != "CAPTURED")
			{
				var capture = client.NewCapture(order.Location);

				CaptureData captureData = new CaptureData()
				{
					CapturedAmount = orderData.OrderAmount,
					Description = "All order items is shipped",
					OrderLines = orderData.OrderLines
				};

				capture.Create(captureData);
				orderData = order.Fetch();
			}

			retVal.IsSuccess = orderData.Status == "CAPTURED";
			retVal.NewPaymentStatus = retVal.IsSuccess ? PaymentStatus.Paid : PaymentStatus.Pending;
			retVal.OrderId = context.Order.Id;

			return retVal;
		}
Esempio n. 11
0
		private PostProcessPaymentResult OldRegisterKlarnaOrder(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			Uri resourceUri = new Uri(string.Format("{0}/{1}", _euroTestBaseUrl, context.OuterId));

			var connector = Connector.Create(AppSecret);

			Order order = new Order(connector, resourceUri)
			{
				ContentType = _contentType
			};

			order.Fetch();
			var status = order.GetValue("status") as string;

			if (status == "checkout_complete")
			{
				var data = new Dictionary<string, object> { { "status", "created" } };
				order.Update(data);
				order.Fetch();
				status = order.GetValue("status") as string;
			}

			if (status == "created")
			{
				var reservation = order.GetValue("reservation") as string;

				if (!string.IsNullOrEmpty(reservation))
				{
					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 response = api.Activate(reservation);

					order.Fetch();

					var klarnaCart = order.GetValue("cart") as JObject;
				}
			}

			retVal.IsSuccess = status == "created";
			retVal.NewPaymentStatus = retVal.IsSuccess ? PaymentStatus.Paid : PaymentStatus.Pending;
			retVal.OrderId = context.Order.Id;

			return retVal;
		}
Esempio n. 12
0
		public override PostProcessPaymentResult PostProcessPayment(PostProcessPaymentEvaluationContext context)
		{
			var retVal = new PostProcessPaymentResult();

			var localization = GetLocalization(context.Order.Currency.ToString(), null);

			if (localization.CountryName == "US" || localization.CountryName == "GB")
			{
				retVal = NewRegisterKlarnaOrder(context);
			}
			else
			{
				retVal = OldRegisterKlarnaOrder(context);
			}

			return retVal;
		}