コード例 #1
0
 public void GetConstraints(OrderReferenceDetails details, IList <string> warnings)
 {
     try
     {
         if (details != null && warnings != null && details.IsSetConstraints())
         {
             foreach (var constraint in details.Constraints.Constraint)
             {
                 string warning = "{0} ({1})".FormatWith(constraint.Description, constraint.ConstraintID);
                 warnings.Add(warning);
             }
         }
     }
     catch (Exception) { }
 }
コード例 #2
0
        public static void ToAddress(this OrderReferenceDetails details, SmartStore.Core.Domain.Common.Address address, ICountryService countryService,
                                     IStateProvinceService stateProvinceService, out bool countryAllowsShipping, out bool countryAllowsBilling)
        {
            countryAllowsShipping = countryAllowsBilling = true;

            if (details.IsSetBuyer() && details.Buyer.IsSetEmail())
            {
                address.Email = details.Buyer.Email;
            }

            if (details.IsSetDestination() && details.Destination.IsSetPhysicalDestination())
            {
                details.Destination.PhysicalDestination.ToAddress(address, countryService, stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);
            }
        }
コード例 #3
0
		public void GetConstraints(OrderReferenceDetails details, IList<string> warnings)
		{
			try
			{
				if (details != null && warnings != null && details.IsSetConstraints())
				{
					foreach (var constraint in details.Constraints.Constraint)
					{
						string warning = "{0} ({1})".FormatWith(constraint.Description, constraint.ConstraintID);
						warnings.Add(warning);
					}
				}
			}
			catch (Exception) { }
		}
コード例 #4
0
        public bool FindAndApplyAddress(OrderReferenceDetails details, Customer customer, bool isShippable, bool forceToTakeAmazonAddress)
        {
            // PlaceOrder requires billing address but we don't get one from Amazon here. so use shipping address instead until we get it from amazon.
            bool countryAllowsShipping, countryAllowsBilling;

            var amazonAddress = new SmartStore.Core.Domain.Common.Address()
            {
                CreatedOnUtc = DateTime.UtcNow
            };

            details.ToAddress(amazonAddress, _countryService, _stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);

            if (isShippable && !countryAllowsShipping)
            {
                return(false);
            }

            if (amazonAddress.Email.IsEmpty())
            {
                amazonAddress.Email = customer.Email;
            }

            if (forceToTakeAmazonAddress)
            {
                // first time to get in touch with an amazon address
                var existingAddress = customer.Addresses.ToList().FindAddress(amazonAddress, true);

                if (existingAddress == null)
                {
                    customer.Addresses.Add(amazonAddress);
                    customer.BillingAddress = amazonAddress;
                }
                else
                {
                    customer.BillingAddress = existingAddress;
                }
            }
            else
            {
                if (customer.BillingAddress == null)
                {
                    customer.Addresses.Add(amazonAddress);
                    customer.BillingAddress = amazonAddress;
                }

                // we already have the address but it is uncomplete, so just complete it
                details.ToAddress(customer.BillingAddress, _countryService, _stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);

                // but now we could have dublicates
                int newAddressId = customer.BillingAddress.Id;
                var addresses    = customer.Addresses.Where(x => x.Id != newAddressId).ToList();

                var existingAddress = addresses.FindAddress(customer.BillingAddress, false);

                if (existingAddress != null)
                {
                    // remove the new and take the old one
                    customer.RemoveAddress(customer.BillingAddress);
                    customer.BillingAddress = existingAddress;

                    try
                    {
                        _addressService.DeleteAddress(newAddressId);
                    }
                    catch (Exception exc)
                    {
                        exc.Dump();
                    }
                }
            }

            customer.ShippingAddress = (isShippable ? customer.BillingAddress : null);

            return(true);
        }
コード例 #5
0
        public static CreateOrderReferenceForIdResponse InvokeCreateOrderReferenceForId(IOffAmazonPaymentsService service, CreateOrderReferenceForIdRequest request)
        {
            CreateOrderReferenceForIdResponse response = null;

            try
            {
                response = service.CreateOrderReferenceForId(request);

                Console.WriteLine("Service Response");
                Console.WriteLine("=============================================================================");
                Console.WriteLine();

                Console.WriteLine("        CreateOrderReferenceForIdResponse");
                if (response.IsSetCreateOrderReferenceForIdResult())
                {
                    Console.WriteLine("            CreateOrderReferenceForIdResult");
                    CreateOrderReferenceForIdResult createOrderReferenceForIdResult = response.CreateOrderReferenceForIdResult;
                    if (createOrderReferenceForIdResult.IsSetOrderReferenceDetails())
                    {
                        Console.WriteLine("                OrderReferenceDetails");
                        OrderReferenceDetails orderReferenceDetails = createOrderReferenceForIdResult.OrderReferenceDetails;
                        if (orderReferenceDetails.IsSetAmazonOrderReferenceId())
                        {
                            Console.WriteLine("                    AmazonOrderReferenceId");
                            Console.WriteLine("                        {0}", orderReferenceDetails.AmazonOrderReferenceId);
                        }
                        if (orderReferenceDetails.IsSetBuyer())
                        {
                            Console.WriteLine("                    Buyer");
                            Buyer buyer = orderReferenceDetails.Buyer;
                            if (buyer.IsSetName())
                            {
                                Console.WriteLine("                        Name");
                                Console.WriteLine("                            {0}", buyer.Name);
                            }
                            if (buyer.IsSetEmail())
                            {
                                Console.WriteLine("                        Email");
                                Console.WriteLine("                            {0}", buyer.Email);
                            }
                            if (buyer.IsSetPhone())
                            {
                                Console.WriteLine("                        Phone");
                                Console.WriteLine("                            {0}", buyer.Phone);
                            }
                        }
                        if (orderReferenceDetails.IsSetOrderTotal())
                        {
                            Console.WriteLine("                    OrderTotal");
                            OrderTotal orderTotal = orderReferenceDetails.OrderTotal;
                            if (orderTotal.IsSetCurrencyCode())
                            {
                                Console.WriteLine("                        CurrencyCode");
                                Console.WriteLine("                            {0}", orderTotal.CurrencyCode);
                            }
                            if (orderTotal.IsSetAmount())
                            {
                                Console.WriteLine("                        Amount");
                                Console.WriteLine("                            {0}", orderTotal.Amount);
                            }
                        }
                        if (orderReferenceDetails.IsSetSellerNote())
                        {
                            Console.WriteLine("                    SellerNote");
                            Console.WriteLine("                        {0}", orderReferenceDetails.SellerNote);
                        }
                        if (orderReferenceDetails.IsSetPlatformId())
                        {
                            Console.WriteLine("                    PlatformId");
                            Console.WriteLine("                        {0}", orderReferenceDetails.PlatformId);
                        }
                        if (orderReferenceDetails.IsSetDestination())
                        {
                            Console.WriteLine("                    Destination");
                            Destination destination = orderReferenceDetails.Destination;
                            if (destination.IsSetDestinationType())
                            {
                                Console.WriteLine("                        DestinationType");
                                Console.WriteLine("                            {0}", destination.DestinationType);
                            }
                            if (destination.IsSetPhysicalDestination())
                            {
                                Console.WriteLine("                        PhysicalDestination");
                                Address physicalDestination = destination.PhysicalDestination;
                                if (physicalDestination.IsSetName())
                                {
                                    Console.WriteLine("                            Name");
                                    Console.WriteLine("                                {0}", physicalDestination.Name);
                                }
                                if (physicalDestination.IsSetAddressLine1())
                                {
                                    Console.WriteLine("                            AddressLine1");
                                    Console.WriteLine("                                {0}", physicalDestination.AddressLine1);
                                }
                                if (physicalDestination.IsSetAddressLine2())
                                {
                                    Console.WriteLine("                            AddressLine2");
                                    Console.WriteLine("                                {0}", physicalDestination.AddressLine2);
                                }
                                if (physicalDestination.IsSetAddressLine3())
                                {
                                    Console.WriteLine("                            AddressLine3");
                                    Console.WriteLine("                                {0}", physicalDestination.AddressLine3);
                                }
                                if (physicalDestination.IsSetCity())
                                {
                                    Console.WriteLine("                            City");
                                    Console.WriteLine("                                {0}", physicalDestination.City);
                                }
                                if (physicalDestination.IsSetCounty())
                                {
                                    Console.WriteLine("                            County");
                                    Console.WriteLine("                                {0}", physicalDestination.County);
                                }
                                if (physicalDestination.IsSetDistrict())
                                {
                                    Console.WriteLine("                            District");
                                    Console.WriteLine("                                {0}", physicalDestination.District);
                                }
                                if (physicalDestination.IsSetStateOrRegion())
                                {
                                    Console.WriteLine("                            StateOrRegion");
                                    Console.WriteLine("                                {0}", physicalDestination.StateOrRegion);
                                }
                                if (physicalDestination.IsSetPostalCode())
                                {
                                    Console.WriteLine("                            PostalCode");
                                    Console.WriteLine("                                {0}", physicalDestination.PostalCode);
                                }
                                if (physicalDestination.IsSetCountryCode())
                                {
                                    Console.WriteLine("                            CountryCode");
                                    Console.WriteLine("                                {0}", physicalDestination.CountryCode);
                                }
                                if (physicalDestination.IsSetPhone())
                                {
                                    Console.WriteLine("                            Phone");
                                    Console.WriteLine("                                {0}", physicalDestination.Phone);
                                }
                            }
                        }
                        if (orderReferenceDetails.IsSetBillingAddress())
                        {
                            Console.WriteLine("                    BillingAddress");
                            BillingAddress billingAddress = orderReferenceDetails.BillingAddress;
                            if (billingAddress.IsSetAddressType())
                            {
                                Console.WriteLine("                        AddressType");
                                Console.WriteLine("                            {0}", billingAddress.AddressType);
                            }
                            if (billingAddress.IsSetPhysicalAddress())
                            {
                                Console.WriteLine("                        PhysicalAddress");
                                Address physicalAddress = billingAddress.PhysicalAddress;
                                if (physicalAddress.IsSetName())
                                {
                                    Console.WriteLine("                            Name");
                                    Console.WriteLine("                                {0}", physicalAddress.Name);
                                }
                                if (physicalAddress.IsSetAddressLine1())
                                {
                                    Console.WriteLine("                            AddressLine1");
                                    Console.WriteLine("                                {0}", physicalAddress.AddressLine1);
                                }
                                if (physicalAddress.IsSetAddressLine2())
                                {
                                    Console.WriteLine("                            AddressLine2");
                                    Console.WriteLine("                                {0}", physicalAddress.AddressLine2);
                                }
                                if (physicalAddress.IsSetAddressLine3())
                                {
                                    Console.WriteLine("                            AddressLine3");
                                    Console.WriteLine("                                {0}", physicalAddress.AddressLine3);
                                }
                                if (physicalAddress.IsSetCity())
                                {
                                    Console.WriteLine("                            City");
                                    Console.WriteLine("                                {0}", physicalAddress.City);
                                }
                                if (physicalAddress.IsSetCounty())
                                {
                                    Console.WriteLine("                            County");
                                    Console.WriteLine("                                {0}", physicalAddress.County);
                                }
                                if (physicalAddress.IsSetDistrict())
                                {
                                    Console.WriteLine("                            District");
                                    Console.WriteLine("                                {0}", physicalAddress.District);
                                }
                                if (physicalAddress.IsSetStateOrRegion())
                                {
                                    Console.WriteLine("                            StateOrRegion");
                                    Console.WriteLine("                                {0}", physicalAddress.StateOrRegion);
                                }
                                if (physicalAddress.IsSetPostalCode())
                                {
                                    Console.WriteLine("                            PostalCode");
                                    Console.WriteLine("                                {0}", physicalAddress.PostalCode);
                                }
                                if (physicalAddress.IsSetCountryCode())
                                {
                                    Console.WriteLine("                            CountryCode");
                                    Console.WriteLine("                                {0}", physicalAddress.CountryCode);
                                }
                                if (physicalAddress.IsSetPhone())
                                {
                                    Console.WriteLine("                            Phone");
                                    Console.WriteLine("                                {0}", physicalAddress.Phone);
                                }
                            }
                        }
                        if (orderReferenceDetails.IsSetReleaseEnvironment())
                        {
                            Console.WriteLine("                    ReleaseEnvironment");
                            Console.WriteLine("                        {0}", orderReferenceDetails.ReleaseEnvironment);
                        }
                        if (orderReferenceDetails.IsSetSellerOrderAttributes())
                        {
                            Console.WriteLine("                    SellerOrderAttributes");
                            SellerOrderAttributes sellerOrderAttributes = orderReferenceDetails.SellerOrderAttributes;
                            if (sellerOrderAttributes.IsSetSellerOrderId())
                            {
                                Console.WriteLine("                        SellerOrderId");
                                Console.WriteLine("                            {0}", sellerOrderAttributes.SellerOrderId);
                            }
                            if (sellerOrderAttributes.IsSetStoreName())
                            {
                                Console.WriteLine("                        StoreName");
                                Console.WriteLine("                            {0}", sellerOrderAttributes.StoreName);
                            }
                            if (sellerOrderAttributes.IsSetOrderItemCategories())
                            {
                                Console.WriteLine("                        OrderItemCategories");
                                OrderItemCategories orderItemCategories   = sellerOrderAttributes.OrderItemCategories;
                                List <String>       orderItemCategoryList = orderItemCategories.OrderItemCategory;
                                foreach (String orderItemCategory in orderItemCategoryList)
                                {
                                    Console.WriteLine("                            OrderItemCategory");
                                    Console.WriteLine("                                {0}", orderItemCategory);
                                }
                            }
                            if (sellerOrderAttributes.IsSetCustomInformation())
                            {
                                Console.WriteLine("                        CustomInformation");
                                Console.WriteLine("                            {0}", sellerOrderAttributes.CustomInformation);
                            }
                        }
                        if (orderReferenceDetails.IsSetOrderReferenceStatus())
                        {
                            Console.WriteLine("                    OrderReferenceStatus");
                            OrderReferenceStatus orderReferenceStatus = orderReferenceDetails.OrderReferenceStatus;
                            if (orderReferenceStatus.IsSetState())
                            {
                                Console.WriteLine("                        State");
                                Console.WriteLine("                            {0}", orderReferenceStatus.State);
                            }
                            if (orderReferenceStatus.IsSetLastUpdateTimestamp())
                            {
                                Console.WriteLine("                        LastUpdateTimestamp");
                                Console.WriteLine("                            {0}", orderReferenceStatus.LastUpdateTimestamp);
                            }
                            if (orderReferenceStatus.IsSetReasonCode())
                            {
                                Console.WriteLine("                        ReasonCode");
                                Console.WriteLine("                            {0}", orderReferenceStatus.ReasonCode);
                            }
                            if (orderReferenceStatus.IsSetReasonDescription())
                            {
                                Console.WriteLine("                        ReasonDescription");
                                Console.WriteLine("                            {0}", orderReferenceStatus.ReasonDescription);
                            }
                        }
                        if (orderReferenceDetails.IsSetConstraints())
                        {
                            Console.WriteLine("                    Constraints");
                            Constraints       constraints    = orderReferenceDetails.Constraints;
                            List <Constraint> constraintList = constraints.Constraint;
                            foreach (Constraint constraint in constraintList)
                            {
                                Console.WriteLine("                        Constraint");
                                if (constraint.IsSetConstraintID())
                                {
                                    Console.WriteLine("                            ConstraintID");
                                    Console.WriteLine("                                {0}", constraint.ConstraintID);
                                }
                                if (constraint.IsSetDescription())
                                {
                                    Console.WriteLine("                            Description");
                                    Console.WriteLine("                                {0}", constraint.Description);
                                }
                            }
                        }
                        if (orderReferenceDetails.IsSetCreationTimestamp())
                        {
                            Console.WriteLine("                    CreationTimestamp");
                            Console.WriteLine("                        {0}", orderReferenceDetails.CreationTimestamp);
                        }
                        if (orderReferenceDetails.IsSetExpirationTimestamp())
                        {
                            Console.WriteLine("                    ExpirationTimestamp");
                            Console.WriteLine("                        {0}", orderReferenceDetails.ExpirationTimestamp);
                        }
                        if (orderReferenceDetails.IsSetParentDetails())
                        {
                            Console.WriteLine("                    ParentDetails");
                            ParentDetails parentDetails = orderReferenceDetails.ParentDetails;
                            if (parentDetails.IsSetId())
                            {
                                Console.WriteLine("                        Id");
                                Console.WriteLine("                            {0}", parentDetails.Id);
                            }
                            if (parentDetails.IsSetType())
                            {
                                Console.WriteLine("                        Type");
                                Console.WriteLine("                            {0}", parentDetails.Type);
                            }
                        }
                        if (orderReferenceDetails.IsSetIdList())
                        {
                            Console.WriteLine("                    IdList");
                            IdList        idList     = orderReferenceDetails.IdList;
                            List <String> memberList = idList.member;
                            foreach (String member in memberList)
                            {
                                Console.WriteLine("                        member");
                                Console.WriteLine("                            {0}", member);
                            }
                        }
                    }
                }
                if (response.IsSetResponseMetadata())
                {
                    Console.WriteLine("            ResponseMetadata");
                    ResponseMetadata responseMetadata = response.ResponseMetadata;
                    if (responseMetadata.IsSetRequestId())
                    {
                        Console.WriteLine("                RequestId");
                        Console.WriteLine("                    {0}", responseMetadata.RequestId);
                    }
                }
            }
            catch (OffAmazonPaymentsServiceException ex)
            {
                PrintException(ex);
            }
            return(response);
        }
コード例 #6
0
        public bool FindAndApplyAddress(OrderReferenceDetails details, Customer customer, bool isShippable, bool forceToTakeAmazonAddress)
        {
            // PlaceOrder requires billing address but we don't get one from Amazon here. so use shipping address instead until we get it from amazon.
            bool countryAllowsShipping, countryAllowsBilling;

            var amazonAddress = new SmartStore.Core.Domain.Common.Address()
            {
                CreatedOnUtc = DateTime.UtcNow
            };

            details.ToAddress(amazonAddress, _countryService, _stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);

            if (isShippable && !countryAllowsShipping)
                return false;

            if (amazonAddress.Email.IsEmpty())
                amazonAddress.Email = customer.Email;

            if (forceToTakeAmazonAddress)
            {
                // first time to get in touch with an amazon address
                var existingAddress = customer.Addresses.ToList().FindAddress(amazonAddress, true);

                if (existingAddress == null)
                {
                    customer.Addresses.Add(amazonAddress);
                    customer.BillingAddress = amazonAddress;
                }
                else
                {
                    customer.BillingAddress = existingAddress;
                }
            }
            else
            {
                if (customer.BillingAddress == null)
                {
                    customer.Addresses.Add(amazonAddress);
                    customer.BillingAddress = amazonAddress;
                }

                // we already have the address but it is uncomplete, so just complete it
                details.ToAddress(customer.BillingAddress, _countryService, _stateProvinceService, out countryAllowsShipping, out countryAllowsBilling);

                // but now we could have dublicates
                int newAddressId = customer.BillingAddress.Id;
                var addresses = customer.Addresses.Where(x => x.Id != newAddressId).ToList();

                var existingAddress = addresses.FindAddress(customer.BillingAddress, false);

                if (existingAddress != null)
                {
                    // remove the new and take the old one
                    customer.RemoveAddress(customer.BillingAddress);
                    customer.BillingAddress = existingAddress;

                    try
                    {
                        _addressService.DeleteAddress(newAddressId);
                    }
                    catch (Exception exc)
                    {
                        exc.Dump();
                    }
                }
            }

            customer.ShippingAddress = (isShippable ? customer.BillingAddress : null);

            return true;
        }