github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/captures/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 captures 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/errors" 10 "github.com/Ingenico-ePayments/connect-sdk-go/domain/refund" 11 sdkErrors "github.com/Ingenico-ePayments/connect-sdk-go/errors" 12 "github.com/Ingenico-ePayments/connect-sdk-go/internal/apiresource" 13 ) 14 15 // Client represents a captures client. Thread-safe. 16 type Client struct { 17 apiResource *apiresource.APIResource 18 } 19 20 // Get represents the resource /{merchantId}/captures/{captureId} - Get capture 21 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/captures/get.html 22 // 23 // Can return any of the following errors: 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) Get(captureID string, context communication.CallContext) (capture.Response, error) { 34 var resultObject capture.Response 35 36 pathContext := map[string]string{ 37 "captureId": captureID, 38 } 39 40 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/captures/{captureId}", pathContext) 41 if err != nil { 42 return resultObject, err 43 } 44 45 clientHeaders := c.apiResource.ClientHeaders() 46 47 getErr := c.apiResource.Communicator().Get(uri, clientHeaders, nil, context, &resultObject) 48 if getErr != nil { 49 responseError, isResponseError := getErr.(*sdkErrors.ResponseError) 50 if isResponseError { 51 var errorObject interface{} 52 53 errorObject = &errors.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, getErr 68 } 69 70 return resultObject, nil 71 } 72 73 // Refund represents the resource /{merchantId}/captures/{captureId}/refund - Create Refund 74 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/captures/refund.html 75 // 76 // Can return any of the following errors: 77 // * DeclinedRefundError if the Ingenico ePayments platform declined / rejected the refund. The refund result will be available from the exception. 78 // * ValidationError if the request was not correct and couldn't be processed (HTTP status code 400) 79 // * AuthorizationError if the request was not allowed (HTTP status code 403) 80 // * IdempotenceError if an idempotent request caused a conflict (HTTP status code 409) 81 // * ReferenceError if an object was attempted to be referenced that doesn't exist or has been removed, 82 // or there was a conflict (HTTP status code 404, 409 or 410) 83 // * GlobalCollectError if something went wrong at the Ingenico ePayments platform, 84 // the Ingenico ePayments platform was unable to process a message from a downstream partner/acquirer, 85 // or the service that you're trying to reach is temporary unavailable (HTTP status code 500, 502 or 503) 86 // * APIError if the Ingenico ePayments platform returned any other error 87 func (c *Client) Refund(captureID string, body refund.Request, context communication.CallContext) (refund.Response, error) { 88 var resultObject refund.Response 89 90 pathContext := map[string]string{ 91 "captureId": captureID, 92 } 93 94 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/captures/{captureId}/refund", pathContext) 95 if err != nil { 96 return resultObject, err 97 } 98 99 clientHeaders := c.apiResource.ClientHeaders() 100 101 postErr := c.apiResource.Communicator().Post(uri, clientHeaders, nil, body, context, &resultObject) 102 if postErr != nil { 103 responseError, isResponseError := postErr.(*sdkErrors.ResponseError) 104 if isResponseError { 105 var errorObject interface{} 106 107 errorObject = &refund.ErrorResponse{} 108 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 109 if err != nil { 110 return resultObject, err 111 } 112 113 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 114 if createErr != nil { 115 return resultObject, createErr 116 } 117 118 return resultObject, err 119 } 120 121 return resultObject, postErr 122 } 123 124 return resultObject, nil 125 } 126 127 // NewClient constructs a Captures Client 128 // 129 // parent is the *apiresource.APIResource on top of which we want to build the new Captures Client 130 func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client { 131 apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext) 132 133 return &Client{apiResource} 134 }