Skip to content

Commit

Permalink
Modify checkoutSession for token response based on API change (#6)
Browse files Browse the repository at this point in the history
* Modify checkoutSession for token response based on API change

* Fix checks run twice in PR

Signed-off-by: Ash Wu <hsatac@gmail.com>
  • Loading branch information
hSATAC committed Jan 4, 2023
1 parent 1174ec0 commit 80fbe5e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
on: [push, pull_request]
on:
pull_request:
push:
branches:
- main
name: Test
jobs:
test:
Expand All @@ -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 ./...
Expand Down
1 change: 1 addition & 0 deletions tests/integration/checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
28 changes: 28 additions & 0 deletions tests/integration/tokenflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,6 +25,33 @@ func (suite *IntegrationTestSuite) TestCreateACheckoutSessionForAToken() {
panic(err)
}

suite.Run("TestRetrieveACheckOutSessionForToken", func() {
params := RetrieveACheckoutSessionParams{}
result, err := suite.client.RetrieveACheckoutSessionWithResponse(suite.ctx, checkoutSessionId, &params)

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, &params)

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,
Expand Down
11 changes: 7 additions & 4 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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"`

Expand All @@ -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.
Expand Down

0 comments on commit 80fbe5e

Please sign in to comment.