/// <summary> /// Add payment method to customer /// </summary> /// <param name="siteUserGuid">Siteuserguid</param> /// <param name="cardtoken">cardtoken from reepay</param> /// <returns>statuscode and carddata</returns> public ApiResponse <Card> AddPaymentMethodToCustomer(int siteUserGuid, string cardtoken) { var myClassname = MethodBase.GetCurrentMethod().Name; var config = this.GetDefaultApiConfiguration(); var api = new CustomerApi(config); for (var i = 0; i <= MaxNoOfRetries; i++) { try { var body = new CardToken(cardtoken); var res = api.AddCardJsonWithHttpInfo(siteUserGuid.ToString(), body); 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 <Card>(apiException.ErrorCode, null, null)); } catch (Exception) when(i < MaxNoOfRetries) { this._log.Debug($"{myClassname} retry attempt {i}"); } } return(new ApiResponse <Card>((int)HttpStatusCode.InternalServerError, null, null)); }