From 62e9278a57e2629909dda843172f4ff364de7d1d Mon Sep 17 00:00:00 2001 From: Ash Wu Date: Wed, 28 Dec 2022 17:26:34 +0800 Subject: [PATCH 1/4] Add CheckoutSessionForToken & CreateAnOrderUsingAToken Signed-off-by: Ash Wu Signed-off-by: Ash Wu --- api.go | 215 ++++++++++++++++++++++++++++ client.go | 14 ++ const.go | 16 ++- tests/integration/suite_test.go | 14 ++ tests/integration/tokenflow_test.go | 74 ++++++++++ types.go | 99 +++++++++++++ 6 files changed, 431 insertions(+), 1 deletion(-) create mode 100644 tests/integration/tokenflow_test.go diff --git a/api.go b/api.go index 08f6a63..a67c4a3 100644 --- a/api.go +++ b/api.go @@ -50,6 +50,18 @@ func (c *Client) CreateACheckoutSession(ctx context.Context, body CreateACheckou return c.Client.Do(req) } +func (c *Client) CreateACheckoutSessionForAToken(ctx context.Context, body CreateACheckoutSessionForATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateACheckoutSessionForATokenRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) RetrieveACheckoutSession(ctx context.Context, checkoutSessionId string, params *RetrieveACheckoutSessionParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewRetrieveACheckoutSessionRequest(c.Server, checkoutSessionId, params) if err != nil { @@ -147,6 +159,30 @@ func (c *Client) ListAllOrders(ctx context.Context, params *ListAllOrdersParams, return c.Client.Do(req) } +func (c *Client) CreateAnOrderUsingATokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateAnOrderUsingATokenRequestWithBody(c.Server, contentType, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) CreateAnOrderUsingAToken(ctx context.Context, body CreateAnOrderUsingATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreateAnOrderUsingATokenRequest(c.Server, body) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) RetrieveAnOrder(ctx context.Context, orderId string, params *RetrieveAnOrderParams, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewRetrieveAnOrderRequest(c.Server, orderId, params) if err != nil { @@ -562,6 +598,18 @@ func NewCreateACheckoutSessionRequest(server string, body CreateACheckoutSession return NewCreateACheckoutSessionRequestWithBody(server, "application/json", bodyReader) } +// NewCreateACheckoutSessionForATokenRequest calls the generic CreateACheckoutSession builder with application/json body +func NewCreateACheckoutSessionForATokenRequest(server string, body CreateACheckoutSessionForATokenJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateACheckoutSessionRequestWithBody(server, "application/json", bodyReader) +} + // NewCreateACheckoutSessionRequestWithBody generates requests for CreateACheckoutSession with any type of body func NewCreateACheckoutSessionRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { var err error @@ -907,6 +955,47 @@ func NewListAllOrdersRequest(server string, params *ListAllOrdersParams) (*http. return req, nil } +// NewCreateAnOrderUsingATokenRequest calls the generic CreateAnOrderUsingAToken builder with application/json body +func NewCreateAnOrderUsingATokenRequest(server string, body CreateAnOrderUsingATokenJSONRequestBody) (*http.Request, error) { + var bodyReader io.Reader + buf, err := json.Marshal(body) + + if err != nil { + return nil, err + } + bodyReader = bytes.NewReader(buf) + return NewCreateAnOrderUsingATokenRequestWithBody(server, "application/json", bodyReader) +} + +// NewCreateAnOrderUsingATokenRequestWithBody generates requests for CreateAnOrderUsingAToken with any type of body +func NewCreateAnOrderUsingATokenRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/orders") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), body) + if err != nil { + return nil, err + } + + req.Header.Add("Content-Type", contentType) + + return req, nil +} + // NewRetrieveAnOrderRequest generates requests for RetrieveAnOrder func NewRetrieveAnOrderRequest(server string, orderId string, params *RetrieveAnOrderParams) (*http.Request, error) { var err error @@ -2129,6 +2218,40 @@ func (r ListAllOrdersResponse) StatusCode() int { return 0 } +type CreateAnOrderUsingATokenResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *OrderExpanded + JSON400 *interface{} + JSON401 *struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + JSON404 *struct { + Details []interface{} `json:"details"` + ErrorCode N404ErrorCode `json:"errorCode"` + Message string `json:"message"` + StatusCode N404StatusCode `json:"statusCode"` + } +} + +// Status returns HTTPResponse.Status +func (r CreateAnOrderUsingATokenResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreateAnOrderUsingATokenResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type RetrieveAnOrderResponse struct { Body []byte HTTPResponse *http.Response @@ -2839,6 +2962,24 @@ func (c *ClientWithResponses) CreateACheckoutSessionWithResponse(ctx context.Con return ParseCreateACheckoutSessionResponse(rsp) } +// CreateACheckoutSessionForATokenWithBodyWithResponse request with arbitrary body returning *CreateACheckoutSessionResponse +func (c *ClientWithResponses) CreateACheckoutSessionForATokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) { + rsp, err := c.CreateACheckoutSessionWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateACheckoutSessionResponse(rsp) +} + +func (c *ClientWithResponses) CreateACheckoutSessionForATokenWithResponse(ctx context.Context, body CreateACheckoutSessionForATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) { + rsp, err := c.CreateACheckoutSessionForAToken(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + + return ParseCreateACheckoutSessionResponse(rsp) +} + // RetrieveACheckoutSessionWithResponse request returning *RetrieveACheckoutSessionResponse func (c *ClientWithResponses) RetrieveACheckoutSessionWithResponse(ctx context.Context, checkoutSessionId string, params *RetrieveACheckoutSessionParams, reqEditors ...RequestEditorFn) (*RetrieveACheckoutSessionResponse, error) { rsp, err := c.RetrieveACheckoutSession(ctx, checkoutSessionId, params, reqEditors...) @@ -2910,6 +3051,24 @@ func (c *ClientWithResponses) ListAllOrdersWithResponse(ctx context.Context, par return ParseListAllOrdersResponse(rsp) } +// CreateAnOrderUsingATokenWithBodyWithResponse request with arbitrary body returning *CreateAnOrderUsingATokenResponse +func (c *ClientWithResponses) CreateAnOrderUsingATokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateAnOrderUsingATokenResponse, error) { + rsp, err := c.CreateAnOrderUsingATokenWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateAnOrderUsingATokenResponse(rsp) +} + +func (c *ClientWithResponses) CreateAnOrderUsingATokenWithResponse(ctx context.Context, body CreateAnOrderUsingATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateAnOrderUsingATokenResponse, error) { + rsp, err := c.CreateAnOrderUsingAToken(ctx, body, reqEditors...) + if err != nil { + return nil, err + } + + return ParseCreateAnOrderUsingATokenResponse(rsp) +} + // RetrieveAnOrderWithResponse request returning *RetrieveAnOrderResponse func (c *ClientWithResponses) RetrieveAnOrderWithResponse(ctx context.Context, orderId string, params *RetrieveAnOrderParams, reqEditors ...RequestEditorFn) (*RetrieveAnOrderResponse, error) { rsp, err := c.RetrieveAnOrder(ctx, orderId, params, reqEditors...) @@ -3543,6 +3702,62 @@ func ParseListAllOrdersResponse(rsp *http.Response) (*ListAllOrdersResponse, err return response, nil } +// ParseCreateAnOrderUsingATokenResponse parses an HTTP response from a CreateAnOrderUsingATokenWithResponse call +func ParseCreateAnOrderUsingATokenResponse(rsp *http.Response) (*CreateAnOrderUsingATokenResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreateAnOrderUsingATokenResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest OrderExpanded + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400: + var dest interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON400 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + Details []interface{} `json:"details"` + ErrorCode N404ErrorCode `json:"errorCode"` + Message string `json:"message"` + StatusCode N404StatusCode `json:"statusCode"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + } + + return response, nil +} + // ParseRetrieveAnOrderResponse parses an HTTP response from a RetrieveAnOrderWithResponse call func ParseRetrieveAnOrderResponse(rsp *http.Response) (*RetrieveAnOrderResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) diff --git a/client.go b/client.go index e73844e..ae8e3d1 100644 --- a/client.go +++ b/client.go @@ -160,6 +160,8 @@ type ClientInterface interface { CreateACheckoutSession(ctx context.Context, body CreateACheckoutSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + CreateACheckoutSessionForAToken(ctx context.Context, body CreateACheckoutSessionForATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + RetrieveACheckoutSession(ctx context.Context, checkoutSessionId string, params *RetrieveACheckoutSessionParams, reqEditors ...RequestEditorFn) (*http.Response, error) // Coupon @@ -178,6 +180,10 @@ type ClientInterface interface { // Order ListAllOrders(ctx context.Context, params *ListAllOrdersParams, reqEditors ...RequestEditorFn) (*http.Response, error) + CreateAnOrderUsingATokenWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) + + CreateAnOrderUsingAToken(ctx context.Context, body CreateAnOrderUsingATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) + RetrieveAnOrder(ctx context.Context, orderId string, params *RetrieveAnOrderParams, reqEditors ...RequestEditorFn) (*http.Response, error) CancelAnOrder(ctx context.Context, orderId string, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -244,8 +250,12 @@ type ClientWithResponsesInterface interface { CreateACheckoutSessionWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) + CreateACheckoutSessionForATokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) + CreateACheckoutSessionWithResponse(ctx context.Context, body CreateACheckoutSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) + CreateACheckoutSessionForATokenWithResponse(ctx context.Context, body CreateACheckoutSessionForATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) + RetrieveACheckoutSessionWithResponse(ctx context.Context, checkoutSessionId string, params *RetrieveACheckoutSessionParams, reqEditors ...RequestEditorFn) (*RetrieveACheckoutSessionResponse, error) // Coupon @@ -264,6 +274,10 @@ type ClientWithResponsesInterface interface { // Order ListAllOrdersWithResponse(ctx context.Context, params *ListAllOrdersParams, reqEditors ...RequestEditorFn) (*ListAllOrdersResponse, error) + CreateAnOrderUsingATokenWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateAnOrderUsingATokenResponse, error) + + CreateAnOrderUsingATokenWithResponse(ctx context.Context, body CreateAnOrderUsingATokenJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateAnOrderUsingATokenResponse, error) + RetrieveAnOrderWithResponse(ctx context.Context, orderId string, params *RetrieveAnOrderParams, reqEditors ...RequestEditorFn) (*RetrieveAnOrderResponse, error) CancelAnOrderWithResponse(ctx context.Context, orderId string, reqEditors ...RequestEditorFn) (*CancelAnOrderResponse, error) diff --git a/const.go b/const.go index 23cd3f6..ddd9383 100644 --- a/const.go +++ b/const.go @@ -159,9 +159,23 @@ const ( ExpandNo Expand = "no" ) -// Defines values for LineItemKind +// Defines values for LineItemKind. const ( LineItemKindProduct LineItemKind = "product" LineItemKindDiscount LineItemKind = "discount" LineItemKindTax LineItemKind = "tax" ) + +// Defines values for Mode. +const ( + ModeToken Mode = "token" +) + +// Defines values for TokenStatus. +const ( + TokenStatusRequiresAuthorization TokenStatus = "requires_authorization" + TokenStatusActive TokenStatus = "active" + TokenStatusRejected TokenStatus = "rejected" + TokenStatusDisabled TokenStatus = "disabled" + TokenStatusDeleted TokenStatus = "deleted" +) diff --git a/tests/integration/suite_test.go b/tests/integration/suite_test.go index 3245809..c31680f 100644 --- a/tests/integration/suite_test.go +++ b/tests/integration/suite_test.go @@ -101,6 +101,20 @@ func authorizeOrder(orderId string) (err error) { return } +func authorizeToken(tokenId string) (err error) { + apiPath, _ := url.Parse(os.Getenv("API_BASE")) + apiPath.Path = path.Join(apiPath.Path, fmt.Sprintf("/tokens/%s/approve", tokenId)) + accessToken, err := retrieveAccessToken() + if err != nil { + return + } + //req.DevMode() + httpClient := req.C().SetLogger(nil) //.EnableDumpAllWithoutResponse() + _, err = httpClient.R().SetBearerAuthToken(accessToken).Put(apiPath.String()) + + return +} + func retrieveAccessToken() (accessToken string, err error) { apiPath, _ := url.Parse(os.Getenv("API_BASE")) apiPath.Path = path.Join(apiPath.Path, "/consumers/auth/login") diff --git a/tests/integration/tokenflow_test.go b/tests/integration/tokenflow_test.go new file mode 100644 index 0000000..310b1e2 --- /dev/null +++ b/tests/integration/tokenflow_test.go @@ -0,0 +1,74 @@ +package integration + +import ( + . "github.com/smartpay-co/sdk-go" +) + +func (suite *IntegrationTestSuite) TestTokenFlow() { + //suite.T().Skip() + checkoutPayload := CreateACheckoutSessionForATokenJSONRequestBody{ + Mode: ModeToken, + SuccessUrl: "https://smartpay.co", + CancelUrl: "https://smartpay.co", + } + result, err := suite.client.CreateACheckoutSessionForATokenWithResponse(suite.ctx, checkoutPayload) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + suite.NotNil(result.JSON200.Token.Id) + tokenId := string(*result.JSON200.Token.Id) + + // Authorize the Token + err = authorizeToken(tokenId) + if err != nil { + panic(err) + } + + suite.Run("TestCreateAnOrderUsingAToken", func() { + payload := CreateAnOrderUsingATokenJSONRequestBody{ + Currency: CurrencyJPY, + Amount: 1250, + Items: []Item{ + {Name: "レブロン 18 LOW", Amount: 1000, Currency: CurrencyJPY, Quantity: Ptr(1)}, + {Name: "discount", Amount: 100, Currency: CurrencyJPY, Kind: Ptr(LineItemKindDiscount)}, + {Name: "tax", Amount: 250, Currency: CurrencyJPY, Kind: Ptr(LineItemKindTax)}, + }, + ShippingInfo: ShippingInfo{ + Address: Address{Country: AddressCountryJP, PostalCode: "123", Locality: "locality", Line1: "line1"}, + FeeAmount: Ptr(float32(100)), + FeeCurrency: Ptr(CurrencyJPY), + }, + CaptureMethod: Ptr(CaptureMethodManual), + Reference: Ptr("order_ref_1234567"), + Token: TokenId(tokenId), + } + // Create an order using the token + result, err := suite.client.CreateAnOrderUsingATokenWithResponse(suite.ctx, payload) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + suite.NotNil(result.JSON200.Id) + suite.NotNil(result.JSON200.TokenId) + suite.EqualValues(string(*result.JSON200.TokenId), tokenId) + }) + + suite.Run("TestRetrieveAToken", func() { + + }) + + suite.Run("TestDisableAToken", func() { + + }) + + suite.Run("TestEnableAToken", func() { + + }) + + suite.Run("TestListAllTokens", func() { + + }) + + suite.Run("TestDeleteAToken", func() { + + }) +} diff --git a/types.go b/types.go index 6114f1c..b241484 100644 --- a/types.go +++ b/types.go @@ -114,6 +114,9 @@ type CheckoutSessionExpanded struct { // The URL to launch Smartpay checkout for this checkout session. Redirect your customer to this URL to complete the purchase. Url *CheckoutSessioUrl `json:"url,omitempty"` + + // A Payment token + Token *Token `json:"token,omitempty"` } // The unique identifier for the Checkout Session object. @@ -368,6 +371,8 @@ type MaxResults int // Set of up to 20 key-value pairs that you can attach to the object. type Metadata map[string]interface{} +type Mode string + // The token for the next page of the collection of objects. type NextPageToken string @@ -454,6 +459,9 @@ type OrderExpanded struct { // The moment at which the object was last updated. Measured in milliseconds since the Unix epoch. UpdatedAt *UpdatedAt `json:"updatedAt,omitempty"` + + // The unique identifier for the Token object. + TokenId *TokenId `json:"tokenId,omitempty"` } // The unique identifier for the Payment object. @@ -465,6 +473,35 @@ type OrderOptions interface{} // Order Status type OrderStatus string +// CheckoutSessionCreate defines model for checkout-session_create. +type OrderCreate struct { + // The amount intended to be collected through this order. A positive integer in the smallest currency unit. + Amount OrderAmount `json:"amount"` + + CaptureMethod *CaptureMethod `json:"captureMethod,omitempty"` + + // Three-letter ISO currency code, in uppercase. Must be a supported currency. + Currency Currency `json:"currency"` + + // Customer Information, the details provided here are used to pre-populate forms for your customer's checkout experiences. The more information you send, the better experience the customer will have. + CustomerInfo CustomerInfo `json:"customerInfo"` + + // The line items the customer wishes to order. + Items []Item `json:"items"` + + // Set of up to 20 key-value pairs that you can attach to the object. + Metadata *Metadata `json:"metadata,omitempty"` + + // A - ideally unique - string to reference the Order in your system (e.g. an order ID, etc.). + Reference *string `json:"reference,omitempty"` + + // Shipping Information + ShippingInfo ShippingInfo `json:"shippingInfo"` + + // The unique identifier for the token to be used when creating this order. + Token TokenId `json:"token"` +} + // The token for the page of the collection of objects. type PageToken string @@ -783,6 +820,39 @@ type SuccessUrl string // A flag with a value `false` if the object exists in live mode or `true` if the object exists in test mode. type TestFlag bool +// Token +type Token struct { + // The unique identifier for the Token object. + Id *TokenId `json:"id,omitempty"` + + // A string representing the object’s type. The value is always `checkoutSession` for Checkout Session objects. + Object *string `json:"object,omitempty"` + + // Time at which the object was created. Measured in milliseconds since the Unix epoch. + CreatedAt *CreatedAt `json:"createdAt,omitempty"` + + // Set of up to 20 key-value pairs that you can attach to the object. + Metadata *Metadata `json:"metadata,omitempty"` + + // A - ideally unique - string to reference the Token in your system (e.g. a token ID, etc.). + Reference *string `json:"reference,omitempty"` + + // The current status of the Token object. + Status *TokenStatus `json:"status,omitempty"` + + // A flag with a value `false` if the object exists in live mode or `true` if the object exists in test mode. + Test *TestFlag `json:"test,omitempty"` + + // The moment at which the object was last updated. Measured in milliseconds since the Unix epoch. + UpdatedAt *UpdatedAt `json:"updatedAt,omitempty"` +} + +// The unique identifier for the Token object. +type TokenId string + +// Token Status +type TokenStatus string + // The moment at which the object was last updated. Measured in milliseconds since the Unix epoch. type UpdatedAt int @@ -1036,6 +1106,29 @@ type CheckoutSessionCreate struct { SuccessUrl SuccessUrl `json:"successUrl"` } +// CheckoutSessionForATokenCreate defines model for checkout-session_create. +type CheckoutSessionForATokenCreate struct { + Mode Mode `json:"mode"` + + // The URL the customer will be redirected to if the Checkout Session hasn't completed successfully. This means the Checkout failed, or the customer decided to cancel it. + CancelUrl CancelUrl `json:"cancelUrl"` + + // Customer Information, the details provided here are used to pre-populate forms for your customer's checkout experiences. The more information you send, the better experience the customer will have. + CustomerInfo CustomerInfo `json:"customerInfo"` + + // Locale + Locale *Locale `json:"locale,omitempty"` + + // Set of up to 20 key-value pairs that you can attach to the object. + Metadata *Metadata `json:"metadata,omitempty"` + + // A - ideally unique - string to reference the Order in your system (e.g. an order ID, etc.). + Reference *string `json:"reference,omitempty"` + + // The URL the customer will be redirected to if the Checkout Session completed successfully. This means the Checkout succeeded, i.e. the customer authorized the order. + SuccessUrl SuccessUrl `json:"successUrl"` +} + // CouponCreate defines model for coupon_create. type CouponCreate struct { // Three-letter ISO currency code, in uppercase. Must be a supported currency. @@ -1360,12 +1453,18 @@ type ListAllWebhookEndpointsParams struct { // CreateACheckoutSessionJSONRequestBody defines body for CreateACheckoutSession for application/json ContentType. type CreateACheckoutSessionJSONRequestBody CheckoutSessionCreate +// CreateACheckoutSessionForATokenJSONRequestBody defines body for CheckoutSessionForATokenCreate for application/json ContentType. +type CreateACheckoutSessionForATokenJSONRequestBody CheckoutSessionForATokenCreate + // CreateACouponJSONRequestBody defines body for CreateACoupon for application/json ContentType. type CreateACouponJSONRequestBody CouponCreate // UpdateACouponJSONRequestBody defines body for UpdateACoupon for application/json ContentType. type UpdateACouponJSONRequestBody CouponUpdate +// CreateAnOrderUsingATokenJSONRequestBody defines body for CreateAnOrderUsingAToken for application/json ContentType. +type CreateAnOrderUsingATokenJSONRequestBody OrderCreate + // CreateAPaymentJSONRequestBody defines body for CreateAPayment for application/json ContentType. type CreateAPaymentJSONRequestBody PaymentCreate From 259b8a97aa040991ba7fea791a5cd256e45935a2 Mon Sep 17 00:00:00 2001 From: Ash Wu Date: Wed, 28 Dec 2022 17:41:18 +0800 Subject: [PATCH 2/4] Reorganize tests Signed-off-by: Ash Wu Signed-off-by: Ash Wu --- tests/integration/checkout_test.go | 130 +++++++++++------------ tests/integration/order_test.go | 153 ++++++++++++++-------------- tests/integration/suite_test.go | 2 +- tests/integration/tokenflow_test.go | 2 +- 4 files changed, 144 insertions(+), 143 deletions(-) diff --git a/tests/integration/checkout_test.go b/tests/integration/checkout_test.go index b5bc668..aca3a9d 100644 --- a/tests/integration/checkout_test.go +++ b/tests/integration/checkout_test.go @@ -16,82 +16,82 @@ func (suite *IntegrationTestSuite) TestCreateACheckOutSession() { suite.Nil(err) suite.Contains(result, "promo123") }) -} -func (suite *IntegrationTestSuite) TestRetrieveACheckOutSession() { - //suite.T().Skip() - params := RetrieveACheckoutSessionParams{} - result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, suite.checkoutSessionId, ¶ms) + suite.Run("TestRetrieveACheckOutSession", func() { + //suite.T().Skip() + params := RetrieveACheckoutSessionParams{} + result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, suite.checkoutSessionId, ¶ms) - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) - checkoutSession, _ := ConvertToStruct[CheckoutSession](result.JSON200) - suite.Equal(string(*checkoutSession.Id), suite.checkoutSessionId) -} + checkoutSession, _ := ConvertToStruct[CheckoutSession](result.JSON200) + suite.Equal(string(*checkoutSession.Id), suite.checkoutSessionId) + }) -func (suite *IntegrationTestSuite) TestRetrieveACheckOutSessionExpanded() { - //suite.T().Skip() - params := RetrieveACheckoutSessionParams{ - Expand: Ptr(RetrieveACheckoutSessionParamsExpand(ExpandAll)), - } - result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, suite.checkoutSessionId, ¶ms) + suite.Run("TestRetrieveACheckOutSessionExpanded", func() { + //suite.T().Skip() + params := RetrieveACheckoutSessionParams{ + Expand: Ptr(RetrieveACheckoutSessionParamsExpand(ExpandAll)), + } + result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, suite.checkoutSessionId, ¶ms) - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) - checkoutSession, _ := ConvertToStruct[CheckoutSessionExpanded](result.JSON200) - suite.Equal(string(*checkoutSession.Id), suite.checkoutSessionId) -} + checkoutSession, _ := ConvertToStruct[CheckoutSessionExpanded](result.JSON200) + suite.Equal(string(*checkoutSession.Id), suite.checkoutSessionId) + }) -func (suite *IntegrationTestSuite) TestListAllCheckoutSession() { - //suite.T().Skip() - params := ListAllCheckoutSessionsParams{} - result, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, ¶ms) + suite.Run("TestListAllCheckoutSession", func() { + //suite.T().Skip() + params := ListAllCheckoutSessionsParams{} + result, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, ¶ms) - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) - checkoutSession, _ := ConvertToStruct[CheckoutSession]((*result.JSON200.Data)[0]) - suite.NotNil(checkoutSession.Id) -} + checkoutSession, _ := ConvertToStruct[CheckoutSession]((*result.JSON200.Data)[0]) + suite.NotNil(checkoutSession.Id) + }) -func (suite *IntegrationTestSuite) TestListAllCheckoutSessionPagination() { - //suite.T().Skip() - // Get the first page - firstPageParams := ListAllCheckoutSessionsParams{ - MaxResults: Ptr(MaxResults(1)), - } - FirstPageResult, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, &firstPageParams) - suite.Nil(err) - suite.Len(*FirstPageResult.JSON200.Data, 1) - - // Get the next page - nextPageToken := FirstPageResult.JSON200.NextPageToken - nextPageParams := ListAllCheckoutSessionsParams{ - MaxResults: Ptr(MaxResults(1)), - PageToken: Ptr(PageToken(*nextPageToken)), - } - nextPageResult, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, &nextPageParams) - suite.Nil(err) - suite.Len(*nextPageResult.JSON200.Data, 1) - suite.EqualValues(string(*nextPageResult.JSON200.PageToken), string(*nextPageToken)) -} + suite.Run("TestListAllCheckoutSessionPagination", func() { + //suite.T().Skip() + // Get the first page + firstPageParams := ListAllCheckoutSessionsParams{ + MaxResults: Ptr(MaxResults(1)), + } + FirstPageResult, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, &firstPageParams) + suite.Nil(err) + suite.Len(*FirstPageResult.JSON200.Data, 1) + + // Get the next page + nextPageToken := FirstPageResult.JSON200.NextPageToken + nextPageParams := ListAllCheckoutSessionsParams{ + MaxResults: Ptr(MaxResults(1)), + PageToken: Ptr(PageToken(*nextPageToken)), + } + nextPageResult, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, &nextPageParams) + suite.Nil(err) + suite.Len(*nextPageResult.JSON200.Data, 1) + suite.EqualValues(string(*nextPageResult.JSON200.PageToken), string(*nextPageToken)) + }) -func (suite *IntegrationTestSuite) TestListAllCheckoutSessionExpanded() { - //suite.T().Skip() - params := ListAllCheckoutSessionsParams{ - Expand: Ptr(ListAllCheckoutSessionsParamsExpand(ExpandAll)), - } - result, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, ¶ms) + suite.Run("TestListAllCheckoutSessionExpanded", func() { + //suite.T().Skip() + params := ListAllCheckoutSessionsParams{ + Expand: Ptr(ListAllCheckoutSessionsParamsExpand(ExpandAll)), + } + result, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, ¶ms) - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) - checkoutSession, _ := ConvertToStruct[CheckoutSessionExpanded]((*result.JSON200.Data)[0]) - suite.NotNil(checkoutSession.Id) + checkoutSession, _ := ConvertToStruct[CheckoutSessionExpanded]((*result.JSON200.Data)[0]) + suite.NotNil(checkoutSession.Id) + }) } diff --git a/tests/integration/order_test.go b/tests/integration/order_test.go index e6dcba9..2f6b0d2 100644 --- a/tests/integration/order_test.go +++ b/tests/integration/order_test.go @@ -15,92 +15,93 @@ func (suite *IntegrationTestSuite) TestListAllOrders() { order, _ := ConvertToStruct[Order]((*result.JSON200.Data)[0]) suite.NotNil(order.Id) -} - -func (suite *IntegrationTestSuite) TestListAllOrdersExpanded() { - //suite.T().Skip() - params := ListAllOrdersParams{ - Expand: Ptr(ListAllOrdersParamsExpand(ExpandAll)), - } - result, err := suite.client.ListAllOrdersWithResponse(suite.ctx, ¶ms) - - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) - - order, _ := ConvertToStruct[Order]((*result.JSON200.Data)[0]) - suite.NotNil(order.Id) -} -func (suite *IntegrationTestSuite) TestListAllOrdersPagination() { - //suite.T().Skip() - // Get the first page - firstPageParams := ListAllOrdersParams{ - MaxResults: Ptr(MaxResults(1)), - } - FirstPageResult, err := suite.client.ListAllOrdersWithResponse(suite.ctx, &firstPageParams) - suite.Nil(err) - suite.Len(*FirstPageResult.JSON200.Data, 1) - - // Get the next page - nextPageToken := FirstPageResult.JSON200.NextPageToken - nextPageParams := ListAllOrdersParams{ - MaxResults: Ptr(MaxResults(1)), - PageToken: Ptr(PageToken(*nextPageToken)), - } - nextPageResult, err := suite.client.ListAllOrdersWithResponse(suite.ctx, &nextPageParams) - suite.Nil(err) - suite.Len(*nextPageResult.JSON200.Data, 1) - suite.EqualValues(string(*nextPageResult.JSON200.PageToken), string(*nextPageToken)) -} + suite.Run("TestListAllOrdersExpanded", func() { + //suite.T().Skip() + params := ListAllOrdersParams{ + Expand: Ptr(ListAllOrdersParamsExpand(ExpandAll)), + } + result, err := suite.client.ListAllOrdersWithResponse(suite.ctx, ¶ms) -func (suite *IntegrationTestSuite) TestRetrieveAnOrder() { - //suite.T().Skip() - params := RetrieveAnOrderParams{} - result, err := suite.client.RetrieveAnOrderWithResponse(suite.ctx, suite.orderId, ¶ms) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) + order, _ := ConvertToStruct[Order]((*result.JSON200.Data)[0]) + suite.NotNil(order.Id) + }) - order, _ := ConvertToStruct[Order](result.JSON200) - suite.NotNil(order.Id) -} + suite.Run("TestListAllOrdersPagination", func() { + //suite.T().Skip() + // Get the first page + firstPageParams := ListAllOrdersParams{ + MaxResults: Ptr(MaxResults(1)), + } + FirstPageResult, err := suite.client.ListAllOrdersWithResponse(suite.ctx, &firstPageParams) + suite.Nil(err) + suite.Len(*FirstPageResult.JSON200.Data, 1) + + // Get the next page + nextPageToken := FirstPageResult.JSON200.NextPageToken + nextPageParams := ListAllOrdersParams{ + MaxResults: Ptr(MaxResults(1)), + PageToken: Ptr(PageToken(*nextPageToken)), + } + nextPageResult, err := suite.client.ListAllOrdersWithResponse(suite.ctx, &nextPageParams) + suite.Nil(err) + suite.Len(*nextPageResult.JSON200.Data, 1) + suite.EqualValues(string(*nextPageResult.JSON200.PageToken), string(*nextPageToken)) + }) -func (suite *IntegrationTestSuite) TestRetrieveAnOrderExpanded() { - //suite.T().Skip() - params := RetrieveAnOrderParams{ - Expand: Ptr(RetrieveAnOrderParamsExpand(ExpandAll)), - } - result, err := suite.client.RetrieveAnOrderWithResponse(suite.ctx, suite.orderId, ¶ms) + suite.Run("TestRetrieveAnOrder", func() { + //suite.T().Skip() + params := RetrieveAnOrderParams{} + result, err := suite.client.RetrieveAnOrderWithResponse(suite.ctx, suite.orderId, ¶ms) - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) - order, _ := ConvertToStruct[OrderExpanded](result.JSON200) - suite.NotNil(order.Id) + order, _ := ConvertToStruct[Order](result.JSON200) + suite.NotNil(order.Id) + }) - suite.Run("TestRetrieveAnOrderExpandedSupportsNewLineItem", func() { - for _, item := range *order.LineItems { - if *item.Kind == LineItemKindTax { - suite.EqualValues(int(*item.Amount), 250) - suite.EqualValues(*item.Currency, CurrencyJPY) - } - if *item.Kind == LineItemKindDiscount { - suite.EqualValues(int(*item.Amount), 100) - suite.EqualValues(*item.Currency, CurrencyJPY) - } + suite.Run("TestRetrieveAnOrderExpanded", func() { + //suite.T().Skip() + params := RetrieveAnOrderParams{ + Expand: Ptr(RetrieveAnOrderParamsExpand(ExpandAll)), } + result, err := suite.client.RetrieveAnOrderWithResponse(suite.ctx, suite.orderId, ¶ms) + + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + + order, _ := ConvertToStruct[OrderExpanded](result.JSON200) + suite.NotNil(order.Id) + + suite.Run("TestRetrieveAnOrderExpandedSupportsNewLineItem", func() { + for _, item := range *order.LineItems { + if *item.Kind == LineItemKindTax { + suite.EqualValues(int(*item.Amount), 250) + suite.EqualValues(*item.Currency, CurrencyJPY) + } + if *item.Kind == LineItemKindDiscount { + suite.EqualValues(int(*item.Amount), 100) + suite.EqualValues(*item.Currency, CurrencyJPY) + } + } + }) }) -} -func (suite *IntegrationTestSuite) TestCancelAnOrder() { - //suite.T().Skip() - result, err := suite.client.CancelAnOrderWithResponse(suite.ctx, suite.testCancelOrderId) + suite.Run("TestCancelAnOrder", func() { + //suite.T().Skip() + result, err := suite.client.CancelAnOrderWithResponse(suite.ctx, suite.testCancelOrderId) + + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + suite.EqualValues(string(*result.JSON200.Status), OrderStatusCanceled) + }) - suite.Nil(err) - suite.NotNil(result.Body) - suite.NotNil(result.JSON200) - suite.EqualValues(string(*result.JSON200.Status), OrderStatusCanceled) } diff --git a/tests/integration/suite_test.go b/tests/integration/suite_test.go index c31680f..60a8333 100644 --- a/tests/integration/suite_test.go +++ b/tests/integration/suite_test.go @@ -22,7 +22,7 @@ type IntegrationTestSuite struct { testCancelOrderId string } -func TestCheckOutTestSuite(t *testing.T) { +func TestIntegrationTestSuite(t *testing.T) { suite.Run(t, new(IntegrationTestSuite)) } diff --git a/tests/integration/tokenflow_test.go b/tests/integration/tokenflow_test.go index 310b1e2..cfe92ab 100644 --- a/tests/integration/tokenflow_test.go +++ b/tests/integration/tokenflow_test.go @@ -4,7 +4,7 @@ import ( . "github.com/smartpay-co/sdk-go" ) -func (suite *IntegrationTestSuite) TestTokenFlow() { +func (suite *IntegrationTestSuite) TestCreateACheckoutSessionForAToken() { //suite.T().Skip() checkoutPayload := CreateACheckoutSessionForATokenJSONRequestBody{ Mode: ModeToken, From ec6b3ef2b3f5ef669af042e84b49c5c61da8a88f Mon Sep 17 00:00:00 2001 From: Ash Wu Date: Thu, 29 Dec 2022 11:50:18 +0800 Subject: [PATCH 3/4] Add token APIs & tests Signed-off-by: Ash Wu Signed-off-by: Ash Wu --- api.go | 750 +++++++++++++++++++++++++++- client.go | 22 + tests/integration/tokenflow_test.go | 49 +- types.go | 9 + 4 files changed, 794 insertions(+), 36 deletions(-) diff --git a/api.go b/api.go index a67c4a3..b47e376 100644 --- a/api.go +++ b/api.go @@ -507,6 +507,66 @@ func (c *Client) DeleteAWebhookEndpoint(ctx context.Context, webhookEndpointId s return c.Client.Do(req) } +func (c *Client) ListAllTokens(ctx context.Context, params *ListAllTokensParams, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewListAllTokensRequest(c.Server, params) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) RetrieveAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewRetrieveATokenRequest(c.Server, tokenId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) EnableAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewEnableATokenRequest(c.Server, tokenId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DisableAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDisableATokenRequest(c.Server, tokenId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + +func (c *Client) DeleteAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewDeleteATokenRequest(c.Server, tokenId) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + // NewListAllCheckoutSessionsRequest generates requests for ListAllCheckoutSessions func NewListAllCheckoutSessionsRequest(server string, params *ListAllCheckoutSessionsParams) (*http.Request, error) { var err error @@ -1892,7 +1952,7 @@ func NewUpdateAWebhookEndpointRequestWithBody(server string, webhookEndpointId s return req, nil } -// NewDeleteAWebhookEndpointRequest generates requests for RetrieveAWebhookEndpoint +// NewDeleteAWebhookEndpointRequest generates requests for DeleteAWebhookEndpoint func NewDeleteAWebhookEndpointRequest(server string, webhookEndpointId string) (*http.Request, error) { var err error @@ -1926,6 +1986,205 @@ func NewDeleteAWebhookEndpointRequest(server string, webhookEndpointId string) ( return req, nil } +// NewListAllTokensRequest generates requests for ListAllTokens +func NewListAllTokensRequest(server string, params *ListAllTokensParams) (*http.Request, error) { + var err error + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/tokens") + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + queryValues := queryURL.Query() + + if params.MaxResults != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "maxResults", runtime.ParamLocationQuery, *params.MaxResults); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + if params.PageToken != nil { + + if queryFrag, err := runtime.StyleParamWithLocation("form", true, "pageToken", runtime.ParamLocationQuery, *params.PageToken); err != nil { + return nil, err + } else if parsed, err := url.ParseQuery(queryFrag); err != nil { + return nil, err + } else { + for k, v := range parsed { + for _, v2 := range v { + queryValues.Add(k, v2) + } + } + } + + } + + queryURL.RawQuery = queryValues.Encode() + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewRetrieveATokenRequest generates requests for RetrieveAToken +func NewRetrieveATokenRequest(server string, tokenId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "tokenId", runtime.ParamLocationPath, tokenId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/tokens/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("GET", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewDeleteATokenRequest generates requests for DeleteAToken +func NewDeleteATokenRequest(server string, tokenId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "tokenId", runtime.ParamLocationPath, tokenId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/tokens/%s", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("DELETE", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewEnableATokenRequest generates requests for EnableAToken +func NewEnableATokenRequest(server string, tokenId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "tokenId", runtime.ParamLocationPath, tokenId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/tokens/%s/enable", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PUT", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + +// NewDisableATokenRequest generates requests for DisableAToken +func NewDisableATokenRequest(server string, tokenId string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "tokenId", runtime.ParamLocationPath, tokenId) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/v1/tokens/%s/disable", pathParam0) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("PUT", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + type ListAllCheckoutSessionsResponse struct { Body []byte HTTPResponse *http.Response @@ -2935,29 +3194,202 @@ func (r DeleteAWebhookEndpointResponse) StatusCode() int { return 0 } -// ListAllCheckoutSessionsWithResponse request returning *ListAllCheckoutSessionsResponse -func (c *ClientWithResponses) ListAllCheckoutSessionsWithResponse(ctx context.Context, params *ListAllCheckoutSessionsParams, reqEditors ...RequestEditorFn) (*ListAllCheckoutSessionsResponse, error) { - rsp, err := c.ListAllCheckoutSessions(ctx, params, reqEditors...) - if err != nil { - return nil, err - } - return ParseListAllCheckoutSessionsResponse(rsp) -} +type ListAllTokensResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *struct { + Data *[]Token `json:"data,omitempty"` -// CreateACheckoutSessionWithBodyWithResponse request with arbitrary body returning *CreateACheckoutSessionResponse -func (c *ClientWithResponses) CreateACheckoutSessionWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) { - rsp, err := c.CreateACheckoutSessionWithBody(ctx, contentType, body, reqEditors...) - if err != nil { - return nil, err - } - return ParseCreateACheckoutSessionResponse(rsp) -} + // The maximum number of objects returned for this call. Equals to the maxResults query parameter specified (or 20 if not specified). + MaxResults *MaxResults `json:"maxResults,omitempty"` -func (c *ClientWithResponses) CreateACheckoutSessionWithResponse(ctx context.Context, body CreateACheckoutSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) { - rsp, err := c.CreateACheckoutSession(ctx, body, reqEditors...) - if err != nil { - return nil, err - } + // The token for the next page of the collection of objects. + NextPageToken *NextPageToken `json:"nextPageToken,omitempty"` + + // A string representing the object’s type. The value is always `collection` for collection objects. + Object *CollectionObject `json:"object,omitempty"` + + // The token for the page of the collection of objects. + PageToken *PageToken `json:"pageToken,omitempty"` + + // The actual number of objects returned for this call. This value is less than or equal to maxResults. + Results *Results `json:"results,omitempty"` + } + JSON401 *struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } +} + +// Status returns HTTPResponse.Status +func (r ListAllTokensResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r ListAllTokensResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type RetrieveATokenResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *Token + JSON401 *struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + JSON404 *struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } +} + +type EnableATokenResponse struct { + Body []byte + HTTPResponse *http.Response + JSON401 *struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + JSON404 *struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } +} + +// Status returns HTTPResponse.Status +func (r EnableATokenResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r EnableATokenResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DisableATokenResponse struct { + Body []byte + HTTPResponse *http.Response + JSON401 *struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + JSON404 *struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } +} + +// Status returns HTTPResponse.Status +func (r DisableATokenResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DisableATokenResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +type DeleteATokenResponse struct { + Body []byte + HTTPResponse *http.Response + JSON401 *struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + JSON404 *struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } +} + +// Status returns HTTPResponse.Status +func (r DeleteATokenResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r DeleteATokenResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// Status returns HTTPResponse.Status +func (r RetrieveATokenResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r RetrieveATokenResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + +// ListAllCheckoutSessionsWithResponse request returning *ListAllCheckoutSessionsResponse +func (c *ClientWithResponses) ListAllCheckoutSessionsWithResponse(ctx context.Context, params *ListAllCheckoutSessionsParams, reqEditors ...RequestEditorFn) (*ListAllCheckoutSessionsResponse, error) { + rsp, err := c.ListAllCheckoutSessions(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseListAllCheckoutSessionsResponse(rsp) +} + +// CreateACheckoutSessionWithBodyWithResponse request with arbitrary body returning *CreateACheckoutSessionResponse +func (c *ClientWithResponses) CreateACheckoutSessionWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) { + rsp, err := c.CreateACheckoutSessionWithBody(ctx, contentType, body, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreateACheckoutSessionResponse(rsp) +} + +func (c *ClientWithResponses) CreateACheckoutSessionWithResponse(ctx context.Context, body CreateACheckoutSessionJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateACheckoutSessionResponse, error) { + rsp, err := c.CreateACheckoutSession(ctx, body, reqEditors...) + if err != nil { + return nil, err + } return ParseCreateACheckoutSessionResponse(rsp) } @@ -3304,6 +3736,51 @@ func (c *ClientWithResponses) DeleteAWebhookEndpointWithResponse(ctx context.Con return ParseDeleteAWebhookEndpointResponse(rsp) } +// ListAllTokensWithResponse request returning *ListAllTokensResponse +func (c *ClientWithResponses) ListAllTokensWithResponse(ctx context.Context, params *ListAllTokensParams, reqEditors ...RequestEditorFn) (*ListAllTokensResponse, error) { + rsp, err := c.ListAllTokens(ctx, params, reqEditors...) + if err != nil { + return nil, err + } + return ParseListAllTokensResponse(rsp) +} + +// RetrieveATokenWithResponse request returning *RetrieveATokenResponse +func (c *ClientWithResponses) RetrieveATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*RetrieveATokenResponse, error) { + rsp, err := c.RetrieveAToken(ctx, tokenId, reqEditors...) + if err != nil { + return nil, err + } + return ParseRetrieveATokenResponse(rsp) +} + +// EnableATokenWithResponse request returning *EnableATokenResponse +func (c *ClientWithResponses) EnableATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*EnableATokenResponse, error) { + rsp, err := c.EnableAToken(ctx, tokenId, reqEditors...) + if err != nil { + return nil, err + } + return ParseEnableATokenResponse(rsp) +} + +// DisableATokenWithResponse request returning *DisableATokenResponse +func (c *ClientWithResponses) DisableATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*DisableATokenResponse, error) { + rsp, err := c.EnableAToken(ctx, tokenId, reqEditors...) + if err != nil { + return nil, err + } + return ParseDisableATokenResponse(rsp) +} + +// DeleteATokenWithResponse request returning *DeleteATokenResponse +func (c *ClientWithResponses) DeleteATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*DeleteATokenResponse, error) { + rsp, err := c.DeleteAToken(ctx, tokenId, reqEditors...) + if err != nil { + return nil, err + } + return ParseDeleteATokenResponse(rsp) +} + // ParseListAllCheckoutSessionsResponse parses an HTTP response from a ListAllCheckoutSessionsWithResponse call func ParseListAllCheckoutSessionsResponse(rsp *http.Response) (*ListAllCheckoutSessionsResponse, error) { bodyBytes, err := ioutil.ReadAll(rsp.Body) @@ -4726,3 +5203,232 @@ func ParseDeleteAWebhookEndpointResponse(rsp *http.Response) (*DeleteAWebhookEnd return response, nil } + +// ParseListAllTokensResponse parses an HTTP response from a ListAllTokensWithResponse call +func ParseListAllTokensResponse(rsp *http.Response) (*ListAllTokensResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &ListAllTokensResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest struct { + Data *[]Token `json:"data,omitempty"` + + // The maximum number of objects returned for this call. Equals to the maxResults query parameter specified (or 20 if not specified). + MaxResults *MaxResults `json:"maxResults,omitempty"` + + // The token for the next page of the collection of objects. + NextPageToken *NextPageToken `json:"nextPageToken,omitempty"` + + // A string representing the object’s type. The value is always `collection` for collection objects. + Object *CollectionObject `json:"object,omitempty"` + + // The token for the page of the collection of objects. + PageToken *PageToken `json:"pageToken,omitempty"` + + // The actual number of objects returned for this call. This value is less than or equal to maxResults. + Results *Results `json:"results,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + } + + return response, nil +} + +// ParseRetrieveATokenResponse parses an HTTP response from a RetrieveATokenWithResponse call +func ParseRetrieveATokenResponse(rsp *http.Response) (*RetrieveATokenResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &RetrieveATokenResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest Token + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + } + + return response, nil +} + +// ParseEnableATokenResponse parses an HTTP response from a EnableATokenWithResponse call +func ParseEnableATokenResponse(rsp *http.Response) (*EnableATokenResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &EnableATokenResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + } + + return response, nil +} + +// ParseDisableATokenResponse parses an HTTP response from a DisableATokenWithResponse call +func ParseDisableATokenResponse(rsp *http.Response) (*DisableATokenResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DisableATokenResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + } + + return response, nil +} + +// ParseDeleteATokenResponse parses an HTTP response from a DeleteATokenWithResponse call +func ParseDeleteATokenResponse(rsp *http.Response) (*DeleteATokenResponse, error) { + bodyBytes, err := ioutil.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &DeleteATokenResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401: + var dest struct { + Realm *string `json:"realm,omitempty"` + Scheme *string `json:"scheme,omitempty"` + StatusCode *int `json:"statusCode,omitempty"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON401 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404: + var dest struct { + Details []interface{} `json:"details"` + ErrorCode string `json:"errorCode"` + Message string `json:"message"` + StatusCode float32 `json:"statusCode"` + } + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON404 = &dest + + } + + return response, nil +} diff --git a/client.go b/client.go index ae8e3d1..1830289 100644 --- a/client.go +++ b/client.go @@ -241,6 +241,17 @@ type ClientInterface interface { UpdateAWebhookEndpoint(ctx context.Context, webhookEndpointId string, body UpdateAWebhookEndpointJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) DeleteAWebhookEndpoint(ctx context.Context, webhookEndpointId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + // Token + ListAllTokens(ctx context.Context, params *ListAllTokensParams, reqEditors ...RequestEditorFn) (*http.Response, error) + + RetrieveAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + EnableAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + DisableAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) + + DeleteAToken(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*http.Response, error) } // ClientWithResponsesInterface is the interface specification for the client with responses. @@ -335,4 +346,15 @@ type ClientWithResponsesInterface interface { UpdateAWebhookEndpointWithResponse(ctx context.Context, webhookEndpointId string, body UpdateAWebhookEndpointJSONRequestBody, reqEditors ...RequestEditorFn) (*UpdateAWebhookEndpointResponse, error) DeleteAWebhookEndpointWithResponse(ctx context.Context, webhookEndpointId string, reqEditors ...RequestEditorFn) (*DeleteAWebhookEndpointResponse, error) + + // Token + ListAllTokensWithResponse(ctx context.Context, params *ListAllTokensParams, reqEditors ...RequestEditorFn) (*ListAllTokensResponse, error) + + RetrieveATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*RetrieveATokenResponse, error) + + EnableATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*EnableATokenResponse, error) + + DisableATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*DisableATokenResponse, error) + + DeleteATokenWithResponse(ctx context.Context, tokenId string, reqEditors ...RequestEditorFn) (*DeleteATokenResponse, error) } diff --git a/tests/integration/tokenflow_test.go b/tests/integration/tokenflow_test.go index cfe92ab..be03ed4 100644 --- a/tests/integration/tokenflow_test.go +++ b/tests/integration/tokenflow_test.go @@ -50,25 +50,46 @@ func (suite *IntegrationTestSuite) TestCreateACheckoutSessionForAToken() { suite.NotNil(result.JSON200.Id) suite.NotNil(result.JSON200.TokenId) suite.EqualValues(string(*result.JSON200.TokenId), tokenId) - }) - suite.Run("TestRetrieveAToken", func() { + suite.Run("TestRetrieveAToken", func() { + result, err := suite.client.RetrieveATokenWithResponse(suite.ctx, tokenId) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + token, _ := ConvertToStruct[Token](result.JSON200) + suite.EqualValues(string(*token.Id), tokenId) + }) - }) + suite.Run("TestDisableAToken", func() { + result, err := suite.client.DisableATokenWithResponse(suite.ctx, tokenId) + suite.Nil(err) + suite.NotNil(result.Body) + suite.EqualValues(result.StatusCode(), 200) + }) - suite.Run("TestDisableAToken", func() { + suite.Run("TestEnableAToken", func() { + result, err := suite.client.EnableATokenWithResponse(suite.ctx, tokenId) + suite.Nil(err) + suite.NotNil(result.Body) + suite.EqualValues(result.StatusCode(), 200) + }) - }) - - suite.Run("TestEnableAToken", func() { + suite.Run("TestListAllTokens", func() { + params := ListAllTokensParams{} + result, err := suite.client.ListAllTokensWithResponse(suite.ctx, ¶ms) + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + obj, _ := ConvertToStruct[Token]((*result.JSON200.Data)[0]) + suite.NotNil(obj.Id) + }) + suite.Run("TestDeleteAToken", func() { + result, err := suite.client.DeleteATokenWithResponse(suite.ctx, tokenId) + suite.Nil(err) + suite.NotNil(result.Body) + suite.EqualValues(result.StatusCode(), 204) + }) }) - suite.Run("TestListAllTokens", func() { - - }) - - suite.Run("TestDeleteAToken", func() { - - }) } diff --git a/types.go b/types.go index b241484..c04e7d5 100644 --- a/types.go +++ b/types.go @@ -1488,3 +1488,12 @@ type CreateAWebhookEndpointJSONRequestBody WebhookEndpointCreate // UpdateAWebhookEndpointJSONRequestBody defines body for UpdateAWebhookEndpoint for application/json ContentType. type UpdateAWebhookEndpointJSONRequestBody WebhookEndpointUpdate + +// ListAllTokensParams defines parameters for ListAllTokens. +type ListAllTokensParams struct { + // Number of objects to return. Defaults to 20 if not set. + MaxResults *MaxResults `json:"maxResults,omitempty"` + + // The token for the page of the collection of objects. + PageToken *PageToken `json:"pageToken,omitempty"` +} From 6d1364d9b686bc441f46ff52bfdb404c7760e5e4 Mon Sep 17 00:00:00 2001 From: Ash Wu Date: Thu, 29 Dec 2022 11:56:54 +0800 Subject: [PATCH 4/4] Fix WebhookEndpoint type Signed-off-by: Ash Wu Signed-off-by: Ash Wu --- tests/integration/webhook_test.go | 9 ++++++--- types.go | 18 +++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/integration/webhook_test.go b/tests/integration/webhook_test.go index 7a1b178..b4701f0 100644 --- a/tests/integration/webhook_test.go +++ b/tests/integration/webhook_test.go @@ -19,14 +19,16 @@ func (suite *IntegrationTestSuite) TestCreateAWebhookEndpoint() { suite.NotNil(result.Body) suite.NotNil(result.JSON200) suite.NotNil(result.JSON200.Id) - webhookEndpointId := string((*result.JSON200).Id) + obj, _ := ConvertToStruct[WebhookEndpoint](result.JSON200) + webhookEndpointId := string(*obj.Id) suite.Run("TestRetrieveAWebhookEndpoint", func() { result, err := suite.client.RetrieveAWebhookEndpointWithResponse(suite.ctx, webhookEndpointId) suite.Nil(err) suite.NotNil(result.Body) suite.NotNil(result.JSON200) - suite.EqualValues(string((*result.JSON200).Id), webhookEndpointId) + obj, _ := ConvertToStruct[WebhookEndpoint](result.JSON200) + suite.EqualValues(string(*obj.Id), webhookEndpointId) }) suite.Run("TestUpdateAWebhookEndpoint", func() { @@ -40,7 +42,8 @@ func (suite *IntegrationTestSuite) TestCreateAWebhookEndpoint() { suite.Nil(err) suite.NotNil(result.Body) suite.NotNil(result.JSON200) - suite.EqualValues(string((*result.JSON200).Id), webhookEndpointId) + obj, _ := ConvertToStruct[WebhookEndpoint](result.JSON200) + suite.EqualValues(string(*obj.Id), webhookEndpointId) }) suite.Run("TestListAllWebhookEndpoints", func() { diff --git a/types.go b/types.go index c04e7d5..d3e1ed6 100644 --- a/types.go +++ b/types.go @@ -859,35 +859,35 @@ type UpdatedAt int // WebhookEndpoint defines model for webhookEndpoint. type WebhookEndpoint struct { // Has the value `true` if the webhook endpoint is active and events are sent to the url specified. Has the value `false if the endpoint is inactive and the events won't be sent to the url specified. - Active bool `json:"active"` + Active *bool `json:"active"` // Time at which the object was created. Measured in milliseconds since the Unix epoch. - CreatedAt CreatedAt `json:"createdAt"` + CreatedAt *CreatedAt `json:"createdAt"` // An optional description for your webhook endpoint. - Description string `json:"description"` + Description *string `json:"description"` // The list of events to subscribe to. If not specified you will be subsribed to all events. EventSubscriptions *[]EventSubscription `json:"eventSubscriptions,omitempty"` // The unique identifier for the Webhook Endpoint object. - Id WebhookEndpointId `json:"id"` + Id *WebhookEndpointId `json:"id"` // Set of up to 20 key-value pairs that you can attach to the object. Metadata *Metadata `json:"metadata,omitempty"` // A string representing the object’s type. The value is always `webhookEndpoint` for Webhook Endpoint objects. - Object string `json:"object"` - SigningSecret string `json:"signingSecret"` + Object *string `json:"object"` + SigningSecret *string `json:"signingSecret"` // A flag with a value `false` if the object exists in live mode or `true` if the object exists in test mode. - Test TestFlag `json:"test"` + Test *TestFlag `json:"test"` // The moment at which the object was last updated. Measured in milliseconds since the Unix epoch. - UpdatedAt UpdatedAt `json:"updatedAt"` + UpdatedAt *UpdatedAt `json:"updatedAt"` // The url which will be called when any of the events you subscribed to occur. - Url string `json:"url"` + Url *string `json:"url"` } // The unique identifier for the Webhook Endpoint object.