github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/disputes/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 disputes
     5  
     6  import (
     7  	"github.com/Ingenico-ePayments/connect-sdk-go/communicator/communication"
     8  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/dispute"
     9  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/errors"
    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 disputes client. Thread-safe.
    15  type Client struct {
    16  	apiResource *apiresource.APIResource
    17  }
    18  
    19  // Get represents the resource /{merchantId}/disputes/{disputeId} - Get dispute
    20  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/disputes/get.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) Get(disputeID string, context communication.CallContext) (dispute.Response, error) {
    33  	var resultObject dispute.Response
    34  
    35  	pathContext := map[string]string{
    36  		"disputeId": disputeID,
    37  	}
    38  
    39  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/disputes/{disputeId}", pathContext)
    40  	if err != nil {
    41  		return resultObject, err
    42  	}
    43  
    44  	clientHeaders := c.apiResource.ClientHeaders()
    45  
    46  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
    47  	if getErr != nil {
    48  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
    49  		if isResponseError {
    50  			var errorObject interface{}
    51  
    52  			errorObject = &errors.ErrorResponse{}
    53  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
    54  			if err != nil {
    55  				return resultObject, err
    56  			}
    57  
    58  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
    59  			if createErr != nil {
    60  				return resultObject, createErr
    61  			}
    62  
    63  			return resultObject, err
    64  		}
    65  
    66  		return resultObject, getErr
    67  	}
    68  
    69  	return resultObject, nil
    70  }
    71  
    72  // Submit represents the resource /{merchantId}/disputes/{disputeId}/submit - Submit dispute
    73  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/disputes/submit.html
    74  //
    75  // Can return any of the following errors:
    76  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    77  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    78  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    79  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    80  // or there was a conflict (HTTP status code 404, 409 or 410)
    81  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    82  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    83  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    84  // * APIError if the Ingenico ePayments platform returned any other error
    85  func (c *Client) Submit(disputeID string, context communication.CallContext) (dispute.Response, error) {
    86  	var resultObject dispute.Response
    87  
    88  	pathContext := map[string]string{
    89  		"disputeId": disputeID,
    90  	}
    91  
    92  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/disputes/{disputeId}/submit", pathContext)
    93  	if err != nil {
    94  		return resultObject, err
    95  	}
    96  
    97  	clientHeaders := c.apiResource.ClientHeaders()
    98  
    99  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject)
   100  	if postErr != nil {
   101  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   102  		if isResponseError {
   103  			var errorObject interface{}
   104  
   105  			errorObject = &errors.ErrorResponse{}
   106  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   107  			if err != nil {
   108  				return resultObject, err
   109  			}
   110  
   111  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   112  			if createErr != nil {
   113  				return resultObject, createErr
   114  			}
   115  
   116  			return resultObject, err
   117  		}
   118  
   119  		return resultObject, postErr
   120  	}
   121  
   122  	return resultObject, nil
   123  }
   124  
   125  // Cancel represents the resource /{merchantId}/disputes/{disputeId}/cancel - Cancel dispute
   126  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/disputes/cancel.html
   127  //
   128  // Can return any of the following errors:
   129  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   130  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   131  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   132  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   133  // or there was a conflict (HTTP status code 404, 409 or 410)
   134  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   135  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   136  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   137  // * APIError if the Ingenico ePayments platform returned any other error
   138  func (c *Client) Cancel(disputeID string, context communication.CallContext) (dispute.Response, error) {
   139  	var resultObject dispute.Response
   140  
   141  	pathContext := map[string]string{
   142  		"disputeId": disputeID,
   143  	}
   144  
   145  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/disputes/{disputeId}/cancel", pathContext)
   146  	if err != nil {
   147  		return resultObject, err
   148  	}
   149  
   150  	clientHeaders := c.apiResource.ClientHeaders()
   151  
   152  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject)
   153  	if postErr != nil {
   154  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   155  		if isResponseError {
   156  			var errorObject interface{}
   157  
   158  			errorObject = &errors.ErrorResponse{}
   159  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   160  			if err != nil {
   161  				return resultObject, err
   162  			}
   163  
   164  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   165  			if createErr != nil {
   166  				return resultObject, createErr
   167  			}
   168  
   169  			return resultObject, err
   170  		}
   171  
   172  		return resultObject, postErr
   173  	}
   174  
   175  	return resultObject, nil
   176  }
   177  
   178  // UploadFile represents the resource /{merchantId}/disputes/{disputeId} - Upload File
   179  // Documentation can be found at https://epayments-api.developer-ingenico.com/fileserviceapi/v1/en_US/go/disputes/uploadFile.html
   180  //
   181  // Can return any of the following errors:
   182  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   183  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   184  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   185  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   186  // or there was a conflict (HTTP status code 404, 409 or 410)
   187  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   188  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   189  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   190  // * APIError if the Ingenico ePayments platform returned any other error
   191  func (c *Client) UploadFile(disputeID string, body UploadFileRequest, context communication.CallContext) (dispute.UploadDisputeFileResponse, error) {
   192  	var resultObject dispute.UploadDisputeFileResponse
   193  
   194  	pathContext := map[string]string{
   195  		"disputeId": disputeID,
   196  	}
   197  
   198  	uri, err := c.apiResource.InstantiateURIWithContext("/files/v1/{merchantId}/disputes/{disputeId}", pathContext)
   199  	if err != nil {
   200  		return resultObject, err
   201  	}
   202  
   203  	clientHeaders := c.apiResource.ClientHeaders()
   204  
   205  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, &body, context, &resultObject)
   206  	if postErr != nil {
   207  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   208  		if isResponseError {
   209  			var errorObject interface{}
   210  
   211  			errorObject = &errors.ErrorResponse{}
   212  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   213  			if err != nil {
   214  				return resultObject, err
   215  			}
   216  
   217  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   218  			if createErr != nil {
   219  				return resultObject, createErr
   220  			}
   221  
   222  			return resultObject, err
   223  		}
   224  
   225  		return resultObject, postErr
   226  	}
   227  
   228  	return resultObject, nil
   229  }
   230  
   231  // NewClient constructs a Disputes Client
   232  //
   233  // parent is the *apiresource.APIResource on top of which we want to build the new Disputes Client
   234  func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client {
   235  	apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext)
   236  
   237  	return &Client{apiResource}
   238  }