public GetAddesssApi(ApiKey apiKey, AdminKey adminKey, HttpClient httpClient = null) { _client = httpClient ?? new HttpClient { BaseAddress = _baseAddress }; _client.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); AdminKey = adminKey; ApiKey = apiKey; DomainWhitelist = new DomainWhitelistApi(AdminKey, this); IpAddressWhitelist = new IpAddressWhitelistApi(AdminKey, this); PrivateAddress = new PrivateAddressApi(AdminKey, this); Usage = new UsageApi(AdminKey, this); BillingAddress = new BillingAddressApi(AdminKey, this); Address = new AddressApi(ApiKey, this); FirstLimitReachedWebhook = new FirstLimitReachedWebhookApi(AdminKey, this); Subscription = new SubscriptionApi(adminKey, this); ApiKeyApi = new ApiKeyApi(adminKey, this); }
/// <summary> /// Reactivate cancelled subscription /// </summary> /// <param name="handle">subscription handle</param> /// <returns>statuscode and subscription</returns> public ApiResponse <Subscription> ReactivateCancelledSubscription(string handle) { var myClassname = MethodBase.GetCurrentMethod().Name; var config = this.GetDefaultApiConfiguration(); var api = new SubscriptionApi(config); for (var i = 0; i <= MaxNoOfRetries; i++) { try { var res = api.UncancelWithHttpInfo(handle); if (res.StatusCode != (int)HttpStatusCode.OK) { this._log.Error($"Unexpected answer from reepay. {myClassname} Errorcode {res.StatusCode}"); } return(res); } catch (ApiException apiException) { this._log.Error($"{myClassname} {apiException.ErrorCode} {apiException.ErrorContent}"); return(new ApiResponse <Subscription>(apiException.ErrorCode, null, null)); } catch (Exception) when(i < MaxNoOfRetries) { this._log.Debug($"{myClassname} retry attempt {i}"); } } return(new ApiResponse <Subscription>((int)HttpStatusCode.InternalServerError, null, null)); }
public async Task Change_a_subscription_plan() { // Arrange var subscriptionRequest = await SubscriptionApi.GetAsync <PaggedResponseMessage <SubscriptionModel> >().ConfigureAwait(false); var subscriptionItems = new List <SubscriptionSubitem> { new SubscriptionSubitem { description = "Mensalidade", price_cents = 65000, quantity = 1, recurrent = true } }; var request = new Request.SubscriptionRequestMessage(createdCustomer.id) { PlanId = createdPlan.identifier, IsCreditBased = false, Subitems = subscriptionItems }; var currentSubscription = await SubscriptionApi.CreateAsync(request).ConfigureAwait(false); var radomPlan = Guid.NewGuid().ToString(); var newdPlan = await PlanApi.CreateAsync($"{radomPlan}-12x", $"{radomPlan}-Plan", 1, "months", 0, "BRL", null, null, Constants.PaymentMethod.BANK_SLIP).ConfigureAwait(false); // Act var suspendendSubscription = await SubscriptionApi.ChangePlanAsync(currentSubscription.id, newdPlan.identifier).ConfigureAwait(false); // Assert suspendendSubscription.Should().NotBeSameAs(currentSubscription); }
/// <summary> /// Remove all payment methods from subscription /// </summary> /// <param name="subscriptionHandle">subscription handle</param> /// <returns>statuscode and PaymentMethods</returns> public ApiResponse <PaymentMethods> RemoveAllPaymentMethods(string subscriptionHandle) { var myClassname = MethodBase.GetCurrentMethod().Name; var config = this.GetDefaultApiConfiguration(); var api = new SubscriptionApi(config); for (var i = 0; i <= MaxNoOfRetries; i++) { try { var res = api.RemoveAllPaymentMethodsWithHttpInfo(subscriptionHandle); return(res); } catch (ApiException apiException) { this._log.Error($"{myClassname} {apiException.ErrorCode} {apiException.ErrorContent}"); return(new ApiResponse <PaymentMethods>(apiException.ErrorCode, null, null)); } catch (Exception) when(i < MaxNoOfRetries) { this._log.Debug($"{myClassname} retry attempt {i}"); } } return(new ApiResponse <PaymentMethods>((int)HttpStatusCode.InternalServerError, null, null)); }
public string AddSubscription(Subscription model) { var rst = new ReturnResult <bool>(); var bll = new SubscriptionBll(); if (model.Id == 0) { var api = new SubscriptionApi(); var apiRst = api.SubscriptionBusinessData((int)model.AppId, model.NotifyType, model.CallbackUrl); if (apiRst.Result) { model.SubscriptionId = apiRst.Data?.subscriptionId; model.NotifyType = apiRst.Data?.notifyType; model.CallbackUrl = apiRst.Data?.callbackUrl; rst = bll.Add(model); } else { rst.Message = apiRst.Message; } } else { rst = bll.Update(model); } return(JsonHelper.Instance.Serialize(rst)); }
/// <summary> /// Get subscribtions for customer /// </summary> /// <param name="siteUserGuid">siteuserguid</param> /// <param name="state">subscription state search creteria</param> /// <returns>statuscode and subscriptions</returns> public ApiResponse <SubscriptionSearch> GetSubscriptions(int siteUserGuid, Subscription.StateEnum?state) { var myClassname = MethodBase.GetCurrentMethod().Name; var config = this.GetDefaultApiConfiguration(); var api = new SubscriptionApi(config); for (var i = 0; i <= MaxNoOfRetries; i++) { try { var res = api.GetSubscriptionsWithHttpInfo(null, null, $"customer.handle:{siteUserGuid}"); if (res.StatusCode != (int)HttpStatusCode.OK) { this._log.Error($"Unexpected answer from reepay. {myClassname} Errorcode {res.StatusCode}"); } if (state != null) { for (int n = res.Data.Content.Count - 1; n >= 0; n--) { if (res.Data.Content[n].State != state.Value) { res.Data.Content.RemoveAt(n); } } } return(res); } catch (ApiException apiException) { this._log.Error($"{myClassname} {apiException.ErrorCode} {apiException.ErrorContent}"); return(new ApiResponse <SubscriptionSearch>(apiException.ErrorCode, null, null)); } catch (Exception) when(i < MaxNoOfRetries) { this._log.Debug($"{myClassname} retry attempt {i}"); } } return(new ApiResponse <SubscriptionSearch>((int)HttpStatusCode.InternalServerError, null, null)); }
public string DelSubscription(Subscription model) { var rst = new ReturnResult <bool>(); var api = new SubscriptionApi(); var delRst = api.DelSubscription(model.SubscriptionId, 1); if (delRst.Status == "NoContent") { rst.Result = true; rst.Message = "删除成功"; var bll = new SubscriptionBll(); var del = bll.Delete(model); } else { rst.Message = "删除失败"; } return(JsonHelper.Instance.Serialize(rst)); }
public async Task Suspended_a_subscription() { // Arrange var subscriptionRequest = await SubscriptionApi.GetAsync <PaggedResponseMessage <SubscriptionModel> >().ConfigureAwait(false); var subscriptionItems = new List <SubscriptionSubitem> { new SubscriptionSubitem { description = "Mensalidade", price_cents = 65000, quantity = 1, recurrent = true } }; var request = new Request.SubscriptionRequestMessage(createdCustomer.id) { PlanId = createdPlan.identifier, IsCreditBased = false, Subitems = subscriptionItems }; var subscription = await SubscriptionApi.CreateAsync(request).ConfigureAwait(false); // Act var suspendendSubscription = await SubscriptionApi.SuspendAsync(subscription.id).ConfigureAwait(false); // Assert Assert.That(suspendendSubscription.suspended, Is.True); }
/// <summary> /// Create customer and subscribtion /// </summary> /// <param name="subscription">subscrription data to create</param> /// <returns>subscription data</returns> public ApiResponse <Subscription> CreateSubscription(CreateSubscription subscription) { var myClassname = MethodBase.GetCurrentMethod().Name; var config = this.GetDefaultApiConfiguration(); var api = new SubscriptionApi(config); if (string.IsNullOrEmpty(subscription.CardToken)) { subscription.CardToken = null; } for (var i = 0; i <= MaxNoOfRetries; i++) { try { var res = api.CreateSubscriptionJsonWithHttpInfo(subscription); if (res.StatusCode != (int)HttpStatusCode.OK) { this._log.Error($"Unexpected answer from reepay. {myClassname} Errorcode {res.StatusCode}"); } return(res); } catch (ApiException apiException) { this._log.Error($"{myClassname} {apiException.ErrorCode} {apiException.ErrorContent}"); return(new ApiResponse <Subscription>(apiException.ErrorCode, null, null)); } catch (Exception) when(i < MaxNoOfRetries) { this._log.Debug($"{myClassname} retry attempt {i}"); } } return(new ApiResponse <Subscription>((int)HttpStatusCode.InternalServerError, null, null)); }
/// <summary> /// Create subscribtion for customer /// if no card id specfied then an email will be sent to user to add payment /// </summary> /// <param name="customerHandle">customer id</param> /// <param name="planHandle">plan id</param> /// <param name="cardToken">cardtoken</param> /// <param name="couponCodes">Coupon codes</param> /// <returns>subscription data</returns> public ApiResponse <Subscription> CreateSubscription(string customerHandle, string planHandle, string cardToken, List <string> couponCodes) { const bool generateSubshandle = true; var myClassname = MethodBase.GetCurrentMethod().Name; var config = this.GetDefaultApiConfiguration(); var api = new SubscriptionApi(config); var signupMethod = string.IsNullOrEmpty(cardToken) ? "email" : "card_token"; var subscription = new CreateSubscription(customerHandle, planHandle, null, null, this._reepayTestFlag, null, null, signupMethod, null, null, null, null, generateSubshandle, null, null, null, cardToken, null, null, couponCodes); for (var i = 0; i <= MaxNoOfRetries; i++) { try { var res = api.CreateSubscriptionJsonWithHttpInfo(subscription); if (res.StatusCode != (int)HttpStatusCode.OK) { this._log.Error($"Unexpected answer from reepay. {myClassname} Errorcode {res.StatusCode}"); } return(res); } catch (ApiException apiException) { this._log.Error($"{myClassname} {apiException.ErrorCode} {apiException.ErrorContent}"); return(new ApiResponse <Subscription>(apiException.ErrorCode, null, null)); } catch (Exception) when(i < MaxNoOfRetries) { this._log.Debug($"{myClassname} retry attempt {i}"); } } return(new ApiResponse <Subscription>((int)HttpStatusCode.InternalServerError, null, null)); }
public async Task FinalizeTests() { PlanApi.Dispose(); SubscriptionApi.Dispose(); CustomerApi.Dispose(); }
public void Init() { instance = new SubscriptionApi(); }