github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/payouts/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 payouts
     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/payout"
    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 payouts client. Thread-safe.
    15  type Client struct {
    16  	apiResource *apiresource.APIResource
    17  }
    18  
    19  // Create represents the resource /{merchantId}/payouts - Create payout
    20  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payouts/create.html
    21  //
    22  // Can return any of the following errors:
    23  // * DeclinedPayoutError if the Ingenico ePayments platform declined / rejected the payout. The payout result will be available from the exception.
    24  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    25  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    26  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    27  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    28  // or there was a conflict (HTTP status code 404, 409 or 410)
    29  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    30  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    31  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    32  // * APIError if the Ingenico ePayments platform returned any other error
    33  func (c *Client) Create(body payout.CreateRequest, context communication.CallContext) (payout.Response, error) {
    34  	var resultObject payout.Response
    35  
    36  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payouts", nil)
    37  	if err != nil {
    38  		return resultObject, err
    39  	}
    40  
    41  	clientHeaders := c.apiResource.ClientHeaders()
    42  
    43  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
    44  	if postErr != nil {
    45  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
    46  		if isResponseError {
    47  			var errorObject interface{}
    48  
    49  			errorObject = &payout.ErrorResponse{}
    50  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
    51  			if err != nil {
    52  				return resultObject, err
    53  			}
    54  
    55  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
    56  			if createErr != nil {
    57  				return resultObject, createErr
    58  			}
    59  
    60  			return resultObject, err
    61  		}
    62  
    63  		return resultObject, postErr
    64  	}
    65  
    66  	return resultObject, nil
    67  }
    68  
    69  // Find represents the resource /{merchantId}/payouts - Find payouts
    70  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payouts/find.html
    71  //
    72  // Can return any of the following errors:
    73  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    74  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    75  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    76  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    77  // or there was a conflict (HTTP status code 404, 409 or 410)
    78  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    79  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    80  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    81  // * APIError if the Ingenico ePayments platform returned any other error
    82  func (c *Client) Find(query FindParams, context communication.CallContext) (payout.FindResponse, error) {
    83  	var resultObject payout.FindResponse
    84  
    85  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payouts", nil)
    86  	if err != nil {
    87  		return resultObject, err
    88  	}
    89  
    90  	clientHeaders := c.apiResource.ClientHeaders()
    91  
    92  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject)
    93  	if getErr != nil {
    94  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
    95  		if isResponseError {
    96  			var errorObject interface{}
    97  
    98  			errorObject = &errors.ErrorResponse{}
    99  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   100  			if err != nil {
   101  				return resultObject, err
   102  			}
   103  
   104  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   105  			if createErr != nil {
   106  				return resultObject, createErr
   107  			}
   108  
   109  			return resultObject, err
   110  		}
   111  
   112  		return resultObject, getErr
   113  	}
   114  
   115  	return resultObject, nil
   116  }
   117  
   118  // Get represents the resource /{merchantId}/payouts/{payoutId} - Get payout
   119  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payouts/get.html
   120  //
   121  // Can return any of the following errors:
   122  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   123  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   124  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   125  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   126  // or there was a conflict (HTTP status code 404, 409 or 410)
   127  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   128  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   129  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   130  // * APIError if the Ingenico ePayments platform returned any other error
   131  func (c *Client) Get(payoutID string, context communication.CallContext) (payout.Response, error) {
   132  	var resultObject payout.Response
   133  
   134  	pathContext := map[string]string{
   135  		"payoutId": payoutID,
   136  	}
   137  
   138  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payouts/{payoutId}", pathContext)
   139  	if err != nil {
   140  		return resultObject, err
   141  	}
   142  
   143  	clientHeaders := c.apiResource.ClientHeaders()
   144  
   145  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
   146  	if getErr != nil {
   147  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
   148  		if isResponseError {
   149  			var errorObject interface{}
   150  
   151  			errorObject = &errors.ErrorResponse{}
   152  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   153  			if err != nil {
   154  				return resultObject, err
   155  			}
   156  
   157  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   158  			if createErr != nil {
   159  				return resultObject, createErr
   160  			}
   161  
   162  			return resultObject, err
   163  		}
   164  
   165  		return resultObject, getErr
   166  	}
   167  
   168  	return resultObject, nil
   169  }
   170  
   171  // Approve represents the resource /{merchantId}/payouts/{payoutId}/approve - Approve payout
   172  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payouts/approve.html
   173  //
   174  // Can return any of the following errors:
   175  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   176  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   177  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   178  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   179  // or there was a conflict (HTTP status code 404, 409 or 410)
   180  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   181  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   182  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   183  // * APIError if the Ingenico ePayments platform returned any other error
   184  func (c *Client) Approve(payoutID string, body payout.ApproveRequest, context communication.CallContext) (payout.Response, error) {
   185  	var resultObject payout.Response
   186  
   187  	pathContext := map[string]string{
   188  		"payoutId": payoutID,
   189  	}
   190  
   191  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payouts/{payoutId}/approve", pathContext)
   192  	if err != nil {
   193  		return resultObject, err
   194  	}
   195  
   196  	clientHeaders := c.apiResource.ClientHeaders()
   197  
   198  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   199  	if postErr != nil {
   200  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   201  		if isResponseError {
   202  			var errorObject interface{}
   203  
   204  			errorObject = &errors.ErrorResponse{}
   205  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   206  			if err != nil {
   207  				return resultObject, err
   208  			}
   209  
   210  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   211  			if createErr != nil {
   212  				return resultObject, createErr
   213  			}
   214  
   215  			return resultObject, err
   216  		}
   217  
   218  		return resultObject, postErr
   219  	}
   220  
   221  	return resultObject, nil
   222  }
   223  
   224  // Cancel represents the resource /{merchantId}/payouts/{payoutId}/cancel - Cancel payout
   225  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payouts/cancel.html
   226  //
   227  // Can return any of the following errors:
   228  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   229  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   230  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   231  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   232  // or there was a conflict (HTTP status code 404, 409 or 410)
   233  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   234  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   235  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   236  // * APIError if the Ingenico ePayments platform returned any other error
   237  func (c *Client) Cancel(payoutID string, context communication.CallContext) error {
   238  	pathContext := map[string]string{
   239  		"payoutId": payoutID,
   240  	}
   241  
   242  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payouts/{payoutId}/cancel", pathContext)
   243  	if err != nil {
   244  		return err
   245  	}
   246  
   247  	clientHeaders := c.apiResource.ClientHeaders()
   248  
   249  	var resultObject map[string]interface{}
   250  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject)
   251  	if postErr != nil {
   252  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   253  		if isResponseError {
   254  			var errorObject interface{}
   255  
   256  			errorObject = &errors.ErrorResponse{}
   257  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   258  			if err != nil {
   259  				return err
   260  			}
   261  
   262  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   263  			if createErr != nil {
   264  				return createErr
   265  			}
   266  
   267  			return err
   268  		}
   269  
   270  		return postErr
   271  	}
   272  
   273  	return nil
   274  }
   275  
   276  // Cancelapproval represents the resource /{merchantId}/payouts/{payoutId}/cancelapproval - Undo approve payout
   277  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payouts/cancelapproval.html
   278  //
   279  // Can return any of the following errors:
   280  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   281  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   282  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   283  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   284  // or there was a conflict (HTTP status code 404, 409 or 410)
   285  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   286  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   287  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   288  // * APIError if the Ingenico ePayments platform returned any other error
   289  func (c *Client) Cancelapproval(payoutID string, context communication.CallContext) error {
   290  	pathContext := map[string]string{
   291  		"payoutId": payoutID,
   292  	}
   293  
   294  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payouts/{payoutId}/cancelapproval", pathContext)
   295  	if err != nil {
   296  		return err
   297  	}
   298  
   299  	clientHeaders := c.apiResource.ClientHeaders()
   300  
   301  	var resultObject map[string]interface{}
   302  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject)
   303  	if postErr != nil {
   304  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   305  		if isResponseError {
   306  			var errorObject interface{}
   307  
   308  			errorObject = &errors.ErrorResponse{}
   309  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   310  			if err != nil {
   311  				return err
   312  			}
   313  
   314  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   315  			if createErr != nil {
   316  				return createErr
   317  			}
   318  
   319  			return err
   320  		}
   321  
   322  		return postErr
   323  	}
   324  
   325  	return nil
   326  }
   327  
   328  // NewClient constructs a Payouts Client
   329  //
   330  // parent is the *apiresource.APIResource on top of which we want to build the new Payouts Client
   331  func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client {
   332  	apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext)
   333  
   334  	return &Client{apiResource}
   335  }