@@ -2839,3 +2839,257 @@ func (s *Customers) GetStateExternal(ctx context.Context, externalID string, opt
28392839 return res , nil
28402840
28412841}
2842+
2843+ // GetBalance - Get Customer Balance
2844+ // Get customer balance information.
2845+ //
2846+ // **Scopes**: `customers:read` `customers:write`
2847+ func (s * Customers ) GetBalance (ctx context.Context , id string , opts ... operations.Option ) (* operations.CustomersGetBalanceResponse , error ) {
2848+ request := operations.CustomersGetBalanceRequest {
2849+ ID : id ,
2850+ }
2851+
2852+ o := operations.Options {}
2853+ supportedOptions := []string {
2854+ operations .SupportedOptionRetries ,
2855+ operations .SupportedOptionTimeout ,
2856+ }
2857+
2858+ for _ , opt := range opts {
2859+ if err := opt (& o , supportedOptions ... ); err != nil {
2860+ return nil , fmt .Errorf ("error applying option: %w" , err )
2861+ }
2862+ }
2863+
2864+ var baseURL string
2865+ if o .ServerURL == nil {
2866+ baseURL = utils .ReplaceParameters (s .sdkConfiguration .GetServerDetails ())
2867+ } else {
2868+ baseURL = * o .ServerURL
2869+ }
2870+ opURL , err := utils .GenerateURL (ctx , baseURL , "/v1/customers/{id}/balance" , request , nil )
2871+ if err != nil {
2872+ return nil , fmt .Errorf ("error generating URL: %w" , err )
2873+ }
2874+
2875+ hookCtx := hooks.HookContext {
2876+ SDK : s .rootSDK ,
2877+ SDKConfiguration : s .sdkConfiguration ,
2878+ BaseURL : baseURL ,
2879+ Context : ctx ,
2880+ OperationID : "customers:get_balance" ,
2881+ OAuth2Scopes : []string {},
2882+ SecuritySource : s .sdkConfiguration .Security ,
2883+ }
2884+
2885+ timeout := o .Timeout
2886+ if timeout == nil {
2887+ timeout = s .sdkConfiguration .Timeout
2888+ }
2889+
2890+ if timeout != nil {
2891+ var cancel context.CancelFunc
2892+ ctx , cancel = context .WithTimeout (ctx , * timeout )
2893+ defer cancel ()
2894+ }
2895+
2896+ req , err := http .NewRequestWithContext (ctx , "GET" , opURL , nil )
2897+ if err != nil {
2898+ return nil , fmt .Errorf ("error creating request: %w" , err )
2899+ }
2900+ req .Header .Set ("Accept" , "application/json" )
2901+ req .Header .Set ("User-Agent" , s .sdkConfiguration .UserAgent )
2902+
2903+ if err := utils .PopulateSecurity (ctx , req , s .sdkConfiguration .Security ); err != nil {
2904+ return nil , err
2905+ }
2906+
2907+ for k , v := range o .SetHeaders {
2908+ req .Header .Set (k , v )
2909+ }
2910+
2911+ globalRetryConfig := s .sdkConfiguration .RetryConfig
2912+ retryConfig := o .Retries
2913+ if retryConfig == nil {
2914+ if globalRetryConfig != nil {
2915+ retryConfig = globalRetryConfig
2916+ }
2917+ }
2918+
2919+ var httpRes * http.Response
2920+ if retryConfig != nil {
2921+ httpRes , err = utils .Retry (ctx , utils.Retries {
2922+ Config : retryConfig ,
2923+ StatusCodes : []string {
2924+ "429" ,
2925+ "500" ,
2926+ "502" ,
2927+ "503" ,
2928+ "504" ,
2929+ },
2930+ }, func () (* http.Response , error ) {
2931+ if req .Body != nil && req .Body != http .NoBody && req .GetBody != nil {
2932+ copyBody , err := req .GetBody ()
2933+
2934+ if err != nil {
2935+ return nil , err
2936+ }
2937+
2938+ req .Body = copyBody
2939+ }
2940+
2941+ req , err = s .hooks .BeforeRequest (hooks.BeforeRequestContext {HookContext : hookCtx }, req )
2942+ if err != nil {
2943+ if retry .IsPermanentError (err ) || retry .IsTemporaryError (err ) {
2944+ return nil , err
2945+ }
2946+
2947+ return nil , retry .Permanent (err )
2948+ }
2949+
2950+ httpRes , err := s .sdkConfiguration .Client .Do (req )
2951+ if err != nil || httpRes == nil {
2952+ if err != nil {
2953+ err = fmt .Errorf ("error sending request: %w" , err )
2954+ } else {
2955+ err = fmt .Errorf ("error sending request: no response" )
2956+ }
2957+
2958+ _ , err = s .hooks .AfterError (hooks.AfterErrorContext {HookContext : hookCtx }, nil , err )
2959+ }
2960+ return httpRes , err
2961+ })
2962+
2963+ if err != nil {
2964+ return nil , err
2965+ } else {
2966+ httpRes , err = s .hooks .AfterSuccess (hooks.AfterSuccessContext {HookContext : hookCtx }, httpRes )
2967+ if err != nil {
2968+ return nil , err
2969+ }
2970+ }
2971+ } else {
2972+ req , err = s .hooks .BeforeRequest (hooks.BeforeRequestContext {HookContext : hookCtx }, req )
2973+ if err != nil {
2974+ return nil , err
2975+ }
2976+
2977+ httpRes , err = s .sdkConfiguration .Client .Do (req )
2978+ if err != nil || httpRes == nil {
2979+ if err != nil {
2980+ err = fmt .Errorf ("error sending request: %w" , err )
2981+ } else {
2982+ err = fmt .Errorf ("error sending request: no response" )
2983+ }
2984+
2985+ _ , err = s .hooks .AfterError (hooks.AfterErrorContext {HookContext : hookCtx }, nil , err )
2986+ return nil , err
2987+ } else if utils .MatchStatusCodes ([]string {"404" , "422" , "4XX" , "5XX" }, httpRes .StatusCode ) {
2988+ _httpRes , err := s .hooks .AfterError (hooks.AfterErrorContext {HookContext : hookCtx }, httpRes , nil )
2989+ if err != nil {
2990+ return nil , err
2991+ } else if _httpRes != nil {
2992+ httpRes = _httpRes
2993+ }
2994+ } else {
2995+ httpRes , err = s .hooks .AfterSuccess (hooks.AfterSuccessContext {HookContext : hookCtx }, httpRes )
2996+ if err != nil {
2997+ return nil , err
2998+ }
2999+ }
3000+ }
3001+
3002+ res := & operations.CustomersGetBalanceResponse {
3003+ HTTPMeta : components.HTTPMetadata {
3004+ Request : req ,
3005+ Response : httpRes ,
3006+ },
3007+ }
3008+
3009+ switch {
3010+ case httpRes .StatusCode == 200 :
3011+ switch {
3012+ case utils .MatchContentType (httpRes .Header .Get ("Content-Type" ), `application/json` ):
3013+ rawBody , err := utils .ConsumeRawBody (httpRes )
3014+ if err != nil {
3015+ return nil , err
3016+ }
3017+
3018+ var out components.CustomerBalance
3019+ if err := utils .UnmarshalJsonFromResponseBody (bytes .NewBuffer (rawBody ), & out , "" ); err != nil {
3020+ return nil , err
3021+ }
3022+
3023+ res .CustomerBalance = & out
3024+ default :
3025+ rawBody , err := utils .ConsumeRawBody (httpRes )
3026+ if err != nil {
3027+ return nil , err
3028+ }
3029+ return nil , apierrors .NewAPIError (fmt .Sprintf ("unknown content-type received: %s" , httpRes .Header .Get ("Content-Type" )), httpRes .StatusCode , string (rawBody ), httpRes )
3030+ }
3031+ case httpRes .StatusCode == 404 :
3032+ switch {
3033+ case utils .MatchContentType (httpRes .Header .Get ("Content-Type" ), `application/json` ):
3034+ rawBody , err := utils .ConsumeRawBody (httpRes )
3035+ if err != nil {
3036+ return nil , err
3037+ }
3038+
3039+ var out apierrors.ResourceNotFound
3040+ if err := utils .UnmarshalJsonFromResponseBody (bytes .NewBuffer (rawBody ), & out , "" ); err != nil {
3041+ return nil , err
3042+ }
3043+
3044+ return nil , & out
3045+ default :
3046+ rawBody , err := utils .ConsumeRawBody (httpRes )
3047+ if err != nil {
3048+ return nil , err
3049+ }
3050+ return nil , apierrors .NewAPIError (fmt .Sprintf ("unknown content-type received: %s" , httpRes .Header .Get ("Content-Type" )), httpRes .StatusCode , string (rawBody ), httpRes )
3051+ }
3052+ case httpRes .StatusCode == 422 :
3053+ switch {
3054+ case utils .MatchContentType (httpRes .Header .Get ("Content-Type" ), `application/json` ):
3055+ rawBody , err := utils .ConsumeRawBody (httpRes )
3056+ if err != nil {
3057+ return nil , err
3058+ }
3059+
3060+ var out apierrors.HTTPValidationError
3061+ if err := utils .UnmarshalJsonFromResponseBody (bytes .NewBuffer (rawBody ), & out , "" ); err != nil {
3062+ return nil , err
3063+ }
3064+
3065+ return nil , & out
3066+ default :
3067+ rawBody , err := utils .ConsumeRawBody (httpRes )
3068+ if err != nil {
3069+ return nil , err
3070+ }
3071+ return nil , apierrors .NewAPIError (fmt .Sprintf ("unknown content-type received: %s" , httpRes .Header .Get ("Content-Type" )), httpRes .StatusCode , string (rawBody ), httpRes )
3072+ }
3073+ case httpRes .StatusCode >= 400 && httpRes .StatusCode < 500 :
3074+ rawBody , err := utils .ConsumeRawBody (httpRes )
3075+ if err != nil {
3076+ return nil , err
3077+ }
3078+ return nil , apierrors .NewAPIError ("API error occurred" , httpRes .StatusCode , string (rawBody ), httpRes )
3079+ case httpRes .StatusCode >= 500 && httpRes .StatusCode < 600 :
3080+ rawBody , err := utils .ConsumeRawBody (httpRes )
3081+ if err != nil {
3082+ return nil , err
3083+ }
3084+ return nil , apierrors .NewAPIError ("API error occurred" , httpRes .StatusCode , string (rawBody ), httpRes )
3085+ default :
3086+ rawBody , err := utils .ConsumeRawBody (httpRes )
3087+ if err != nil {
3088+ return nil , err
3089+ }
3090+ return nil , apierrors .NewAPIError ("unknown status code returned" , httpRes .StatusCode , string (rawBody ), httpRes )
3091+ }
3092+
3093+ return res , nil
3094+
3095+ }
0 commit comments