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

Modify checkoutSession for token response based on API change #6

Merged
merged 2 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
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