github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/mandates/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 mandates 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/mandates" 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 mandates client. Thread-safe. 15 type Client struct { 16 apiResource *apiresource.APIResource 17 } 18 19 // Create represents the resource /{merchantId}/mandates - Create mandate 20 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/mandates/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 mandates.CreateMandateRequest, context communication.CallContext) (mandates.CreateMandateResponse, error) { 33 var resultObject mandates.CreateMandateResponse 34 35 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/mandates", 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 // CreateWithMandateReference represents the resource /{merchantId}/mandates/{uniqueMandateReference} - Create mandate with mandatereference 69 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/mandates/createWithMandateReference.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) CreateWithMandateReference(uniqueMandateReference string, body mandates.CreateMandateRequest, context communication.CallContext) (mandates.CreateMandateResponse, error) { 82 var resultObject mandates.CreateMandateResponse 83 84 pathContext := map[string]string{ 85 "uniqueMandateReference": uniqueMandateReference, 86 } 87 88 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/mandates/{uniqueMandateReference}", pathContext) 89 if err != nil { 90 return resultObject, err 91 } 92 93 clientHeaders := c.apiResource.ClientHeaders() 94 95 putErr := c.apiResource.Communicator().Put(uri, clientHeaders, nil, body, context, &resultObject) 96 if putErr != nil { 97 responseError, isResponseError := putErr.(*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, putErr 116 } 117 118 return resultObject, nil 119 } 120 121 // Get represents the resource /{merchantId}/mandates/{uniqueMandateReference} - Get mandate 122 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/mandates/get.html 123 // 124 // Can return any of the following errors: 125 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 126 // * AuthorizationError if the request was not allowed (HTTP status code 403) 127 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 128 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 129 // or there was a conflict (HTTP status code 404, 409 or 410) 130 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 131 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 132 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 133 // * APIError if the Ingenico ePayments platform returned any other error 134 func (c *Client) Get(uniqueMandateReference string, context communication.CallContext) (mandates.GetMandateResponse, error) { 135 var resultObject mandates.GetMandateResponse 136 137 pathContext := map[string]string{ 138 "uniqueMandateReference": uniqueMandateReference, 139 } 140 141 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/mandates/{uniqueMandateReference}", pathContext) 142 if err != nil { 143 return resultObject, err 144 } 145 146 clientHeaders := c.apiResource.ClientHeaders() 147 148 getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject) 149 if getErr != nil { 150 responseError, isResponseError := getErr.(*sdkErrors.ResponseError) 151 if isResponseError { 152 var errorObject interface{} 153 154 errorObject = &errors.ErrorResponse{} 155 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 156 if err != nil { 157 return resultObject, err 158 } 159 160 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 161 if createErr != nil { 162 return resultObject, createErr 163 } 164 165 return resultObject, err 166 } 167 168 return resultObject, getErr 169 } 170 171 return resultObject, nil 172 } 173 174 // Block represents the resource /{merchantId}/mandates/{uniqueMandateReference}/block - Block mandate 175 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/mandates/block.html 176 // 177 // Can return any of the following errors: 178 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 179 // * AuthorizationError if the request was not allowed (HTTP status code 403) 180 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 181 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 182 // or there was a conflict (HTTP status code 404, 409 or 410) 183 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 184 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 185 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 186 // * APIError if the Ingenico ePayments platform returned any other error 187 func (c *Client) Block(uniqueMandateReference string, context communication.CallContext) (mandates.GetMandateResponse, error) { 188 var resultObject mandates.GetMandateResponse 189 190 pathContext := map[string]string{ 191 "uniqueMandateReference": uniqueMandateReference, 192 } 193 194 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/mandates/{uniqueMandateReference}/block", pathContext) 195 if err != nil { 196 return resultObject, err 197 } 198 199 clientHeaders := c.apiResource.ClientHeaders() 200 201 postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject) 202 if postErr != nil { 203 responseError, isResponseError := postErr.(*sdkErrors.ResponseError) 204 if isResponseError { 205 var errorObject interface{} 206 207 errorObject = &errors.ErrorResponse{} 208 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 209 if err != nil { 210 return resultObject, err 211 } 212 213 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 214 if createErr != nil { 215 return resultObject, createErr 216 } 217 218 return resultObject, err 219 } 220 221 return resultObject, postErr 222 } 223 224 return resultObject, nil 225 } 226 227 // Unblock represents the resource /{merchantId}/mandates/{uniqueMandateReference}/unblock - Unblock mandate 228 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/mandates/unblock.html 229 // 230 // Can return any of the following errors: 231 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 232 // * AuthorizationError if the request was not allowed (HTTP status code 403) 233 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 234 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 235 // or there was a conflict (HTTP status code 404, 409 or 410) 236 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 237 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 238 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 239 // * APIError if the Ingenico ePayments platform returned any other error 240 func (c *Client) Unblock(uniqueMandateReference string, context communication.CallContext) (mandates.GetMandateResponse, error) { 241 var resultObject mandates.GetMandateResponse 242 243 pathContext := map[string]string{ 244 "uniqueMandateReference": uniqueMandateReference, 245 } 246 247 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/mandates/{uniqueMandateReference}/unblock", pathContext) 248 if err != nil { 249 return resultObject, err 250 } 251 252 clientHeaders := c.apiResource.ClientHeaders() 253 254 postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject) 255 if postErr != nil { 256 responseError, isResponseError := postErr.(*sdkErrors.ResponseError) 257 if isResponseError { 258 var errorObject interface{} 259 260 errorObject = &errors.ErrorResponse{} 261 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 262 if err != nil { 263 return resultObject, err 264 } 265 266 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 267 if createErr != nil { 268 return resultObject, createErr 269 } 270 271 return resultObject, err 272 } 273 274 return resultObject, postErr 275 } 276 277 return resultObject, nil 278 } 279 280 // Revoke represents the resource /{merchantId}/mandates/{uniqueMandateReference}/revoke - Revoke mandate 281 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/mandates/revoke.html 282 // 283 // Can return any of the following errors: 284 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 285 // * AuthorizationError if the request was not allowed (HTTP status code 403) 286 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 287 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 288 // or there was a conflict (HTTP status code 404, 409 or 410) 289 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 290 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 291 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 292 // * APIError if the Ingenico ePayments platform returned any other error 293 func (c *Client) Revoke(uniqueMandateReference string, context communication.CallContext) (mandates.GetMandateResponse, error) { 294 var resultObject mandates.GetMandateResponse 295 296 pathContext := map[string]string{ 297 "uniqueMandateReference": uniqueMandateReference, 298 } 299 300 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/mandates/{uniqueMandateReference}/revoke", pathContext) 301 if err != nil { 302 return resultObject, err 303 } 304 305 clientHeaders := c.apiResource.ClientHeaders() 306 307 postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, nil, context, &resultObject) 308 if postErr != nil { 309 responseError, isResponseError := postErr.(*sdkErrors.ResponseError) 310 if isResponseError { 311 var errorObject interface{} 312 313 errorObject = &errors.ErrorResponse{} 314 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 315 if err != nil { 316 return resultObject, err 317 } 318 319 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 320 if createErr != nil { 321 return resultObject, createErr 322 } 323 324 return resultObject, err 325 } 326 327 return resultObject, postErr 328 } 329 330 return resultObject, nil 331 } 332 333 // NewClient constructs a Mandates Client 334 // 335 // parent is the *apiresource.APIResource on top of which we want to build the new Mandates Client 336 func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client { 337 apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext) 338 339 return &Client{apiResource} 340 }