Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        /// <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));
        }