github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/payments/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 payments
     5  
     6  import (
     7  	"github.com/Ingenico-ePayments/connect-sdk-go/communicator/communication"
     8  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/capture"
     9  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/dispute"
    10  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/errors"
    11  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/payment"
    12  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/refund"
    13  	"github.com/Ingenico-ePayments/connect-sdk-go/domain/token"
    14  	sdkErrors "github.com/Ingenico-ePayments/connect-sdk-go/errors"
    15  	"github.com/Ingenico-ePayments/connect-sdk-go/internal/apiresource"
    16  )
    17  
    18  // Client represents a payments client. Thread-safe.
    19  type Client struct {
    20  	apiResource *apiresource.APIResource
    21  }
    22  
    23  // Create represents the resource /{merchantId}/payments - Create payment
    24  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/create.html
    25  //
    26  // Can return any of the following errors:
    27  // * DeclinedPaymentError if the Ingenico ePayments platform declined / rejected the payment. The payment result will be available from the exception.
    28  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    29  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    30  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    31  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    32  // or there was a conflict (HTTP status code 404, 409 or 410)
    33  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    34  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    35  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    36  // * APIError if the Ingenico ePayments platform returned any other error
    37  func (c *Client) Create(body payment.CreateRequest, context communication.CallContext) (payment.CreateResponse, error) {
    38  	var resultObject payment.CreateResponse
    39  
    40  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments", nil)
    41  	if err != nil {
    42  		return resultObject, err
    43  	}
    44  
    45  	clientHeaders := c.apiResource.ClientHeaders()
    46  
    47  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
    48  	if postErr != nil {
    49  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
    50  		if isResponseError {
    51  			var errorObject interface{}
    52  
    53  			errorObject = &payment.ErrorResponse{}
    54  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
    55  			if err != nil {
    56  				return resultObject, err
    57  			}
    58  
    59  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
    60  			if createErr != nil {
    61  				return resultObject, createErr
    62  			}
    63  
    64  			return resultObject, err
    65  		}
    66  
    67  		return resultObject, postErr
    68  	}
    69  
    70  	return resultObject, nil
    71  }
    72  
    73  // Find represents the resource /{merchantId}/payments - Find payments
    74  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/find.html
    75  //
    76  // Can return any of the following errors:
    77  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
    78  // * AuthorizationError if the request was not allowed (HTTP status code 403)
    79  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
    80  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
    81  // or there was a conflict (HTTP status code 404, 409 or 410)
    82  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
    83  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
    84  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
    85  // * APIError if the Ingenico ePayments platform returned any other error
    86  func (c *Client) Find(query FindParams, context communication.CallContext) (payment.FindResponse, error) {
    87  	var resultObject payment.FindResponse
    88  
    89  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments", nil)
    90  	if err != nil {
    91  		return resultObject, err
    92  	}
    93  
    94  	clientHeaders := c.apiResource.ClientHeaders()
    95  
    96  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, &query, context, &resultObject)
    97  	if getErr != nil {
    98  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
    99  		if isResponseError {
   100  			var errorObject interface{}
   101  
   102  			errorObject = &errors.ErrorResponse{}
   103  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   104  			if err != nil {
   105  				return resultObject, err
   106  			}
   107  
   108  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   109  			if createErr != nil {
   110  				return resultObject, createErr
   111  			}
   112  
   113  			return resultObject, err
   114  		}
   115  
   116  		return resultObject, getErr
   117  	}
   118  
   119  	return resultObject, nil
   120  }
   121  
   122  // Get represents the resource /{merchantId}/payments/{paymentId} - Get payment
   123  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/get.html
   124  //
   125  // Can return any of the following errors:
   126  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   127  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   128  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   129  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   130  // or there was a conflict (HTTP status code 404, 409 or 410)
   131  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   132  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   133  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   134  // * APIError if the Ingenico ePayments platform returned any other error
   135  func (c *Client) Get(paymentID string, context communication.CallContext) (payment.Response, error) {
   136  	var resultObject payment.Response
   137  
   138  	pathContext := map[string]string{
   139  		"paymentId": paymentID,
   140  	}
   141  
   142  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}", pathContext)
   143  	if err != nil {
   144  		return resultObject, err
   145  	}
   146  
   147  	clientHeaders := c.apiResource.ClientHeaders()
   148  
   149  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
   150  	if getErr != nil {
   151  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
   152  		if isResponseError {
   153  			var errorObject interface{}
   154  
   155  			errorObject = &errors.ErrorResponse{}
   156  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   157  			if err != nil {
   158  				return resultObject, err
   159  			}
   160  
   161  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   162  			if createErr != nil {
   163  				return resultObject, createErr
   164  			}
   165  
   166  			return resultObject, err
   167  		}
   168  
   169  		return resultObject, getErr
   170  	}
   171  
   172  	return resultObject, nil
   173  }
   174  
   175  // Complete represents the resource /{merchantId}/payments/{paymentId}/complete - Complete payment
   176  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/complete.html
   177  //
   178  // Can return any of the following errors:
   179  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   180  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   181  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   182  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   183  // or there was a conflict (HTTP status code 404, 409 or 410)
   184  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   185  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   186  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   187  // * APIError if the Ingenico ePayments platform returned any other error
   188  func (c *Client) Complete(paymentID string, body payment.CompletePaymentRequest, context communication.CallContext) (payment.CompletePaymentResponse, error) {
   189  	var resultObject payment.CompletePaymentResponse
   190  
   191  	pathContext := map[string]string{
   192  		"paymentId": paymentID,
   193  	}
   194  
   195  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/complete", pathContext)
   196  	if err != nil {
   197  		return resultObject, err
   198  	}
   199  
   200  	clientHeaders := c.apiResource.ClientHeaders()
   201  
   202  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   203  	if postErr != nil {
   204  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   205  		if isResponseError {
   206  			var errorObject interface{}
   207  
   208  			errorObject = &errors.ErrorResponse{}
   209  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   210  			if err != nil {
   211  				return resultObject, err
   212  			}
   213  
   214  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   215  			if createErr != nil {
   216  				return resultObject, createErr
   217  			}
   218  
   219  			return resultObject, err
   220  		}
   221  
   222  		return resultObject, postErr
   223  	}
   224  
   225  	return resultObject, nil
   226  }
   227  
   228  // ThirdPartyStatus represents the resource /{merchantId}/payments/{paymentId}/thirdpartystatus - Third party status poll
   229  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/thirdPartyStatus.html
   230  //
   231  // Can return any of the following errors:
   232  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   233  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   234  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   235  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   236  // or there was a conflict (HTTP status code 404, 409 or 410)
   237  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   238  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   239  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   240  // * APIError if the Ingenico ePayments platform returned any other error
   241  func (c *Client) ThirdPartyStatus(paymentID string, context communication.CallContext) (payment.ThirdPartyStatusResponse, error) {
   242  	var resultObject payment.ThirdPartyStatusResponse
   243  
   244  	pathContext := map[string]string{
   245  		"paymentId": paymentID,
   246  	}
   247  
   248  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/thirdpartystatus", pathContext)
   249  	if err != nil {
   250  		return resultObject, err
   251  	}
   252  
   253  	clientHeaders := c.apiResource.ClientHeaders()
   254  
   255  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
   256  	if getErr != nil {
   257  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
   258  		if isResponseError {
   259  			var errorObject interface{}
   260  
   261  			errorObject = &errors.ErrorResponse{}
   262  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   263  			if err != nil {
   264  				return resultObject, err
   265  			}
   266  
   267  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   268  			if createErr != nil {
   269  				return resultObject, createErr
   270  			}
   271  
   272  			return resultObject, err
   273  		}
   274  
   275  		return resultObject, getErr
   276  	}
   277  
   278  	return resultObject, nil
   279  }
   280  
   281  // Tokenize represents the resource /{merchantId}/payments/{paymentId}/tokenize - Create a token from payment
   282  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/tokenize.html
   283  //
   284  // Can return any of the following errors:
   285  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   286  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   287  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   288  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   289  // or there was a conflict (HTTP status code 404, 409 or 410)
   290  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   291  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   292  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   293  // * APIError if the Ingenico ePayments platform returned any other error
   294  func (c *Client) Tokenize(paymentID string, body payment.TokenizeRequest, context communication.CallContext) (token.CreateResponse, error) {
   295  	var resultObject token.CreateResponse
   296  
   297  	pathContext := map[string]string{
   298  		"paymentId": paymentID,
   299  	}
   300  
   301  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/tokenize", pathContext)
   302  	if err != nil {
   303  		return resultObject, err
   304  	}
   305  
   306  	clientHeaders := c.apiResource.ClientHeaders()
   307  
   308  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   309  	if postErr != nil {
   310  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   311  		if isResponseError {
   312  			var errorObject interface{}
   313  
   314  			errorObject = &errors.ErrorResponse{}
   315  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   316  			if err != nil {
   317  				return resultObject, err
   318  			}
   319  
   320  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   321  			if createErr != nil {
   322  				return resultObject, createErr
   323  			}
   324  
   325  			return resultObject, err
   326  		}
   327  
   328  		return resultObject, postErr
   329  	}
   330  
   331  	return resultObject, nil
   332  }
   333  
   334  // Processchallenged represents the resource /{merchantId}/payments/{paymentId}/processchallenged - Approves challenged payment
   335  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/processchallenged.html
   336  //
   337  // Can return any of the following errors:
   338  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   339  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   340  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   341  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   342  // or there was a conflict (HTTP status code 404, 409 or 410)
   343  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   344  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   345  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   346  // * APIError if the Ingenico ePayments platform returned any other error
   347  func (c *Client) Processchallenged(paymentID string, context communication.CallContext) (payment.Response, error) {
   348  	var resultObject payment.Response
   349  
   350  	pathContext := map[string]string{
   351  		"paymentId": paymentID,
   352  	}
   353  
   354  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/processchallenged", pathContext)
   355  	if err != nil {
   356  		return resultObject, err
   357  	}
   358  
   359  	clientHeaders := c.apiResource.ClientHeaders()
   360  
   361  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject)
   362  	if postErr != nil {
   363  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   364  		if isResponseError {
   365  			var errorObject interface{}
   366  
   367  			errorObject = &errors.ErrorResponse{}
   368  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   369  			if err != nil {
   370  				return resultObject, err
   371  			}
   372  
   373  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   374  			if createErr != nil {
   375  				return resultObject, createErr
   376  			}
   377  
   378  			return resultObject, err
   379  		}
   380  
   381  		return resultObject, postErr
   382  	}
   383  
   384  	return resultObject, nil
   385  }
   386  
   387  // Approve represents the resource /{merchantId}/payments/{paymentId}/approve - Approve payment
   388  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/approve.html
   389  //
   390  // Can return any of the following errors:
   391  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   392  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   393  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   394  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   395  // or there was a conflict (HTTP status code 404, 409 or 410)
   396  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   397  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   398  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   399  // * APIError if the Ingenico ePayments platform returned any other error
   400  func (c *Client) Approve(paymentID string, body payment.ApproveRequest, context communication.CallContext) (payment.ApprovalResponse, error) {
   401  	var resultObject payment.ApprovalResponse
   402  
   403  	pathContext := map[string]string{
   404  		"paymentId": paymentID,
   405  	}
   406  
   407  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/approve", pathContext)
   408  	if err != nil {
   409  		return resultObject, err
   410  	}
   411  
   412  	clientHeaders := c.apiResource.ClientHeaders()
   413  
   414  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   415  	if postErr != nil {
   416  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   417  		if isResponseError {
   418  			var errorObject interface{}
   419  
   420  			errorObject = &errors.ErrorResponse{}
   421  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   422  			if err != nil {
   423  				return resultObject, err
   424  			}
   425  
   426  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   427  			if createErr != nil {
   428  				return resultObject, createErr
   429  			}
   430  
   431  			return resultObject, err
   432  		}
   433  
   434  		return resultObject, postErr
   435  	}
   436  
   437  	return resultObject, nil
   438  }
   439  
   440  // Capture represents the resource /{merchantId}/payments/{paymentId}/capture - Capture payment
   441  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/capture.html
   442  //
   443  // Can return any of the following errors:
   444  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   445  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   446  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   447  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   448  // or there was a conflict (HTTP status code 404, 409 or 410)
   449  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   450  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   451  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   452  // * APIError if the Ingenico ePayments platform returned any other error
   453  func (c *Client) Capture(paymentID string, body payment.CapturePaymentRequest, context communication.CallContext) (capture.Response, error) {
   454  	var resultObject capture.Response
   455  
   456  	pathContext := map[string]string{
   457  		"paymentId": paymentID,
   458  	}
   459  
   460  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/capture", pathContext)
   461  	if err != nil {
   462  		return resultObject, err
   463  	}
   464  
   465  	clientHeaders := c.apiResource.ClientHeaders()
   466  
   467  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   468  	if postErr != nil {
   469  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   470  		if isResponseError {
   471  			var errorObject interface{}
   472  
   473  			errorObject = &errors.ErrorResponse{}
   474  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   475  			if err != nil {
   476  				return resultObject, err
   477  			}
   478  
   479  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   480  			if createErr != nil {
   481  				return resultObject, createErr
   482  			}
   483  
   484  			return resultObject, err
   485  		}
   486  
   487  		return resultObject, postErr
   488  	}
   489  
   490  	return resultObject, nil
   491  }
   492  
   493  // Cancelapproval represents the resource /{merchantId}/payments/{paymentId}/cancelapproval - Undo capture payment
   494  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/cancelapproval.html
   495  //
   496  // Can return any of the following errors:
   497  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   498  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   499  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   500  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   501  // or there was a conflict (HTTP status code 404, 409 or 410)
   502  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   503  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   504  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   505  // * APIError if the Ingenico ePayments platform returned any other error
   506  func (c *Client) Cancelapproval(paymentID string, context communication.CallContext) (payment.CancelApprovalPaymentResponse, error) {
   507  	var resultObject payment.CancelApprovalPaymentResponse
   508  
   509  	pathContext := map[string]string{
   510  		"paymentId": paymentID,
   511  	}
   512  
   513  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/cancelapproval", pathContext)
   514  	if err != nil {
   515  		return resultObject, err
   516  	}
   517  
   518  	clientHeaders := c.apiResource.ClientHeaders()
   519  
   520  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject)
   521  	if postErr != nil {
   522  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   523  		if isResponseError {
   524  			var errorObject interface{}
   525  
   526  			errorObject = &errors.ErrorResponse{}
   527  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   528  			if err != nil {
   529  				return resultObject, err
   530  			}
   531  
   532  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   533  			if createErr != nil {
   534  				return resultObject, createErr
   535  			}
   536  
   537  			return resultObject, err
   538  		}
   539  
   540  		return resultObject, postErr
   541  	}
   542  
   543  	return resultObject, nil
   544  }
   545  
   546  // Captures represents the resource /{merchantId}/payments/{paymentId}/captures - Get captures of payment
   547  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/captures.html
   548  //
   549  // Can return any of the following errors:
   550  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   551  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   552  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   553  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   554  // or there was a conflict (HTTP status code 404, 409 or 410)
   555  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   556  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   557  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   558  // * APIError if the Ingenico ePayments platform returned any other error
   559  func (c *Client) Captures(paymentID string, context communication.CallContext) (capture.CapturesResponse, error) {
   560  	var resultObject capture.CapturesResponse
   561  
   562  	pathContext := map[string]string{
   563  		"paymentId": paymentID,
   564  	}
   565  
   566  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/captures", pathContext)
   567  	if err != nil {
   568  		return resultObject, err
   569  	}
   570  
   571  	clientHeaders := c.apiResource.ClientHeaders()
   572  
   573  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
   574  	if getErr != nil {
   575  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
   576  		if isResponseError {
   577  			var errorObject interface{}
   578  
   579  			errorObject = &errors.ErrorResponse{}
   580  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   581  			if err != nil {
   582  				return resultObject, err
   583  			}
   584  
   585  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   586  			if createErr != nil {
   587  				return resultObject, createErr
   588  			}
   589  
   590  			return resultObject, err
   591  		}
   592  
   593  		return resultObject, getErr
   594  	}
   595  
   596  	return resultObject, nil
   597  }
   598  
   599  // Refund represents the resource /{merchantId}/payments/{paymentId}/refund - Create refund
   600  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/refund.html
   601  //
   602  // Can return any of the following errors:
   603  // * DeclinedRefundError if the Ingenico ePayments platform declined / rejected the refund. The refund result will be available from the exception.
   604  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   605  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   606  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   607  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   608  // or there was a conflict (HTTP status code 404, 409 or 410)
   609  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   610  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   611  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   612  // * APIError if the Ingenico ePayments platform returned any other error
   613  func (c *Client) Refund(paymentID string, body refund.Request, context communication.CallContext) (refund.Response, error) {
   614  	var resultObject refund.Response
   615  
   616  	pathContext := map[string]string{
   617  		"paymentId": paymentID,
   618  	}
   619  
   620  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/refund", pathContext)
   621  	if err != nil {
   622  		return resultObject, err
   623  	}
   624  
   625  	clientHeaders := c.apiResource.ClientHeaders()
   626  
   627  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   628  	if postErr != nil {
   629  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   630  		if isResponseError {
   631  			var errorObject interface{}
   632  
   633  			errorObject = &refund.ErrorResponse{}
   634  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   635  			if err != nil {
   636  				return resultObject, err
   637  			}
   638  
   639  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   640  			if createErr != nil {
   641  				return resultObject, createErr
   642  			}
   643  
   644  			return resultObject, err
   645  		}
   646  
   647  		return resultObject, postErr
   648  	}
   649  
   650  	return resultObject, nil
   651  }
   652  
   653  // Refunds represents the resource /{merchantId}/payments/{paymentId}/refunds - Get refunds of payment
   654  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/refunds.html
   655  //
   656  // Can return any of the following errors:
   657  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   658  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   659  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   660  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   661  // or there was a conflict (HTTP status code 404, 409 or 410)
   662  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   663  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   664  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   665  // * APIError if the Ingenico ePayments platform returned any other error
   666  func (c *Client) Refunds(paymentID string, context communication.CallContext) (refund.RefundsResponse, error) {
   667  	var resultObject refund.RefundsResponse
   668  
   669  	pathContext := map[string]string{
   670  		"paymentId": paymentID,
   671  	}
   672  
   673  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/refunds", pathContext)
   674  	if err != nil {
   675  		return resultObject, err
   676  	}
   677  
   678  	clientHeaders := c.apiResource.ClientHeaders()
   679  
   680  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
   681  	if getErr != nil {
   682  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
   683  		if isResponseError {
   684  			var errorObject interface{}
   685  
   686  			errorObject = &errors.ErrorResponse{}
   687  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   688  			if err != nil {
   689  				return resultObject, err
   690  			}
   691  
   692  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   693  			if createErr != nil {
   694  				return resultObject, createErr
   695  			}
   696  
   697  			return resultObject, err
   698  		}
   699  
   700  		return resultObject, getErr
   701  	}
   702  
   703  	return resultObject, nil
   704  }
   705  
   706  // Cancel represents the resource /{merchantId}/payments/{paymentId}/cancel - Cancel payment
   707  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/cancel.html
   708  //
   709  // Can return any of the following errors:
   710  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   711  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   712  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   713  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   714  // or there was a conflict (HTTP status code 404, 409 or 410)
   715  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   716  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   717  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   718  // * APIError if the Ingenico ePayments platform returned any other error
   719  func (c *Client) Cancel(paymentID string, context communication.CallContext) (payment.CancelResponse, error) {
   720  	var resultObject payment.CancelResponse
   721  
   722  	pathContext := map[string]string{
   723  		"paymentId": paymentID,
   724  	}
   725  
   726  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/cancel", pathContext)
   727  	if err != nil {
   728  		return resultObject, err
   729  	}
   730  
   731  	clientHeaders := c.apiResource.ClientHeaders()
   732  
   733  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject)
   734  	if postErr != nil {
   735  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   736  		if isResponseError {
   737  			var errorObject interface{}
   738  
   739  			errorObject = &errors.ErrorResponse{}
   740  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   741  			if err != nil {
   742  				return resultObject, err
   743  			}
   744  
   745  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   746  			if createErr != nil {
   747  				return resultObject, createErr
   748  			}
   749  
   750  			return resultObject, err
   751  		}
   752  
   753  		return resultObject, postErr
   754  	}
   755  
   756  	return resultObject, nil
   757  }
   758  
   759  // Dispute represents the resource /{merchantId}/payments/{paymentId}/dispute - Create dispute
   760  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/dispute.html
   761  //
   762  // Can return any of the following errors:
   763  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   764  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   765  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   766  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   767  // or there was a conflict (HTTP status code 404, 409 or 410)
   768  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   769  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   770  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   771  // * APIError if the Ingenico ePayments platform returned any other error
   772  func (c *Client) Dispute(paymentID string, body dispute.CreateRequest, context communication.CallContext) (dispute.Response, error) {
   773  	var resultObject dispute.Response
   774  
   775  	pathContext := map[string]string{
   776  		"paymentId": paymentID,
   777  	}
   778  
   779  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/dispute", pathContext)
   780  	if err != nil {
   781  		return resultObject, err
   782  	}
   783  
   784  	clientHeaders := c.apiResource.ClientHeaders()
   785  
   786  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
   787  	if postErr != nil {
   788  		responseError, isResponseError := postErr.(*sdkErrors.ResponseError)
   789  		if isResponseError {
   790  			var errorObject interface{}
   791  
   792  			errorObject = &errors.ErrorResponse{}
   793  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   794  			if err != nil {
   795  				return resultObject, err
   796  			}
   797  
   798  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   799  			if createErr != nil {
   800  				return resultObject, createErr
   801  			}
   802  
   803  			return resultObject, err
   804  		}
   805  
   806  		return resultObject, postErr
   807  	}
   808  
   809  	return resultObject, nil
   810  }
   811  
   812  // Disputes represents the resource /{merchantId}/payments/{paymentId}/disputes - Get disputes
   813  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/disputes.html
   814  //
   815  // Can return any of the following errors:
   816  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   817  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   818  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   819  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   820  // or there was a conflict (HTTP status code 404, 409 or 410)
   821  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   822  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   823  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   824  // * APIError if the Ingenico ePayments platform returned any other error
   825  func (c *Client) Disputes(paymentID string, context communication.CallContext) (dispute.DisputesResponse, error) {
   826  	var resultObject dispute.DisputesResponse
   827  
   828  	pathContext := map[string]string{
   829  		"paymentId": paymentID,
   830  	}
   831  
   832  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/disputes", pathContext)
   833  	if err != nil {
   834  		return resultObject, err
   835  	}
   836  
   837  	clientHeaders := c.apiResource.ClientHeaders()
   838  
   839  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
   840  	if getErr != nil {
   841  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
   842  		if isResponseError {
   843  			var errorObject interface{}
   844  
   845  			errorObject = &errors.ErrorResponse{}
   846  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   847  			if err != nil {
   848  				return resultObject, err
   849  			}
   850  
   851  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   852  			if createErr != nil {
   853  				return resultObject, createErr
   854  			}
   855  
   856  			return resultObject, err
   857  		}
   858  
   859  		return resultObject, getErr
   860  	}
   861  
   862  	return resultObject, nil
   863  }
   864  
   865  // Devicefingerprint represents the resource /{merchantId}/payments/{paymentId}/devicefingerprint - Get Device Fingerprint details
   866  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/payments/devicefingerprint.html
   867  //
   868  // Can return any of the following errors:
   869  // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400)
   870  // * AuthorizationError if the request was not allowed (HTTP status code 403)
   871  // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409)
   872  // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed,
   873  // or there was a conflict (HTTP status code 404, 409 or 410)
   874  // * GlobalCollectError if something went wrong at the Ingenico ePayments platform,
   875  // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer,
   876  // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503)
   877  // * APIError if the Ingenico ePayments platform returned any other error
   878  func (c *Client) Devicefingerprint(paymentID string, context communication.CallContext) (payment.DeviceFingerprintDetails, error) {
   879  	var resultObject payment.DeviceFingerprintDetails
   880  
   881  	pathContext := map[string]string{
   882  		"paymentId": paymentID,
   883  	}
   884  
   885  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/payments/{paymentId}/devicefingerprint", pathContext)
   886  	if err != nil {
   887  		return resultObject, err
   888  	}
   889  
   890  	clientHeaders := c.apiResource.ClientHeaders()
   891  
   892  	getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject)
   893  	if getErr != nil {
   894  		responseError, isResponseError := getErr.(*sdkErrors.ResponseError)
   895  		if isResponseError {
   896  			var errorObject interface{}
   897  
   898  			errorObject = &errors.ErrorResponse{}
   899  			err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject)
   900  			if err != nil {
   901  				return resultObject, err
   902  			}
   903  
   904  			err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context)
   905  			if createErr != nil {
   906  				return resultObject, createErr
   907  			}
   908  
   909  			return resultObject, err
   910  		}
   911  
   912  		return resultObject, getErr
   913  	}
   914  
   915  	return resultObject, nil
   916  }
   917  
   918  // NewClient constructs a Payments Client
   919  //
   920  // parent is the *apiresource.APIResource on top of which we want to build the new Payments Client
   921  func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client {
   922  	apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext)
   923  
   924  	return &Client{apiResource}
   925  }