github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/installments/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 installments
     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/installments"
    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 installments client. Thread-safe.
    15  type Client struct {
    16  	apiResource *apiresource.APIResource
    17  }
    18  
    19  // GetInstallmentsInfo represents the resource /{merchantId}/installments/getInstallmentsInfo - Get installment information
    20  // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/installments/getInstallmentsInfo.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) GetInstallmentsInfo(body installments.GetInstallmentRequest, context communication.CallContext) (installments.InstallmentOptionsResponse, error) {
    33  	var resultObject installments.InstallmentOptionsResponse
    34  
    35  	uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/installments/getInstallmentsInfo", 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  // NewClient constructs a Installments Client
    69  //
    70  // parent is the *apiresource.APIResource on top of which we want to build the new Installments Client
    71  func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client {
    72  	apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext)
    73  
    74  	return &Client{apiResource}
    75  }