github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/hostedmandatemanagements/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 hostedmandatemanagements
     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/hostedmandatemanagement"
    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 hostedmandatemanagements client. Thread-safe.
    15  type Client struct {
    16  	apiResource *apiresource.APIResource
    17  }
    18  
    19  // Create represents the resource /{merchantId}/hostedmandatemanagements - Create hosted mandate management
    20  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/hostedmandatemanagements/create.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) Create(body hostedmandatemanagement.CreateRequest, context communication.CallContext) (hostedmandatemanagement.CreateResponse, error) {
    33  	var resultObject hostedmandatemanagement.CreateResponse
    34  
    35  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/hostedmandatemanagements", nil)
    36  	if err != nil {
    37  		return resultObject, err
    38  	}
    39  
    40  	clientHeaders := c.apiResource.ClientHeaders()
    41  
    42  	postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject)
    43  	if postErr != nil {
    44  		responseError, isResponseError := postErr.(*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, postErr
    63  	}
    64  
    65  	return resultObject, nil
    66  }
    67  
    68  // Get represents the resource /{merchantId}/hostedmandatemanagements/{hostedMandateManagementId} - Get hosted mandate management status
    69  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/hostedmandatemanagements/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(hostedMandateManagementID string, context communication.CallContext) (hostedmandatemanagement.GetResponse, error) {
    82  	var resultObject hostedmandatemanagement.GetResponse
    83  
    84  	pathContext := map[string]string{
    85  		"hostedMandateManagementId": hostedMandateManagementID,
    86  	}
    87  
    88  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/hostedmandatemanagements/{hostedMandateManagementId}", 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, nil, 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  // NewClient constructs a Hostedmandatemanagements Client
   122  //
   123  // parent is the *apiresource.APIResource on top of which we want to build the new Hostedmandatemanagements Client
   124  func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client {
   125  	apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext)
   126  
   127  	return &Client{apiResource}
   128  }