public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context)
		{
			context.Payment.IsApproved = true;
			context.Payment.PaymentStatus = PaymentStatus.Paid;
			context.Payment.VoidedDate = DateTime.UtcNow;
			return new CaptureProcessPaymentResult { IsSuccess = true, NewPaymentStatus = PaymentStatus.Paid };
		}
        public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context)
        {
            var retVal = new CaptureProcessPaymentResult();

            var request = PrepareCaptureProcessPaymentRequest(context);

            var reply = NVPClient.RunTransaction(request);
            if (reply != null && reply.ContainsKey("decision") && reply.ContainsKey("reasonCode"))
            {
                var decision = (string)reply["decision"];
                var reasonCode = int.Parse((string)reply["reasonCode"]);
                var isAccept = decision.Equals("ACCEPT", StringComparison.InvariantCultureIgnoreCase);
                var isSuccessReasonCode = reasonCode == 100;
                if (isAccept && isSuccessReasonCode)
                {
                    context.Payment.OuterId = (string)reply["requestID"];
                    retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
                    context.Payment.CapturedDate = DateTime.UtcNow;
                    context.Payment.IsApproved = true;
                    retVal.IsSuccess = true;
                }
                else
                {
                    if (reasonCode == 101)
                        throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}, full info of reason is {2}", decision, reasonCode, EnumerateValues(reply, "missingField")));
                    if (reasonCode == 102)
                        throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}, full info of reason is {2}", decision, reasonCode, EnumerateValues(reply, "invalidField")));
                    if (reasonCode == 204)
                        throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}, full info of reason is not enough funds", decision, reasonCode));

                    throw new NullReferenceException(string.Format("result from cyber source, not success, decision is {0}, reasonCode is {1}", decision, reasonCode));
                }
            }
            else
            {
                throw new NullReferenceException("no reply from cyber source");
            }

            return retVal;
        }
        public void CapturePayment()
        {
            var service = GetCustomerOrderService();
            var order = service.GetById("ec2b8124-f061-4997-baa1-ca55c1149a58", CustomerOrderResponseGroup.Full);
            var method = GetMethod();

            var context = new CaptureProcessPaymentEvaluationContext
            {
                Payment = order.InPayments.First()
            };

            var result = method.CaptureProcessPayment(context);

            service = GetCustomerOrderService();
            service.Update(new CustomerOrder[] { order });

            service = GetCustomerOrderService();
            order = service.GetById("ec2b8124-f061-4997-baa1-ca55c1149a58", CustomerOrderResponseGroup.Full);

            Assert.AreEqual(PaymentStatus.Paid, order.InPayments.First().PaymentStatus);
            Assert.IsTrue(order.InPayments.First().IsApproved);
            Assert.IsNotNull(order.InPayments.First().CapturedDate);
        }
        public void CapturePayment()
        {
            var service = GetCustomerOrderService();
            var order = service.GetById("9ae2ccce-008d-42bd-952b-9dbd9ac88e6a", CustomerOrderResponseGroup.Full);
            var method = GetMethod();

            var context = new CaptureProcessPaymentEvaluationContext
            {
                Payment = order.InPayments.First()
            };

            var result = method.CaptureProcessPayment(context);

            service = GetCustomerOrderService();
            service.Update(new CustomerOrder[] { order });

            service = GetCustomerOrderService();
            order = service.GetById("9ae2ccce-008d-42bd-952b-9dbd9ac88e6a", CustomerOrderResponseGroup.Full);

            Assert.AreEqual(PaymentStatus.Paid, order.InPayments.First().PaymentStatus);
            Assert.IsTrue(order.InPayments.First().IsApproved);
            Assert.IsNotNull(order.InPayments.First().CapturedDate);
        }
		public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context)
		{
			throw new NotImplementedException();
		}
 /// <summary>
 /// Capture authorized payment
 /// </summary>
 /// <param name="context"></param>
 /// <returns>Result of capturing payment in external system</returns>
 public abstract CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context);
        public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context)
        {
            var retVal = new CaptureProcessPaymentResult();

            var webClient = new WebClient();
            var form = new NameValueCollection();
            form.Add("x_login", ApiLogin);
            form.Add("x_tran_key", TxnKey);

            form.Add("x_delim_data", "TRUE");
            form.Add("x_delim_char", "|");
            form.Add("x_encap_char", "");
            form.Add("x_version", GetApiVersion());
            form.Add("x_method", "CC");
            form.Add("x_currency_code", context.Payment.Currency.ToString());
            form.Add("x_type", "CAPTURE_ONLY");

            var orderTotal = Math.Round(context.Payment.Sum, 2);
            form.Add("x_amount", orderTotal.ToString("0.00", CultureInfo.InvariantCulture));

            //x_trans_id. When x_test_request (sandbox) is set to a positive response, 
            //or when Test mode is enabled on the payment gateway, this value will be "0".
            form.Add("x_trans_id", context.Payment.OuterId);

            var responseData = webClient.UploadValues(GetAuthorizeNetUrl(), form);
            var reply = Encoding.ASCII.GetString(responseData);

            if (!string.IsNullOrEmpty(reply))
            {
                string[] responseFields = reply.Split('|');
                switch (responseFields[0])
                {
                    case "1":
                        retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
                        retVal.OuterId = context.Payment.OuterId = string.Format("{0},{1}", responseFields[6], responseFields[4]);
                        retVal.IsSuccess = true;
                        context.Payment.IsApproved = true;
                        break;
                    case "2":
                        throw new NullReferenceException(string.Format("Declined ({0}: {1})", responseFields[2], responseFields[3]));
                    case "3":
                        throw new NullReferenceException(string.Format("Error: {0}", reply));
                }
            }
            else
            {
                throw new NullReferenceException("Authorize.NET unknown error");
            }

            return retVal;
        }
		public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context)
		{
			if (context == null || context.Payment == null)
				throw new ArgumentNullException("paymentEvaluationContext");

			CaptureProcessPaymentResult retVal = new CaptureProcessPaymentResult();

			if (!context.Payment.IsApproved && (context.Payment.PaymentStatus == PaymentStatus.Authorized || context.Payment.PaymentStatus == PaymentStatus.Cancelled))
			{
				try
				{
					var config = GetConfigMap();
					var service = new PayPalAPIInterfaceServiceService(config);
					DoCaptureReq doCaptureRequest = GetDoCaptureRequest(context.Payment);

					var doCaptureResponse = service.DoCapture(doCaptureRequest);

					CheckResponse(doCaptureResponse);

					if(doCaptureResponse.DoCaptureResponseDetails.PaymentInfo.PaymentStatus == PaymentStatusCodeType.COMPLETED)
					{
						retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
						context.Payment.CapturedDate = DateTime.UtcNow;
						context.Payment.IsApproved = true;
						retVal.IsSuccess = true;
					}
				}
				catch(Exception ex)
				{
					retVal.ErrorMessage = ex.Message;
				}
			}

			return retVal;
		}
		public override CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			if (context.Payment == null)
				throw new ArgumentNullException("context.Payment");

			var retVal = new CaptureProcessPaymentResult();

			Uri resourceUri = new Uri(string.Format("{0}/{1}", _euroTestBaseUrl, context.Payment.OuterId));
			var connector = Connector.Create(AppSecret);
			Order order = new Order(connector, resourceUri)
			{
				ContentType = _contentType
			};
			order.Fetch();

			var reservation = order.GetValue("reservation") as string;
			if (!string.IsNullOrEmpty(reservation))
			{
				try
				{
					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);

					retVal.NewPaymentStatus = context.Payment.PaymentStatus = PaymentStatus.Paid;
					context.Payment.CapturedDate = DateTime.UtcNow;
					context.Payment.IsApproved = true;
					retVal.IsSuccess = true;
					retVal.OuterId = context.Payment.OuterId = response.InvoiceNumber;
				}
				catch(Exception ex)
				{
					retVal.ErrorMessage = ex.Message;
				}
			}
			else
			{
				retVal.ErrorMessage = "No reservation for this order";
			}

			return retVal;
		}
		/// <summary>
		/// Capture authorized payment
		/// </summary>
		/// <param name="context"></param>
		/// <returns>Result of capturing payment in external system</returns>
		public abstract CaptureProcessPaymentResult CaptureProcessPayment(CaptureProcessPaymentEvaluationContext context);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private Hashtable PrepareCaptureProcessPaymentRequest(CaptureProcessPaymentEvaluationContext context)
        {
            Hashtable request = new Hashtable();

            if (IsTest())
                request.Add("sendToProduction", "false");
            else
                request.Add("sendToProduction", "true");

            request.Add("ccCaptureService_authRequestID", context.Payment.OuterId);
            request.Add("merchantID", MerchantId);
            request.Add("merchantReferenceCode", context.Payment.Number);
            request.Add("ccCaptureService_run", "true");
            request.Add("purchaseTotals_currency", context.Payment.Currency.ToString());
            request.Add("item_0_unitPrice", context.Payment.Sum.ToString());
            //request.Add("item_0_quantity", "1");

            return request;
        }