public async Task <ResponseProxy <CustomerModel> > SearchCustomersAsync(string query) { var client = new HttpClient(); string baseUrl = ApiUrlHelper.BaseUrl(); client.BaseAddress = new Uri(baseUrl); var url = string.Concat(baseUrl, "/api/", "Customer/", "SearchCustomers?query=", query); var response = client.GetAsync(url).Result; if (response.StatusCode == HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); var Customers = JsonConvert.DeserializeObject <List <CustomerModel> >(result); return(new ResponseProxy <CustomerModel> { Status = true, Code = (int)HttpStatusCode.OK, Message = "Status", List = Customers }); } else { return(new ResponseProxy <CustomerModel> { Code = (int)response.StatusCode, Message = "Error" }); } }
public async Task <EResponseBase <BillDetailProxy> > DetailCustomerAsync(int ID) { var client = new HttpClient(); string baseUrl = ApiUrlHelper.BaseUrl(); client.BaseAddress = new Uri(baseUrl); var url = string.Concat(baseUrl, "/api/", "BillDetail/", "GetBillDetail/", ID); var response = client.GetAsync(url).Result; if (response.StatusCode == HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); var BillDetail = JsonConvert.DeserializeObject <BillDetailProxy>(result); return(new EResponseBase <BillDetailProxy> { Status = true, Code = (int)HttpStatusCode.OK, Message = "Status", Object = BillDetail }); } else { return(new EResponseBase <BillDetailProxy> { Code = (int)response.StatusCode, Message = "Error" }); } }
public async Task <HostedPaymentPageCreateSessionResponse> CreateSession( HostedPaymentPageCreateSessionRequest session) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri); return(await Post <HostedPaymentPageCreateSessionResponse>(url, session).ConfigureAwait(false)); }
public AutomationDataFactory(DataFactoryConfiguration configuration, TestShippingAuthCredential testShippingAuthCredential) { //empties and nulls validation ApiUrlHelper.ValidateUrl(configuration.IntegrationsApiUrl, nameof(configuration.IntegrationsApiUrl)); ApiUrlHelper.ValidateUrl(configuration.ShippingServiceApiUrl, nameof(configuration.ShippingServiceApiUrl)); //clean service api url string integrationsApiUrl = ApiUrlHelper.GetRequesterFormatUrl(configuration.IntegrationsApiUrl); string shippingServiceApiUrl = ApiUrlHelper.GetRequesterFormatUrl(configuration.ShippingServiceApiUrl); string tenantUrl = ApiUrlHelper.GetRequesterFormatUrl(configuration.TenantSiteUrl); //clients initialization var integrationsClient = new IntegrationsWebAppClient(integrationsApiUrl, configuration.TenantExternalIdentifier, configuration.TenantInternalIdentifier, configuration.IntegrationsApiUrl.Contains("https")); var shippingServiceClient = new ShippingServiceClient(shippingServiceApiUrl, configuration.TenantExternalIdentifier, configuration.ShippingServiceApiUrl.Contains("https")); //dependencies setup var usersProcessor = new UserAccountsProcessor(integrationsClient); Users = new UserAccountsFactory(usersProcessor); var shippingProcessor = new ShippingServiceProcessor(shippingServiceClient, configuration.ShippingServiceApiUrl, configuration.TenantExternalIdentifier); Shipping = new ShippingConfigurationFactory(shippingProcessor, testShippingAuthCredential); var productsProcessor = new MerchandiseProcessor(integrationsClient); Products = new ProductsFactory(productsProcessor, tenantUrl); }
public async Task AuthenticateWithToken(TestShippingAuthCredential authCredential) { var authRequest = new ShippingAuthRequest { Name = authCredential.Name, Password = authCredential.Password, PublicKey = authCredential.PublicKey }; var response = await Client.Token.Authenticate(authRequest); if (!response.Success) { throw new Exception($"Shipping auth request responded with: {response.StatusCode} code"); } //reasign client dependency string essUrl = ApiUrlHelper.GetRequesterFormatUrl(_essApiUrl); Client = new ShippingServiceClient(essUrl, _tenantExtId, response.Result, ApiUrlHelper.UrlContainsHttps(_essApiUrl)); //if response is null, then auth is not success var testResponse = await Client.ShippingConfigurations.GetSingle("string"); if (testResponse == null) { throw new Exception("Endpoints are not authenticated"); } }
/// <summary> /// Returns a collection of transactions. /// </summary> /// <param name="paymentReference">Optional. The reference id of the payout</param> /// <param name="orderId">Optional. The Klarna assigned order id reference</param> /// <param name="size"> /// Optional. How many elements to include in the result. If no value for size is provided, /// a default of 20 will be used. /// </param> /// <param name="offset">Optional. The current offset. Describes "where" in a collection the current starts.</param> /// <returns><see cref="TransactionCollection"/></returns> public async Task <TransactionCollection> GetTransactions(string paymentReference = "", string orderId = "", int size = 0, int offset = 0) { var parameters = new NameValueCollection(); if (!string.IsNullOrEmpty(paymentReference)) { parameters.Add("payment_reference", paymentReference); } if (!string.IsNullOrEmpty(orderId)) { parameters.Add("order_id", orderId); } if (size > 0) { parameters.Add("size", size.ToString("F0")); } if (offset > 0) { parameters.Add("offset", offset.ToString("F0")); } var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.SettlementTransactions, null, parameters); return(await Get <TransactionCollection>(url).ConfigureAwait(false)); }
public async Task <EResponseBase <BillDetailProxy> > DeleteCustomerAsync(int ID) { var client = new HttpClient(); string baseUrl = ApiUrlHelper.BaseUrl(); client.BaseAddress = new Uri(baseUrl); var url = string.Concat(baseUrl, "/api/", "BillDetail/", "DeleteBillDetail/", ID); var response = client.DeleteAsync(url).Result; if (response.StatusCode == HttpStatusCode.OK) { var result = await response.Content.ReadAsStringAsync(); var exito = JsonConvert.DeserializeObject <bool>(result); return(new EResponseBase <BillDetailProxy> { Status = exito, Code = 0, Message = "Exito" }); } else { return(new EResponseBase <BillDetailProxy> { Status = false, Code = (int)response.StatusCode, Message = "Error" }); } }
/// <summary> /// Creates a new HPP session /// </summary> /// <param name="session">The <see cref="HppModel.SessionCreationRequestV1"/> object</param> /// <returns>A single <see cref="HppModel.SessionCreationResponseV1"/> object</returns> public async Task <HppModel.SessionCreationResponseV1> CreateSession( HppModel.SessionCreationRequestV1 session) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri); return(await Post <HppModel.SessionCreationResponseV1>(url, session).ConfigureAwait(false)); }
/// <summary> /// Returns a collection of payouts. /// </summary> /// <param name="startDate">Optional. ISO-8601 formatted date with optional time string</param> /// <param name="endDate">Optional. ISO-8601 formatted date with optional time string</param> /// <param name="currencyCode">Optional. ISO-3166 Currency Code.</param> /// <param name="size">Optional. How many elements to include in the result. If no value for size is provided, a default of 20 will be used.</param> /// <param name="offset">Optional. The current offset. Describes "where" in a collection the current starts.</param> /// <returns><see cref="SettlementsGetAllPayoutsResponse"/></returns> public async Task <SettlementsGetAllPayoutsResponse> GetAllPayouts(string startDate = "", string endDate = "", string currencyCode = "", int size = 0, int offset = 0) { var parameters = new NameValueCollection(); if (!string.IsNullOrEmpty(startDate)) { parameters.Add("start_date", startDate); } if (!string.IsNullOrEmpty(endDate)) { parameters.Add("end_date", endDate); } if (!string.IsNullOrEmpty(currencyCode)) { parameters.Add("currency_code", currencyCode); } if (size > 0) { parameters.Add("size", size.ToString("F0")); } if (offset > 0) { parameters.Add("offset", offset.ToString("F0")); } var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, null, parameters); return(await Get <SettlementsGetAllPayoutsResponse>(url).ConfigureAwait(false)); }
/// <summary> /// Returns a collection of transactions. /// </summary> /// <param name="paymentReference">Optional. The reference id of the payout</param> /// <param name="orderId">Optional. The Klarna assigned order id reference</param> /// <param name="size">Optional. How many elements to include in the result. If no value for size is provided, a default of 20 will be used.</param> /// <param name="offset">Optional. The current offset. Describes "where" in a collection the current starts.</param> /// <returns></returns> public async Task <SettlementsGetTransactionsResponse> GetTransactions(string paymentReference = "", string orderId = "", int size = 0, int offset = 0) { var nvm = new NameValueCollection(); if (!string.IsNullOrEmpty(paymentReference)) { nvm.Add("payment_reference", paymentReference); } if (!string.IsNullOrEmpty(orderId)) { nvm.Add("order_id", orderId); } if (size > 0) { nvm.Add("size", size.ToString("F0")); } if (offset > 0) { nvm.Add("offset", offset.ToString("F0")); } var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.SettlementTransactions, null, nvm); var response = await Get <SettlementsGetTransactionsResponse>(url); return(response); }
/// <summary> /// Create a new order using the customer token /// </summary> /// <param name="customerToken">Customer token</param> /// <param name="order">A <see cref="CustomerTokenOrder"/> object</param> /// <returns><see cref="CustomerTokenCreateOrderResponse"/></returns> public async Task <CustomerTokenCreateOrderResponse> CreateOrder(string customerToken, CustomerTokenOrder order) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"{customerToken}/order"); var response = await Post <CustomerTokenCreateOrderResponse>(url, order); return(response); }
/// <summary> /// Creates a new order /// <a href="https://developers.klarna.com/api/#payments-api-create-a-new-order"> /// https://developers.klarna.com/api/#payments-api-create-a-new-order /// </a> /// </summary> /// <param name="authorizationToken">Authorization token from JS client</param> /// <param name="order">The <see cref="PaymentOrder"/> object</param> /// <returns><see cref="PaymentOrderResponse"/></returns> public async Task <Order> CreateOrder(string authorizationToken, CreateOrderRequest order) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.PaymentAuthorizations, $"{authorizationToken}/order"); return(await Post <Order>(url, order).ConfigureAwait(false)); }
/// <summary> /// Updates an existing order. /// Please note: an order can only be updated when the status is 'checkout_incomplete'. /// <a href="https://developers.klarna.com/api/#checkout-api-update-an-order">https://developers.klarna.com/api/#checkout-api-update-an-order</a> /// </summary> /// <param name="order">The <see cref="CheckoutOrder"/> object</param> /// <returns><see cref="CheckoutOrder"/></returns> public async Task <CheckoutOrder> UpdateOrder(CheckoutOrder order) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, order.OrderId); var response = await Post <CheckoutOrder>(url, order); return(response); }
/// <summary> /// Get all captures for one order /// <a href="https://developers.klarna.com/api/#order-management-api-get-all-captures-for-one-order">https://developers.klarna.com/api/#order-management-api-get-all-captures-for-one-order</a> /// </summary> /// <param name="orderId">Id of order to retrieve captures</param> /// <returns>Collection of <see cref="OrderManagementCapture"/></returns> public async Task <ICollection <OrderManagementCapture> > GetCapturesForOrder(string orderId) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"{orderId}/captures"); var response = await Get <ICollection <OrderManagementCapture> >(url); return(response); }
/// <summary> /// Get one capture /// <a href="https://developers.klarna.com/api/#order-management-api-get-one-capture">https://developers.klarna.com/api/#order-management-api-get-one-capture</a> /// </summary> /// <param name="orderId">Id of order that contains the capture</param> /// <param name="captureId">Id of capture to retrieve</param> /// <returns><see cref="OrderManagementCapture"/></returns> public async Task <OrderManagementCapture> GetCapture(string orderId, string captureId) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"{orderId}/captures/{captureId}"); var response = await Get <OrderManagementCapture>(url); return(response); }
/// <summary> /// Retrieve an existing settlement /// To read the settlement resource provide the settlement identifier. /// </summary> /// <param name="settlementId">Unique settlement identifier.</param> /// <param name="keyId">Unique identifier for the public key used for encryption of the card data</param> /// <returns>A single <see cref="VirtualCardSettlement"/> object</returns> public async Task <VirtualCardSettlement> GetSettlement(string settlementId, string keyId) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, settlementId); return(await Get <VirtualCardSettlement>(url, new Dictionary <string, string> { { "KeyId", keyId } }).ConfigureAwait(false)); }
/// <summary> /// Create a new settlement /// To create a settlement resource provide a completed order identifier and (optionally) a promise identifier. /// </summary> /// <param name="request">The <see cref="VirtualCardCreateSettlementRequest"/> object</param> /// <returns>A single <see cref="VirtualCardSettlement"/> object</returns> public async Task <VirtualCardSettlement> CreateSettlement(VirtualCardCreateSettlementRequest request) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri); var response = await Post <VirtualCardSettlement>(url, request); return(response); }
/// <summary> /// Create capture /// <a href="https://developers.klarna.com/api/#order-management-api-create-capture">https://developers.klarna.com/api/#order-management-api-create-capture</a> /// </summary> /// <param name="orderId">Id of order to create capture</param> /// <param name="capture">The <see cref="OrderManagementCapture"/> object</param> /// <returns>Object of <see cref="OrderManagementCapture"/> </returns> public async Task <OrderManagementCapture> CreateCapture(string orderId, OrderManagementCreateCapture capture) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"{orderId}/captures"); OrderManagementCapture response = await Post <OrderManagementCapture>(url, capture); return(response); }
/// <summary> /// Get HPP session status /// </summary> /// <param name="sessionId">HPP session id</param> /// <returns>A single <see cref="HostedPaymentPageSessionStatus"/> object</returns> public async Task <HostedPaymentPageSessionStatus> GetSessionStatus(string sessionId) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"{sessionId}/status"); var response = await Get <HostedPaymentPageSessionStatus>(url); return(response); }
/// <summary> /// Use this API call to read an order from Klarna. /// Note that orders should only be read from the checkout API until the order is completed. Completed orders should be read using the order management API /// <a href="https://developers.klarna.com/api/#checkout-api-retrieve-an-order">https://developers.klarna.com/api/#checkout-api-retrieve-an-order</a> /// </summary> /// <param name="orderId">ID of the order to retrieve</param> /// <returns><see cref="CheckoutOrder"/></returns> public async Task <CheckoutOrder> GetOrder(string orderId) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, orderId); var response = await Get <CheckoutOrder>(url); return(response); }
/// <summary> /// Retrieves a settled order's settlement /// To read the order's settlement resource provide the order identifier. /// </summary> /// <param name="orderId">Unique identifier for the order associated to the settlement.</param> /// <param name="keyId">Unique identifier for the public key used for encryption of the card data.</param> /// <returns>A single <see cref="SettlementResponse"/> object</returns> public async Task <SettlementResponse> GetSettlementForOrder(string orderId, string keyId) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, $"order/{orderId}"); return(await Get <SettlementResponse>(url, new Dictionary <string, string> { { "KeyId", keyId } }).ConfigureAwait(false)); }
/// <summary> /// Read customer tokens details /// </summary> /// <param name="customerToken">Customer token</param> /// <returns><see cref="CustomerTokenDetails"/></returns> public async Task <CustomerTokenDetails> GetCustomerTokenDetails(string customerToken) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, customerToken); var response = await Get <CustomerTokenDetails>(url); return(response); }
/// <summary> /// Create a new order /// <a href="https://developers.klarna.com/api/#payments-api-create-a-new-order">https://developers.klarna.com/api/#payments-api-create-a-new-order</a> /// </summary> /// <param name="authorizationToken">Authorization token from JS client</param> /// <param name="order">The <see cref="PaymentOrder"/> object</param> /// <returns><see cref="PaymentOrderResponse"/></returns> public async Task <PaymentOrderResponse> CreateOrder(string authorizationToken, PaymentOrder order) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.PaymentAuthorizations, $"{authorizationToken}/order"); var response = await Post <PaymentOrderResponse>(url, order); return(response); }
/// <summary> /// Generate a consumer token /// <a href="https://developers.klarna.com/api/#payments-api-generate-a-consumer-token">https://developers.klarna.com/api/#payments-api-generate-a-consumer-token</a> /// </summary> /// <param name="authorizationToken">Authorization token from JS client</param> /// <param name="consumerTokenRequest">The <see cref="PaymentGenerateConsumerTokenRequest"/> object</param> /// <returns><see cref="PaymentGenerateConsumerTokenResponse"/></returns> public async Task <PaymentGenerateConsumerTokenResponse> GenerateConsumerToken(string authorizationToken, PaymentGenerateConsumerTokenRequest consumerTokenRequest) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.PaymentAuthorizations, $"{authorizationToken}/customer-token"); var response = await Post <PaymentGenerateConsumerTokenResponse>(url, consumerTokenRequest); return(response); }
/// <summary> /// Read an existing credit session /// <a href="https://developers.klarna.com/api/#payments-api-read-an-existing-credit-session">https://developers.klarna.com/api/#payments-api-read-an-existing-credit-session</a> /// </summary> /// <param name="sessionId">Id of the credit session to retrieve</param> /// <returns><see cref="PaymentCreditSession"/></returns> public async Task <PaymentCreditSession> GetCreditSession(string sessionId) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, sessionId); var response = await Get <PaymentCreditSession>(url); return(response); }
/// <summary> /// Create a new credit session /// <a href="https://developers.klarna.com/api/#payments-api-create-a-new-credit-session">https://developers.klarna.com/api/#payments-api-create-a-new-credit-session</a> /// </summary> /// <param name="creditSession">The <see cref="PaymentCreditSession"/> object</param> /// <returns><see cref="PaymentCreditSessionResponse"/></returns> public async Task <PaymentCreditSessionResponse> CreateCreditSession(PaymentCreditSession creditSession) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri); var response = await Post <PaymentCreditSessionResponse>(url, creditSession); return(response); }
/// <summary> /// Returns a specific payout based on a given payment reference. /// </summary> /// <param name="paymentReference">The reference id of the payout</param> /// <returns>A single <see cref="SettlementsPayout"/> object</returns> public async Task <SettlementsPayout> GetPayout(string paymentReference) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllerUri, paymentReference); var response = await Get <SettlementsPayout>(url); return(response); }
/// <summary> /// Generates a consumer token /// <a href="https://developers.klarna.com/api/#payments-api-generate-a-consumer-token"> /// https://developers.klarna.com/api/#payments-api-generate-a-consumer-token /// </a> /// </summary> /// <param name="authorizationToken">Authorization token from JS client</param> /// <param name="consumerTokenRequest">The <see cref="CustomerTokenCreationRequest"/> object</param> /// <returns><see cref="CustomerTokenCreationResponse"/></returns> public async Task <CustomerTokenCreationResponse> GenerateConsumerToken(string authorizationToken, CustomerTokenCreationRequest consumerTokenRequest) { var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.PaymentAuthorizations, $"{authorizationToken}/customer-token"); return(await Post <CustomerTokenCreationResponse>(url, consumerTokenRequest).ConfigureAwait(false)); }
/// <summary> /// A single settlement summed up in pdf format /// </summary> /// <param name="paymentReference">Required. The reference id of the payout</param> /// <returns>A <see cref="Stream"/> of content type application/pdf</returns> public Task <Stream> GetPdfPayoutSummary(string paymentReference) { var parameters = new NameValueCollection { { "payment_reference", paymentReference } }; var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.SettlementReports, "payout", parameters); return(GetStream(url)); }
/// <summary> /// Get CSV Payout Report /// More information about this CSV format is available at: /// <a href="https://developers.klarna.com/en/gb/kco-v3/settlement-files">https://developers.klarna.com/en/gb/kco-v3/settlement-files</a> /// </summary> /// <param name="paymentReference">The reference id of the payout</param> /// <returns>A <see cref="Stream"/> of content type text/csv</returns> public async Task <Stream> GetCsvPayoutReport(string paymentReference) { var nvm = new NameValueCollection { { "payment_reference", paymentReference } }; var url = ApiUrlHelper.GetApiUrlForController(ApiSession.ApiUrl, ApiControllers.SettlementReports, "payout-with-transactions", nvm); return(await GetStream(url)); }