GetSingleSiteJobsAsync(object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiGetAsync <List <SingleSiteJob> >( "/place_card_on_single_site_jobs", qd, paging, headers)); }
UpdateSingleSiteJobAsync(object query, PropertyBag body, string safeKey = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, body); return(await ApiPutDelAsync <SingleSiteJob>( "/place_card_on_single_site_jobs/{0}", qd.ID, HttpMethod.Put, body, safeKey, headers)); }
UpdateCardAsync(object query, PropertyBag body, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, body); return(await ApiMultiPutDelAsync <Card>( "/cardsavr_cards", null, qd, HttpMethod.Put, body, null, paging, headers)); }
DeleteCardAsync(object query, string safeKey = null, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, null, false, true); return(await ApiMultiPutDelAsync <Card>( "/cardsavr_cards", null, qd, HttpMethod.Delete, null, safeKey, paging, headers)); }
DeleteCardholderAsync(object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiMultiPutDelAsync <Cardholder>( "/cardholders", null, qd, HttpMethod.Delete, null, null, paging, headers)); }
DeleteAddressAsync(object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiMultiPutDelAsync <Address>( "/cardsavr_addresses", null, qd, HttpMethod.Delete, null, null, paging, headers)); }
DeleteAccountAsync(object query, string safeKey = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, null, false, true); return(await ApiPutDelAsync <Account>( "/cardsavr_accounts/{0}", qd.ID, HttpMethod.Delete, null, safeKey, headers)); }
UpdateUserPasswordAsync(object query, PropertyBag body, HttpRequestHeaders headers = null) { body["password"] = body["password_copy"] = MakePasswordKey((string)body["username"], (string)body["password"]); QueryDef qd = new QueryDef(query, body, false, true); string path = "/cardsavr_users/{0}/update_password"; return(await ApiPutDelAsync <PropertyBag>(path, qd.ID, HttpMethod.Put, body, null, headers)); }
GetMerchantSitesAsync(object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiGetAsync <List <MerchantSite> >("/merchant_sites", qd, paging, headers)); //string url = "https://swch-site-images-mgmt.s3-us-west-2.amazonaws.com/branding/sites.json"; }
UpdateIntegratorsAsync( object query, PropertyBag body, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, body); return(await ApiMultiPutDelAsync <Integrator>( "/integrators", null, qd, HttpMethod.Put, body, null, paging, headers)); }
GetCardPlacementResultReportingJobsAsync( object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiGetAsync <List <CardPlacementResult> >( "/card_placement_result_reporting_jobs", qd, paging, headers)); }
RotateIntegratorsAsync( object query, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); string path = "/integrators/{0}/rotate_key"; return(await ApiPutDelAsync <Integrator>( path, qd.ID, HttpMethod.Put, null, null, headers)); }
UpdateUserAsync(object query, PropertyBag body, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, body); string path = "/cardsavr_users"; if (headers == null) { headers = new HttpRequestMessage().Headers; } return(await ApiMultiPutDelAsync <User>(path, null, qd, HttpMethod.Put, body, null, paging, headers)); }
UpdateAccountAsync(object query, PropertyBag body, string envelopeId, string safeKey = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, body, false, true); if (envelopeId != null) { headers.Add("x-cardsavr-envelope_id", envelopeId); } return(await ApiPutDelAsync <Account>( "/cardsavr_accounts/{0}", qd.ID, HttpMethod.Put, body, safeKey, headers)); }
UpdateCardholderAsync(object query, PropertyBag body, string newSafeKey = null, string safeKey = null, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query, body); string path = "/cardholders"; if (headers == null) { headers = new HttpRequestMessage().Headers; } AddNewSafeKeyHeader(headers, newSafeKey); return(await ApiMultiPutDelAsync <Cardholder>(path, null, qd, HttpMethod.Put, body, null, paging, headers)); }
public static string AppendQueryString(string path, QueryDef qd) { if (qd == null || qd.IsEmpty) { return(path); } if (qd.IsID) { return($"{path}?ids={qd.ID}"); } return(AppendQueryString(path, qd.Collection)); }
// Could be exposed publicly to give advanced users more flexibility. private async Task <CardSavrResponse <List <T> > > ApiMultiPutDelAsync <T>( string path, string pathWithId, QueryDef qd, HttpMethod method, object body, string safeKey, Paging paging = null, HttpRequestHeaders headers = null) where T : class { // by default we just tack the id on the end (we assume no trailing slash). pathWithId = pathWithId ?? path + "/{0}"; CardSavrResponse <List <T> > result; if (qd.IsID) { // this is a singular operation, so just do it. CardSavrResponse <T> singleResponse = await ApiPutDelAsync <T>( pathWithId, qd.ID, method, body, safeKey, headers); // then transform the result into a list. result = new CardSavrResponse <List <T> >() { StatusCode = singleResponse.StatusCode, Paging = singleResponse.Paging, Body = new List <T>() { singleResponse.Body } }; } else { // get all the things implied by the query parameters, the iterate through and perform // the operation on each thing successively. result = await ApiGetAsync <List <T> >(path, qd, paging, headers); foreach (T t in result.Body) { // we have to use reflection on a generic type. string id = Convert.ToString(t.GetType().GetProperty("id").GetValue(t)); // should probably have some error handling here so we can continue on failure. await ApiPutDelAsync <T>(pathWithId, id, method, body, safeKey, headers); } } return(result); }
/*========== PRIVATE IMPLEMENTATION ==========*/ // Could be exposed publicly to give advanced users more flexibility. private async Task <CardSavrResponse <T> > ApiGetAsync <T>( string path, QueryDef qd, Paging paging = null, HttpRequestHeaders headers = null) where T : class { // allow an empty query: enumerates all entities. path = ApiUtil.AppendQueryString(path, qd); log.Debug($"path with query: \"{path}\""); using (HttpRequestMessage request = CreateRequest(HttpMethod.Get, path, null, headers)) { if (paging != null && paging.GetCount() > 0) { request.Headers.Add("x-cardsavr-paging", paging.Stringify()); } using (HttpResponseMessage response = await SendAsync(request)) { return(await ProcessResponseAsync <T>(request, response)); } } }
GetIntegratorsAsync(object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiGetAsync <List <Integrator> >("/integrators", qd, paging, headers)); }
GetBinsAsync(object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiGetAsync <List <BIN> >("/cardsavr_bins", qd, paging, headers)); }
GetCardholdersAsync(object query, Paging paging = null, HttpRequestHeaders headers = null) { QueryDef qd = new QueryDef(query); return(await ApiGetAsync <List <Cardholder> >("/cardholders", qd, paging, headers)); }