private void SerializeOrderAttribute(AmazonPayOrderAttribute attribute, Order order)
        {
            if (attribute != null)
            {
                var sb = new StringBuilder();
                using (var writer = new StringWriter(sb))
                {
                    var serializer = new XmlSerializer(typeof(AmazonPayOrderAttribute));
                    serializer.Serialize(writer, attribute);

                    _genericAttributeService.SaveAttribute <string>(order, AmazonPayPlugin.SystemName + ".OrderAttribute", sb.ToString(), order.StoreId);
                }
            }
        }
        private AmazonPayOrderAttribute DeserializeOrderAttribute(Order order)
        {
            var serialized = order.GetAttribute <string>(AmazonPayPlugin.SystemName + ".OrderAttribute", _genericAttributeService, order.StoreId);

            if (!serialized.HasValue())
            {
                var attribute = new AmazonPayOrderAttribute();

                // legacy < v.1.14
                attribute.OrderReferenceId = order.GetAttribute <string>(AmazonPayPlugin.SystemName + ".OrderReferenceId", order.StoreId);

                return(attribute);
            }

            using (var reader = new StringReader(serialized))
            {
                var serializer = new XmlSerializer(typeof(AmazonPayOrderAttribute));
                return((AmazonPayOrderAttribute)serializer.Deserialize(reader));
            }
        }
        private void SerializeOrderAttribute(AmazonPayOrderAttribute attribute, Order order)
        {
            if (attribute != null)
            {
                var sb = new StringBuilder();
                using (var writer = new StringWriter(sb))
                {
                    var serializer = new XmlSerializer(typeof(AmazonPayOrderAttribute));
                    serializer.Serialize(writer, attribute);

                    _genericAttributeService.SaveAttribute<string>(order, AmazonPayCore.AmazonPayOrderAttributeKey, sb.ToString(), order.StoreId);
                }
            }
        }
        public void PostProcessPayment(PostProcessPaymentRequest request)
        {
            // early polling... note we do not have the amazon billing address yet
            //try
            //{
            //	int orderId = request.Order.Id;
            //	var settings = _services.Settings.LoadSetting<AmazonPaySettings>(request.Order.StoreId);

            //	if (orderId != 0 && settings.StatusFetching == AmazonPayStatusFetchingType.Polling)
            //	{
            //		AsyncRunner.Run((container, obj) =>
            //		{
            //			var amazonService = container.Resolve<IAmazonPayService>();
            //			amazonService.EarlyPolling(orderId, obj as AmazonPaySettings);
            //		},
            //		settings, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
            //	}
            //}
            //catch (OffAmazonPaymentsServiceException exc)
            //{
            //	LogAmazonError(exc);
            //}
            //catch (Exception exc)
            //{
            //	LogError(exc);
            //}

            try
            {
                var state = _httpContext.GetAmazonPayState(_services.Localization);

                var orderAttribute = new AmazonPayOrderAttribute()
                {
                    OrderReferenceId = state.OrderReferenceId
                };

                SerializeOrderAttribute(orderAttribute, request.Order);
            }
            catch (Exception exc)
            {
                LogError(exc);
            }
        }
        private AmazonPayOrderAttribute DeserializeOrderAttribute(Order order)
        {
            var serialized = order.GetAttribute<string>(AmazonPayCore.AmazonPayOrderAttributeKey, _genericAttributeService, order.StoreId);

            if (!serialized.HasValue())
            {
                var attribute = new AmazonPayOrderAttribute();

                // legacy < v.1.14
                attribute.OrderReferenceId = order.GetAttribute<string>(AmazonPayCore.SystemName + ".OrderReferenceId", order.StoreId);

                return attribute;
            }

            using (var reader = new StringReader(serialized))
            {
                var serializer = new XmlSerializer(typeof(AmazonPayOrderAttribute));
                return (AmazonPayOrderAttribute)serializer.Deserialize(reader);
            }
        }