Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sc-8280] token flow support #5

Merged
merged 4 commits into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,095 changes: 1,008 additions & 87 deletions api.go

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -235,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.
Expand All @@ -244,8 +261,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
Expand All @@ -264,6 +285,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)
Expand Down Expand Up @@ -321,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)
}
16 changes: 15 additions & 1 deletion const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
130 changes: 65 additions & 65 deletions tests/integration/checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
suite.Run("TestRetrieveACheckOutSession", func() {
//suite.T().Skip()
params := RetrieveACheckoutSessionParams{}
result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, suite.checkoutSessionId, &params)

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, &params)
suite.Run("TestRetrieveACheckOutSessionExpanded", func() {
//suite.T().Skip()
params := RetrieveACheckoutSessionParams{
Expand: Ptr(RetrieveACheckoutSessionParamsExpand(ExpandAll)),
}
result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, suite.checkoutSessionId, &params)

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, &params)
suite.Run("TestListAllCheckoutSession", func() {
//suite.T().Skip()
params := ListAllCheckoutSessionsParams{}
result, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, &params)

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, &params)
suite.Run("TestListAllCheckoutSessionExpanded", func() {
//suite.T().Skip()
params := ListAllCheckoutSessionsParams{
Expand: Ptr(ListAllCheckoutSessionsParamsExpand(ExpandAll)),
}
result, err := suite.client.ListAllCheckoutSessionsWithResponse(suite.ctx, &params)

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)
})
}
Loading