github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/products/Client.go (about) 1 // This class was auto-generated from the API references found at 2 // https://epayments-api.developer-ingenico.com/ 3 4 package products 5 6 import ( 7 "strconv" 8 9 "github.com/Ingenico-ePayments/connect-sdk-go/communicator/communication" 10 "github.com/Ingenico-ePayments/connect-sdk-go/domain/errors" 11 "github.com/Ingenico-ePayments/connect-sdk-go/domain/product" 12 sdkErrors "github.com/Ingenico-ePayments/connect-sdk-go/errors" 13 "github.com/Ingenico-ePayments/connect-sdk-go/internal/apiresource" 14 ) 15 16 // Client represents a products client. Thread-safe. 17 type Client struct { 18 apiResource *apiresource.APIResource 19 } 20 21 // Find represents the resource /{merchantId}/products - Get payment products 22 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/products/find.html 23 // 24 // Can return any of the following errors: 25 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 26 // * AuthorizationError if the request was not allowed (HTTP status code 403) 27 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 28 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 29 // or there was a conflict (HTTP status code 404, 409 or 410) 30 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 31 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 32 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 33 // * APIError if the Ingenico ePayments platform returned any other error 34 func (c *Client) Find(query FindParams, context communication.CallContext) (product.PaymentProducts, error) { 35 var resultObject product.PaymentProducts 36 37 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/products", nil) 38 if err != nil { 39 return resultObject, err 40 } 41 42 clientHeaders := c.apiResource.ClientHeaders() 43 44 getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject) 45 if getErr != nil { 46 responseError, isResponseError := getErr.(*sdkErrors.ResponseError) 47 if isResponseError { 48 var errorObject interface{} 49 50 errorObject = &errors.ErrorResponse{} 51 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 52 if err != nil { 53 return resultObject, err 54 } 55 56 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 57 if createErr != nil { 58 return resultObject, createErr 59 } 60 61 return resultObject, err 62 } 63 64 return resultObject, getErr 65 } 66 67 return resultObject, nil 68 } 69 70 // Get represents the resource /{merchantId}/products/{paymentProductId} - Get payment product 71 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/products/get.html 72 // 73 // Can return any of the following errors: 74 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 75 // * AuthorizationError if the request was not allowed (HTTP status code 403) 76 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 77 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 78 // or there was a conflict (HTTP status code 404, 409 or 410) 79 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 80 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 81 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 82 // * APIError if the Ingenico ePayments platform returned any other error 83 func (c *Client) Get(paymentProductID int32, query GetParams, context communication.CallContext) (product.PaymentProductResponse, error) { 84 var resultObject product.PaymentProductResponse 85 86 pathContext := map[string]string{ 87 "paymentProductId": strconv.FormatInt(int64(paymentProductID), 10), 88 } 89 90 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/products/{paymentProductId}", pathContext) 91 if err != nil { 92 return resultObject, err 93 } 94 95 clientHeaders := c.apiResource.ClientHeaders() 96 97 getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject) 98 if getErr != nil { 99 responseError, isResponseError := getErr.(*sdkErrors.ResponseError) 100 if isResponseError { 101 var errorObject interface{} 102 103 errorObject = &errors.ErrorResponse{} 104 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 105 if err != nil { 106 return resultObject, err 107 } 108 109 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 110 if createErr != nil { 111 return resultObject, createErr 112 } 113 114 return resultObject, err 115 } 116 117 return resultObject, getErr 118 } 119 120 return resultObject, nil 121 } 122 123 // Directory represents the resource /{merchantId}/products/{paymentProductId}/directory - Get payment product directory 124 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/products/directory.html 125 // 126 // Can return any of the following errors: 127 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 128 // * AuthorizationError if the request was not allowed (HTTP status code 403) 129 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 130 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 131 // or there was a conflict (HTTP status code 404, 409 or 410) 132 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 133 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 134 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 135 // * APIError if the Ingenico ePayments platform returned any other error 136 func (c *Client) Directory(paymentProductID int32, query DirectoryParams, context communication.CallContext) (product.Directory, error) { 137 var resultObject product.Directory 138 139 pathContext := map[string]string{ 140 "paymentProductId": strconv.FormatInt(int64(paymentProductID), 10), 141 } 142 143 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/products/{paymentProductId}/directory", pathContext) 144 if err != nil { 145 return resultObject, err 146 } 147 148 clientHeaders := c.apiResource.ClientHeaders() 149 150 getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject) 151 if getErr != nil { 152 responseError, isResponseError := getErr.(*sdkErrors.ResponseError) 153 if isResponseError { 154 var errorObject interface{} 155 156 errorObject = &errors.ErrorResponse{} 157 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 158 if err != nil { 159 return resultObject, err 160 } 161 162 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 163 if createErr != nil { 164 return resultObject, createErr 165 } 166 167 return resultObject, err 168 } 169 170 return resultObject, getErr 171 } 172 173 return resultObject, nil 174 } 175 176 // CustomerDetails represents the resource /{merchantId}/products/{paymentProductId}/customerDetails - Get customer details 177 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/products/customerDetails.html 178 // 179 // Can return any of the following errors: 180 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 181 // * AuthorizationError if the request was not allowed (HTTP status code 403) 182 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 183 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 184 // or there was a conflict (HTTP status code 404, 409 or 410) 185 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 186 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 187 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 188 // * APIError if the Ingenico ePayments platform returned any other error 189 func (c *Client) CustomerDetails(paymentProductID int32, body product.GetCustomerDetailsRequest, context communication.CallContext) (product.GetCustomerDetailsResponse, error) { 190 var resultObject product.GetCustomerDetailsResponse 191 192 pathContext := map[string]string{ 193 "paymentProductId": strconv.FormatInt(int64(paymentProductID), 10), 194 } 195 196 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/products/{paymentProductId}/customerDetails", pathContext) 197 if err != nil { 198 return resultObject, err 199 } 200 201 clientHeaders := c.apiResource.ClientHeaders() 202 203 postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject) 204 if postErr != nil { 205 responseError, isResponseError := postErr.(*sdkErrors.ResponseError) 206 if isResponseError { 207 var errorObject interface{} 208 209 errorObject = &errors.ErrorResponse{} 210 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 211 if err != nil { 212 return resultObject, err 213 } 214 215 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 216 if createErr != nil { 217 return resultObject, createErr 218 } 219 220 return resultObject, err 221 } 222 223 return resultObject, postErr 224 } 225 226 return resultObject, nil 227 } 228 229 // DeviceFingerprint represents the resource /{merchantId}/products/{paymentProductId}/deviceFingerprint - Get device fingerprint 230 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/products/deviceFingerprint.html 231 // 232 // Can return any of the following errors: 233 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 234 // * AuthorizationError if the request was not allowed (HTTP status code 403) 235 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 236 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 237 // or there was a conflict (HTTP status code 404, 409 or 410) 238 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 239 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 240 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 241 // * APIError if the Ingenico ePayments platform returned any other error 242 func (c *Client) DeviceFingerprint(paymentProductID int32, body product.DeviceFingerprintRequest, context communication.CallContext) (product.DeviceFingerprintResponse, error) { 243 var resultObject product.DeviceFingerprintResponse 244 245 pathContext := map[string]string{ 246 "paymentProductId": strconv.FormatInt(int64(paymentProductID), 10), 247 } 248 249 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/products/{paymentProductId}/deviceFingerprint", pathContext) 250 if err != nil { 251 return resultObject, err 252 } 253 254 clientHeaders := c.apiResource.ClientHeaders() 255 256 postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject) 257 if postErr != nil { 258 responseError, isResponseError := postErr.(*sdkErrors.ResponseError) 259 if isResponseError { 260 var errorObject interface{} 261 262 errorObject = &errors.ErrorResponse{} 263 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 264 if err != nil { 265 return resultObject, err 266 } 267 268 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 269 if createErr != nil { 270 return resultObject, createErr 271 } 272 273 return resultObject, err 274 } 275 276 return resultObject, postErr 277 } 278 279 return resultObject, nil 280 } 281 282 // Networks represents the resource /{merchantId}/products/{paymentProductId}/networks - Get payment product networks 283 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/products/networks.html 284 // 285 // Can return any of the following errors: 286 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 287 // * AuthorizationError if the request was not allowed (HTTP status code 403) 288 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 289 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 290 // or there was a conflict (HTTP status code 404, 409 or 410) 291 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 292 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 293 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 294 // * APIError if the Ingenico ePayments platform returned any other error 295 func (c *Client) Networks(paymentProductID int32, query NetworksParams, context communication.CallContext) (product.PaymentProductNetworksResponse, error) { 296 var resultObject product.PaymentProductNetworksResponse 297 298 pathContext := map[string]string{ 299 "paymentProductId": strconv.FormatInt(int64(paymentProductID), 10), 300 } 301 302 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/products/{paymentProductId}/networks", pathContext) 303 if err != nil { 304 return resultObject, err 305 } 306 307 clientHeaders := c.apiResource.ClientHeaders() 308 309 getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject) 310 if getErr != nil { 311 responseError, isResponseError := getErr.(*sdkErrors.ResponseError) 312 if isResponseError { 313 var errorObject interface{} 314 315 errorObject = &errors.ErrorResponse{} 316 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 317 if err != nil { 318 return resultObject, err 319 } 320 321 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 322 if createErr != nil { 323 return resultObject, createErr 324 } 325 326 return resultObject, err 327 } 328 329 return resultObject, getErr 330 } 331 332 return resultObject, nil 333 } 334 335 // Sessions represents the resource /{merchantId}/products/{paymentProductId}/sessions - Create session for payment product 336 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/products/sessions.html 337 // 338 // Can return any of the following errors: 339 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 340 // * AuthorizationError if the request was not allowed (HTTP status code 403) 341 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 342 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 343 // or there was a conflict (HTTP status code 404, 409 or 410) 344 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 345 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 346 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 347 // * APIError if the Ingenico ePayments platform returned any other error 348 func (c *Client) Sessions(paymentProductID int32, body product.CreatePaymentProductSessionRequest, context communication.CallContext) (product.CreatePaymentProductSessionResponse, error) { 349 var resultObject product.CreatePaymentProductSessionResponse 350 351 pathContext := map[string]string{ 352 "paymentProductId": strconv.FormatInt(int64(paymentProductID), 10), 353 } 354 355 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/products/{paymentProductId}/sessions", pathContext) 356 if err != nil { 357 return resultObject, err 358 } 359 360 clientHeaders := c.apiResource.ClientHeaders() 361 362 postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject) 363 if postErr != nil { 364 responseError, isResponseError := postErr.(*sdkErrors.ResponseError) 365 if isResponseError { 366 var errorObject interface{} 367 368 errorObject = &errors.ErrorResponse{} 369 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 370 if err != nil { 371 return resultObject, err 372 } 373 374 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 375 if createErr != nil { 376 return resultObject, createErr 377 } 378 379 return resultObject, err 380 } 381 382 return resultObject, postErr 383 } 384 385 return resultObject, nil 386 } 387 388 // NewClient constructs a Products Client 389 // 390 // parent is the *apiresource.APIResource on top of which we want to build the new Products Client 391 func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client { 392 apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext) 393 394 return &Client{apiResource} 395 }