github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/productgroups/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 productgroups
     5  
     6  import (
     7  	"github.com/Ingenico-ePayments/connect-sdk-go/communicator/communication"
     8  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/errors"
     9  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/product"
    10  	sdkErrors "github.com/Ingenico-ePayments/connect-sdk-go/errors"
    11  	"github.com/Ingenico-ePayments/connect-sdk-go/internal/apiresource"
    12  )
    13  
    14  // Client represents a productgroups client. Thread-safe.
    15  type Client struct {
    16  	apiResource *apiresource.APIResource
    17  }
    18  
    19  // Find represents the resource /{merchantId}/productgroups - Get payment product groups
    20  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/productgroups/find.html
    21  //
    22  // Can return any of the following errors:
    23  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    24  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    25  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    26  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    27  // or there was a conflict (HTTP status code 404, 409 or 410)
    28  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    29  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    30  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    31  // * APIError if the Ingenico ePayments platform returned any other error
    32  func (c *Client) Find(query FindParams, context communication.CallContext) (product.PaymentProductGroups, error) {
    33  	var resultObject product.PaymentProductGroups
    34  
    35  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/productgroups", nil)
    36  	if err != nil {
    37  		return resultObject, err
    38  	}
    39  
    40  	clientHeaders := c.apiResource.ClientHeaders()
    41  
    42  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject)
    43  	if getErr != nil {
    44  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
    45  		if isResponseError {
    46  			var errorObject interface{}
    47  
    48  			errorObject = &errors.ErrorResponse{}
    49  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
    50  			if err != nil {
    51  				return resultObject, err
    52  			}
    53  
    54  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
    55  			if createErr != nil {
    56  				return resultObject, createErr
    57  			}
    58  
    59  			return resultObject, err
    60  		}
    61  
    62  		return resultObject, getErr
    63  	}
    64  
    65  	return resultObject, nil
    66  }
    67  
    68  // Get represents the resource /{merchantId}/productgroups/{paymentProductGroupId} - Get payment product group
    69  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/productgroups/get.html
    70  //
    71  // Can return any of the following errors:
    72  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    73  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    74  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    75  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    76  // or there was a conflict (HTTP status code 404, 409 or 410)
    77  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    78  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    79  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    80  // * APIError if the Ingenico ePayments platform returned any other error
    81  func (c *Client) Get(paymentProductGroupID string, query GetParams, context communication.CallContext) (product.PaymentProductGroupResponse, error) {
    82  	var resultObject product.PaymentProductGroupResponse
    83  
    84  	pathContext := map[string]string{
    85  		"paymentProductGroupId": paymentProductGroupID,
    86  	}
    87  
    88  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/productgroups/{paymentProductGroupId}", pathContext)
    89  	if err != nil {
    90  		return resultObject, err
    91  	}
    92  
    93  	clientHeaders := c.apiResource.ClientHeaders()
    94  
    95  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject)
    96  	if getErr != nil {
    97  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
    98  		if isResponseError {
    99  			var errorObject interface{}
   100  
   101  			errorObject = &errors.ErrorResponse{}
   102  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   103  			if err != nil {
   104  				return resultObject, err
   105  			}
   106  
   107  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   108  			if createErr != nil {
   109  				return resultObject, createErr
   110  			}
   111  
   112  			return resultObject, err
   113  		}
   114  
   115  		return resultObject, getErr
   116  	}
   117  
   118  	return resultObject, nil
   119  }
   120  
   121  // DeviceFingerprint represents the resource /{merchantId}/productgroups/{paymentProductGroupId}/deviceFingerprint - Get device fingerprint
   122  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/productgroups/deviceFingerprint.html
   123  //
   124  // Can return any of the following errors:
   125  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   126  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   127  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   128  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   129  // or there was a conflict (HTTP status code 404, 409 or 410)
   130  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   131  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   132  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   133  // * APIError if the Ingenico ePayments platform returned any other error
   134  func (c *Client) DeviceFingerprint(paymentProductGroupID string, body product.DeviceFingerprintRequest, context communication.CallContext) (product.DeviceFingerprintResponse, error) {
   135  	var resultObject product.DeviceFingerprintResponse
   136  
   137  	pathContext := map[string]string{
   138  		"paymentProductGroupId": paymentProductGroupID,
   139  	}
   140  
   141  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/productgroups/{paymentProductGroupId}/deviceFingerprint", pathContext)
   142  	if err != nil {
   143  		return resultObject, err
   144  	}
   145  
   146  	clientHeaders := c.apiResource.ClientHeaders()
   147  
   148  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   149  	if postErr != nil {
   150  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   151  		if isResponseError {
   152  			var errorObject interface{}
   153  
   154  			errorObject = &errors.ErrorResponse{}
   155  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   156  			if err != nil {
   157  				return resultObject, err
   158  			}
   159  
   160  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   161  			if createErr != nil {
   162  				return resultObject, createErr
   163  			}
   164  
   165  			return resultObject, err
   166  		}
   167  
   168  		return resultObject, postErr
   169  	}
   170  
   171  	return resultObject, nil
   172  }
   173  
   174  // NewClient constructs a Productgroups Client
   175  //
   176  // parent is the *apiresource.APIResource on top of which we want to build the new Productgroups Client
   177  func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client {
   178  	apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext)
   179  
   180  	return &Client{apiResource}
   181  }