コード例 #1
0
		public void Copy(AmazonPaySettings settings, bool fromSettings)
		{
			if (fromSettings)
			{
				UseSandbox = settings.UseSandbox;
				SellerId = settings.SellerId;
				AccessKey = settings.AccessKey;
				SecretKey = settings.SecretKey;
				Marketplace = settings.Marketplace;
				DataFetching = settings.DataFetching;
				PollingMaxOrderCreationDays = settings.PollingMaxOrderCreationDays;
				TransactionType = settings.TransactionType;
				SaveEmailAndPhone = settings.SaveEmailAndPhone;
				ShowButtonInMiniShoppingCart = settings.ShowButtonInMiniShoppingCart;
				AmazonButtonColor = settings.AmazonButtonColor;
				AmazonButtonSize = settings.AmazonButtonSize;
				AddressWidgetWidth = settings.AddressWidgetWidth;
				AddressWidgetHeight = settings.AddressWidgetHeight;
				PaymentWidgetWidth = settings.PaymentWidgetWidth;
				PaymentWidgetHeight = settings.PaymentWidgetHeight;
				AdditionalFee = settings.AdditionalFee;
				AdditionalFeePercentage = settings.AdditionalFeePercentage;
				AddOrderNotes = settings.AddOrderNotes;
				InformCustomerAboutErrors = settings.InformCustomerAboutErrors;
				InformCustomerAddErrors = settings.InformCustomerAddErrors;
			}
			else
			{
				settings.UseSandbox = UseSandbox;
				settings.SellerId = SellerId;
				settings.AccessKey = AccessKey;
				settings.SecretKey = SecretKey;
				settings.Marketplace = Marketplace;
				settings.DataFetching = DataFetching;
				settings.PollingMaxOrderCreationDays = PollingMaxOrderCreationDays;
				settings.TransactionType = TransactionType;
				settings.SaveEmailAndPhone = SaveEmailAndPhone;
				settings.ShowButtonInMiniShoppingCart = ShowButtonInMiniShoppingCart;
				settings.AmazonButtonColor = AmazonButtonColor;
				settings.AmazonButtonSize = AmazonButtonSize;
				settings.AddressWidgetWidth = AddressWidgetWidth;
				settings.AddressWidgetHeight = AddressWidgetHeight;
				settings.PaymentWidgetWidth = PaymentWidgetWidth;
				settings.PaymentWidgetHeight = PaymentWidgetHeight;
				settings.AdditionalFee = AdditionalFee;
				settings.AdditionalFeePercentage = AdditionalFeePercentage;
				settings.AddOrderNotes = AddOrderNotes;
				settings.InformCustomerAboutErrors = InformCustomerAboutErrors;
				settings.InformCustomerAddErrors = InformCustomerAddErrors;
			}
		}
コード例 #2
0
        public AmazonPayClient(AmazonPaySettings settings)
        {
            string appVersion = "1.0";

            try
            {
                appVersion = EngineContext.Current.Resolve<IPluginFinder>().GetPluginDescriptorBySystemName(AmazonPayCore.SystemName).Version.ToString();
            }
            catch (Exception) { }

            var config = new OffAmazonPaymentsServiceConfig()
            {
                ServiceURL = (settings.UseSandbox ? AmazonPayCore.UrlApiEuSandbox : AmazonPayCore.UrlApiEuProduction)
            };

            config.SetUserAgent(AmazonPayCore.AppName, appVersion);

            Settings = settings;
            Service = new OffAmazonPaymentsServiceClient(AmazonPayCore.AppName, appVersion, settings.AccessKey, settings.SecretKey, config);
        }
コード例 #3
0
        public bool FulfillBillingAddress(AmazonPaySettings settings, Order order, AuthorizationDetails details, out string formattedAddress)
        {
            formattedAddress = "";

            if (details == null)
            {
                AmazonPayApiData data;
                details = GetAuthorizationDetails(new AmazonPayClient(settings), order.AuthorizationTransactionId, out data);
            }

            if (details == null || !details.IsSetAuthorizationBillingAddress())
                return false;

            bool countryAllowsShipping, countryAllowsBilling;

            // override billing address cause it is just copy of the shipping address
            details.AuthorizationBillingAddress.ToAddress(order.BillingAddress, _countryService, _stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);

            if (!countryAllowsBilling)
            {
                formattedAddress = details.AuthorizationBillingAddress.ToFormatedAddress(_countryService, _stateProvinceService);
                return false;
            }

            order.BillingAddress.CreatedOnUtc = DateTime.UtcNow;

            if (order.BillingAddress.Email.IsEmpty())
                order.BillingAddress.Email = order.Customer.Email;

            _orderService.UpdateOrder(order);

            formattedAddress = details.AuthorizationBillingAddress.ToFormatedAddress(_countryService, _stateProvinceService);

            return true;
        }
コード例 #4
0
        private void CloseOrderReference(AmazonPaySettings settings, Order order)
        {
            // You can still perform captures against any open authorizations, but you cannot create any new authorizations on the
            // Order Reference object. You can still execute refunds against the Order Reference object.

            try
            {
                var client = new AmazonPayClient(settings);

                var orderAttribute = DeserializeOrderAttribute(order);

                _api.CloseOrderReference(client, orderAttribute.OrderReferenceId);
            }
            catch (OffAmazonPaymentsServiceException exc)
            {
                LogAmazonError(exc);
            }
            catch (Exception exc)
            {
                LogError(exc);
            }
        }
コード例 #5
0
        public void AddOrderNote(AmazonPaySettings settings, Order order, AmazonPayOrderNote note, string anyString = null)
        {
            try
            {
                if (!settings.AddOrderNotes || order == null)
                    return;

                var sb = new StringBuilder();

                string[] orderNoteStrings = T("Plugins.Payments.AmazonPay.OrderNoteStrings").Text.SplitSafe(";");
                string faviconUrl = "{0}Plugins/{1}/Content/images/favicon.png".FormatWith(_services.WebHelper.GetStoreLocation(false), AmazonPayCore.SystemName);

                sb.AppendFormat("<img src=\"{0}\" style=\"float: left; width: 16px; height: 16px;\" />", faviconUrl);

                if (anyString.HasValue())
                {
                    anyString = orderNoteStrings.SafeGet((int)note).FormatWith(anyString);
                }
                else
                {
                    anyString = orderNoteStrings.SafeGet((int)note);
                    anyString = anyString.Replace("{0}", "");
                }

                if (anyString.HasValue())
                {
                    sb.AppendFormat("<span style=\"padding-left: 4px;\">{0}</span>", anyString);
                }

                order.OrderNotes.Add(new OrderNote()
                {
                    Note = sb.ToString(),
                    DisplayToCustomer = false,
                    CreatedOnUtc = DateTime.UtcNow
                });

                _orderService.UpdateOrder(order);
            }
            catch (Exception exc)
            {
                LogError(exc);
            }
        }
コード例 #6
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");
            });
        }
コード例 #7
0
        public AmazonPayClient(AmazonPaySettings settings)
        {
            var config = new OffAmazonPaymentsServiceConfig()
            {
                ServiceURL = (settings.UseSandbox ? AmazonPayCore.UrlApiEuSandbox : AmazonPayCore.UrlApiEuProduction)
            };

            config.SetUserAgent(AmazonPayCore.AppName, AmazonPayCore.AppVersion);

            Settings = settings;
            Service = new OffAmazonPaymentsServiceClient(AmazonPayCore.AppName, AmazonPayCore.AppVersion, settings.AccessKey, settings.SecretKey, config);
        }