Ejemplo n.º 1
0
        private void PollingLoop(PollingLoopData data, Func<bool> poll)
        {
            try
            {
                var sleepMillSec = 8000;
                var loopMillSec = 90000;
                var startTime = DateTime.Now.TimeOfDay;

                for (int i = 0; i < 99 && (DateTime.Now.TimeOfDay.Milliseconds - startTime.Milliseconds) <= loopMillSec; ++i)
                {
                    // inside the loop cause other instances are also updating the order
                    data.Order = _orderService.GetOrderById(data.OrderId);

                    if (data.Settings == null)
                        data.Settings = _services.Settings.LoadSetting<AmazonPaySettings>(data.Order.StoreId);

                    if (data.Client == null)
                        data.Client = new AmazonPayClient(data.Settings);

                    if (!poll())
                        break;

                    Thread.Sleep(sleepMillSec);
                }
            }
            catch (OffAmazonPaymentsServiceException exc)
            {
                LogAmazonError(exc);
            }
            catch (Exception exc)
            {
                LogError(exc);
            }
        }
Ejemplo n.º 2
0
        private void EarlyPolling(int orderId, AmazonPaySettings settings)
        {
            // the Authorization object moves to the Open state after remaining in the Pending state for 30 seconds.

            AmazonPayApiData data;
            var d = new PollingLoopData(orderId);
            d.Settings = settings;

            PollingLoop(d, () =>
            {
                if (d.Order.AuthorizationTransactionId.IsNullOrEmpty())
                    return false;

                var details = _api.GetAuthorizationDetails(d.Client, d.Order.AuthorizationTransactionId, out data);

                if (!data.State.IsCaseInsensitiveEqual("pending"))
                {
                    ProcessAuthorizationResult(d.Client, d.Order, data, details);
                    return false;
                }
                return true;
            });

            PollingLoop(d, () =>
            {
                if (d.Order.CaptureTransactionId.IsNullOrEmpty())
                    return false;

                _api.GetCaptureDetails(d.Client, d.Order.CaptureTransactionId, out data);

                ProcessCaptureResult(d.Client, d.Order, data);

                return data.State.IsCaseInsensitiveEqual("pending");
            });
        }