github.com/Ingenico-ePayments/connect-sdk-go@v0.0.0-20240318153750-1f8cd329b9c9/merchant/hostedcheckouts/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 hostedcheckouts 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/hostedcheckout" 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 hostedcheckouts client. Thread-safe. 15 type Client struct { 16 apiResource *apiresource.APIResource 17 } 18 19 // Create represents the resource /{merchantId}/hostedcheckouts - Create hosted checkout 20 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/hostedcheckouts/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 hostedcheckout.CreateRequest, context communication.CallContext) (hostedcheckout.CreateResponse, error) { 33 var resultObject hostedcheckout.CreateResponse 34 35 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/hostedcheckouts", 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}/hostedcheckouts/{hostedCheckoutId} - Get hosted checkout status 69 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/hostedcheckouts/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(hostedCheckoutID string, context communication.CallContext) (hostedcheckout.GetResponse, error) { 82 var resultObject hostedcheckout.GetResponse 83 84 pathContext := map[string]string{ 85 "hostedCheckoutId": hostedCheckoutID, 86 } 87 88 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/hostedcheckouts/{hostedCheckoutId}", 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 // Delete represents the resource /{merchantId}/hostedcheckouts/{hostedCheckoutId} - Delete hosted checkout 122 // Documentation can be found at https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/go/hostedcheckouts/delete.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) Delete(hostedCheckoutID string, context communication.CallContext) error { 135 pathContext := map[string]string{ 136 "hostedCheckoutId": hostedCheckoutID, 137 } 138 139 uri, err := c.apiResource.InstantiateURIWithContext("/v1/{merchantId}/hostedcheckouts/{hostedCheckoutId}", pathContext) 140 if err != nil { 141 return err 142 } 143 144 clientHeaders := c.apiResource.ClientHeaders() 145 146 var resultObject map[string]interface{} 147 deleteErr := c.apiResource.Communicator().Delete(uri, clientHeaders, nil, context, &resultObject) 148 if deleteErr != nil { 149 responseError, isResponseError := deleteErr.(*sdkErrors.ResponseError) 150 if isResponseError { 151 var errorObject interface{} 152 153 errorObject = &errors.ErrorResponse{} 154 err = c.apiResource.Communicator().Marshaller().Unmarshal(responseError.Body(), errorObject) 155 if err != nil { 156 return err 157 } 158 159 err, createErr := sdkErrors.CreateAPIError(responseError.StatusCode(), responseError.Body(), errorObject, context) 160 if createErr != nil { 161 return createErr 162 } 163 164 return err 165 } 166 167 return deleteErr 168 } 169 170 return nil 171 } 172 173 // NewClient constructs a Hostedcheckouts Client 174 // 175 // parent is the *apiresource.APIResource on top of which we want to build the new Hostedcheckouts Client 176 func NewClient(parent *apiresource.APIResource, pathContext map[string]string) *Client { 177 apiResource := apiresource.NewAPIResourceWithParent(parent, pathContext) 178 179 return &Client{apiResource} 180 }