Ejemplo n.º 1
0
        private static async Task <IEnumerable <Location> > GetStoresForAccountAsync(MyBusinessService service, Account account)
        {
            List <Location> downloadedLocations = new List <Location>();

            AccountsResource.LocationsResource.ListRequest locationsListRequest =
                service.Accounts.Locations.List(account.Name);

            locationsListRequest.PageSize = 100;

            ListLocationsResponse locationsResult = await locationsListRequest.ExecuteAsync().ConfigureAwait(false);

            if (locationsResult?.Locations != null)

            {
                downloadedLocations.AddRange(locationsResult.Locations);

                while (locationsResult.NextPageToken != null)

                {
                    locationsListRequest.PageToken = locationsResult.NextPageToken;

                    locationsResult = await locationsListRequest.ExecuteAsync().ConfigureAwait(false);

                    downloadedLocations.AddRange(locationsResult.Locations);
                }
            }

            else

            {
                Console.WriteLine($@"Account {account.Name} has no locations.");
            }

            return(downloadedLocations);
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonDataSyncConfig config = new AmazonDataSyncConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonDataSyncClient client = new AmazonDataSyncClient(creds, config);

            ListLocationsResponse resp = new ListLocationsResponse();

            do
            {
                ListLocationsRequest req = new ListLocationsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListLocations(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Locations)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListLocationsResponse response = new ListLocationsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Locations", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <LocationListEntry, LocationListEntryUnmarshaller>(LocationListEntryUnmarshaller.Instance);
                    response.Locations = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Ejemplo n.º 4
0
        static public async Task <ListLocationsResponse> GetLocations()
        {
            LocationsApi api = new LocationsApi();

            ListLocationsResponse resp = await api.ListLocationsAsync();

            return(resp);
        }
Ejemplo n.º 5
0
        public static void Main(string[] args)
        {
            // Configure OAuth2 access token for authorization: oauth2
            string HMS  = "sq0atp-M5ylQzjwtUqHFV_1aZBkWw";
            string TEST = "sq0atp-NbIspn1KqTCzVxmJJblliQ";

            Configuration.Default.AccessToken = HMS;

//			PortCustomersAsync().Wait();
            //WebRequest.DefaultWebProxy = new WebProxy("127.0.0.1", 8888);
            //FixLocations().Wait();
            List <ShopifySharp.Product> products = Shopify.GetProductsAsync().Result;
            //SetInventory(products).Wait();
            //FixBarCodes(products).Wait();
            ListLocationsResponse locations = GetLocations().Result;
            //			DeleteProducts().Wait();
            //			PortItemsAsync(locations.Locations[0].Id).Wait();
            //			PortItemsAsync("me").Wait();
            ListTransactionsResponse transactions = GetTransactions(locations.Locations[0].Id).Result;
            Customer customer  = GetCustomer("Raboud", "Robert").Result;
            Customer customer2 = GetCustomer("Raboud", "Carrie").Result;

            GetProductsAsync().Wait();

            //var customerTransactions = transactions.Transactions.Where(t => t.Tenders.Any(te => te.CustomerId == customer.Id)).ToList();
            //foreach (var transaction in customerTransactions)
            //{
            //	foreach (var tender in transaction.Tenders)
            //	{
            //		if (tender.CustomerId == customer.Id)
            //		{
            //			tender.CustomerId = customer2.Id;
            //		}
            //	}
            //}
        }
Ejemplo n.º 6
0
        private async Task SynchVenuesWithExternalPaymentProvider(string accessToken, Company company)
        {
            if (company == null)
            {
                return;
            }

            try
            {
                var client = new SquareClient.Builder()
                             .Environment(_settings.Connection.SquarePaymentsSandbox ? Square.Environment.Sandbox : Square.Environment.Production)
                             .AccessToken(accessToken)
                             .Build();

                ListLocationsResponse result = await client.LocationsApi.ListLocationsAsync().ConfigureAwait(false);

                var companyVenues = await _venues.FetchCompanyVenues(company.CompanyId, 0, int.MaxValue)
                                    .OnSuccess(c => c.Value.ToList())
                                    .ConfigureAwait(true);

                if (companyVenues.IsSuccess)
                {
                    foreach (var item in companyVenues.Value)
                    {
                        try
                        {
                            var matchedLocation = result.Locations
                                                  .FirstOrDefault(
                                x => NormaliseString(x.Name) == NormaliseString(item.VenueName) &&
                                NormaliseString(x.Address.PostalCode) == NormaliseString(item.VenuePostCode));

                            // need to find a match in Square location
                            if (matchedLocation != null)
                            {
                                if (string.IsNullOrWhiteSpace(item.ExternalLocationId) && matchedLocation != null)
                                {
                                    // We have a match and need to update local Database
                                    await _venues.UpdateVenue(new VenuePatch
                                    {
                                        ResourceId         = item.VenueId,
                                        ExternalLocationId = new PatchOperation <string> {
                                            Operation = OperationKind.Update, Value = matchedLocation.Id
                                        },
                                    }).ConfigureAwait(false);
                                }
                            }
                            else if (matchedLocation == null)
                            {
                                // we have a location in our system that does not exist in sqaure. Need to add one
                                var createLocation = new CreateLocationRequest(new Location(
                                                                                   name: item.VenueName,
                                                                                   address:
                                                                                   new Address(
                                                                                       addressLine1: string.IsNullOrWhiteSpace(item.VenueAddress) ? "Not supplied" : item.VenueAddress,
                                                                                       addressLine2: item.VenueAddress2,
                                                                                       addressLine3: item.VenueAddress3,
                                                                                       postalCode: string.IsNullOrWhiteSpace(item.VenuePostCode) ? "Not supplied" : item.VenuePostCode,
                                                                                       locality: string.IsNullOrWhiteSpace(item.VenueCounty) ? "Not supplied" : item.VenueCounty,
                                                                                       firstName: item.VenueContact),
                                                                                   status: "ACTIVE",
                                                                                   phoneNumber: GetVenuePhoneNumber(company, item)));

                                var newLocation = client.LocationsApi.CreateLocation(createLocation);

                                if (newLocation.Location != null)
                                {
                                    await _venues.UpdateVenue(new VenuePatch
                                    {
                                        ResourceId         = item.VenueId,
                                        ExternalLocationId = new PatchOperation <string> {
                                            Operation = OperationKind.Update, Value = newLocation.Location.Id
                                        },
                                    }).ConfigureAwait(false);
                                }
                            }
                        }
                        catch (ApiException e)
                        {
                            Logger.LogError(e, $"Failed to create business location for venue {item.VenueName}");
                        }
                    }
                }
            }
            catch (ApiException e)
            {
                Logger.LogError(e, $"Failed to connect to Square API");
            }
        }