diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c220414..2f1b3f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,8 @@ -on: [push, pull_request] +on: + pull_request: + push: + branches: + - main name: Test jobs: test: @@ -13,6 +17,8 @@ jobs: - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} + check-latest: true + cache: true - run: go mod verify - run: go build -v ./... - run: go vet ./... diff --git a/tests/integration/checkout_test.go b/tests/integration/checkout_test.go index aca3a9d..77565c3 100644 --- a/tests/integration/checkout_test.go +++ b/tests/integration/checkout_test.go @@ -42,6 +42,7 @@ func (suite *IntegrationTestSuite) TestCreateACheckOutSession() { suite.NotNil(result.JSON200) checkoutSession, _ := ConvertToStruct[CheckoutSessionExpanded](result.JSON200) + suite.Equal(*checkoutSession.Order.Object, "order") suite.Equal(string(*checkoutSession.Id), suite.checkoutSessionId) }) diff --git a/tests/integration/tokenflow_test.go b/tests/integration/tokenflow_test.go index be03ed4..b519060 100644 --- a/tests/integration/tokenflow_test.go +++ b/tests/integration/tokenflow_test.go @@ -16,6 +16,7 @@ func (suite *IntegrationTestSuite) TestCreateACheckoutSessionForAToken() { suite.NotNil(result.Body) suite.NotNil(result.JSON200) suite.NotNil(result.JSON200.Token.Id) + checkoutSessionId := string(*result.JSON200.Id) tokenId := string(*result.JSON200.Token.Id) // Authorize the Token @@ -24,6 +25,33 @@ func (suite *IntegrationTestSuite) TestCreateACheckoutSessionForAToken() { panic(err) } + suite.Run("TestRetrieveACheckOutSessionForToken", func() { + params := RetrieveACheckoutSessionParams{} + result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, checkoutSessionId, ¶ms) + + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + + checkoutSession, _ := ConvertToStruct[CheckoutSession](result.JSON200) + suite.Equal(string(*checkoutSession.Token), tokenId) + }) + + suite.Run("TestRetrieveACheckOutSessionForTokenExpanded", func() { + params := RetrieveACheckoutSessionParams{ + Expand: Ptr(RetrieveACheckoutSessionParamsExpand(ExpandAll)), + } + result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, checkoutSessionId, ¶ms) + + suite.Nil(err) + suite.NotNil(result.Body) + suite.NotNil(result.JSON200) + + checkoutSession, _ := ConvertToStruct[CheckoutSessionExpanded](result.JSON200) + suite.Equal(*checkoutSession.Token.Object, "token") + suite.Equal(string(*checkoutSession.Token.Id), tokenId) + }) + suite.Run("TestCreateAnOrderUsingAToken", func() { payload := CreateAnOrderUsingATokenJSONRequestBody{ Currency: CurrencyJPY, diff --git a/types.go b/types.go index d3e1ed6..883f55b 100644 --- a/types.go +++ b/types.go @@ -67,6 +67,9 @@ type CheckoutSession struct { // The unique identifier for the Payment object. Order *OrderId `json:"order,omitempty"` + // The unique identifier for the Token object. + Token *TokenId `json:"token,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,omitempty"` @@ -100,9 +103,12 @@ type CheckoutSessionExpanded struct { // A string representing the object’s type. The value is always `checkoutSession` for Checkout Session objects. Object *string `json:"object,omitempty"` - // The unique identifier for the Payment object. + // Expanded Order Order *OrderExpanded `json:"order,omitempty"` + // A Payment token + Token *Token `json:"token,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,omitempty"` @@ -114,9 +120,6 @@ 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.