Skip to content

Commit a3c66fa

Browse files
authored
Merge pull request #265 from EasyPost/SHPE-594_sessions
feat: portal and embeddables sessions
2 parents 8305aa8 + aac691e commit a3c66fa

File tree

8 files changed

+345
-2
lines changed

8 files changed

+345
-2
lines changed

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
* text=auto
22

3-
tests/cassettes/* -diff
4-
tests/cassettes/* linguist-generated
3+
cassettes/* -diff
4+
cassettes/* linguist-generated

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## Next Release
4+
5+
- Adds the following functions:
6+
- `CreateCustomerPortalAccountLink`
7+
- `CreateEmbeddablesSession`
8+
39
## v5.4.0 (2025-11-10)
410

511
- Adds support for `UspsShipAccount`

cassettes/TestCreateCustomerPortalAccountLink.yaml

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cassettes/TestCreateEmbeddablesSession.yaml

Lines changed: 112 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

customer_portal.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package easypost
2+
3+
import (
4+
"context"
5+
"net/http"
6+
)
7+
8+
// A CustomerPortalAccountLink object represents an object containing an AccountLink.
9+
type CustomerPortalAccountLink struct {
10+
Object string `json:"object,omitempty" url:"object,omitempty"`
11+
Link string `json:"link,omitempty" url:"link,omitempty"`
12+
CreatedAt *DateTime `json:"created_at,omitempty" url:"created_at,omitempty"`
13+
ExpiresAt *DateTime `json:"expires_at,omitempty" url:"expires_at,omitempty"`
14+
}
15+
16+
// CustomerPortalAccountLinkParameters is used to specify parameters for creating an AccountLink.
17+
type CustomerPortalAccountLinkParameters struct {
18+
SessionType string `json:"session_type,omitempty" url:"session_type,omitempty"`
19+
UserId string `json:"user_id,omitempty" url:"user_id,omitempty"`
20+
RefreshUrl string `json:"refresh_url,omitempty" url:"refresh_url,omitempty"`
21+
ReturnUrl string `json:"return_url,omitempty" url:"return_url,omitempty"`
22+
Metadata map[string]interface{} `json:"metadata,omitempty" url:"metadata,omitempty"`
23+
}
24+
25+
// CreateCustomerPortalAccountLink generates a one-time Customer Portal URL.
26+
func (c *Client) CreateCustomerPortalAccountLink(in *CustomerPortalAccountLinkParameters) (out *CustomerPortalAccountLink, err error) {
27+
return c.CreateCustomerPortalAccountLinkWithContext(context.Background(), in)
28+
}
29+
30+
// CreateCustomerPortalAccountLinkWithContext performs the same operation as CreateCustomerPortalAccountLink, but allows specifying a context that can interrupt the request.
31+
func (c *Client) CreateCustomerPortalAccountLinkWithContext(ctx context.Context, in *CustomerPortalAccountLinkParameters) (out *CustomerPortalAccountLink, err error) {
32+
err = c.do(ctx, http.MethodPost, "customer_portal/account_link", in, &out)
33+
return
34+
}

customer_portal_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package easypost
2+
3+
func (c *ClientTests) TestCreateCustomerPortalAccountLink() {
4+
client := c.ProdClient()
5+
assert, require := c.Assert(), c.Require()
6+
7+
childUsers, err := client.ListChildUsers(
8+
&ListOptions{
9+
PageSize: c.fixture.pageSize(),
10+
},
11+
)
12+
require.NoError(err)
13+
14+
accountLink, err := client.CreateCustomerPortalAccountLink(
15+
&CustomerPortalAccountLinkParameters{
16+
SessionType: "account_onboarding",
17+
UserId: childUsers.Children[0].ID,
18+
RefreshUrl: "https://example.com/refresh",
19+
ReturnUrl: "https://example.com/return",
20+
},
21+
)
22+
require.NoError(err)
23+
24+
assert.Equal("CustomerPortalAccountLink", accountLink.Object)
25+
}

embeddable.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package easypost
2+
3+
import (
4+
"context"
5+
"net/http"
6+
)
7+
8+
// A EmbeddablesSession object represents an object containing an AccountLink.
9+
type EmbeddablesSession struct {
10+
Object string `json:"object,omitempty" url:"object,omitempty"`
11+
SessionId string `json:"session_id,omitempty" url:"session_id,omitempty"`
12+
CreatedAt *DateTime `json:"created_at,omitempty" url:"created_at,omitempty"`
13+
ExpiresAt *DateTime `json:"expires_at,omitempty" url:"expires_at,omitempty"`
14+
}
15+
16+
// EmbeddablesSessionParameters is used to specify parameters for creating an AccountLink.
17+
type EmbeddablesSessionParameters struct {
18+
OriginHost string `json:"origin_host,omitempty" url:"origin_host,omitempty"`
19+
UserId string `json:"user_id,omitempty" url:"user_id,omitempty"`
20+
}
21+
22+
// CreateEmbeddablesSession creates a temporary session for initializing embeddable components.
23+
func (c *Client) CreateEmbeddablesSession(in *EmbeddablesSessionParameters) (out *EmbeddablesSession, err error) {
24+
return c.CreateEmbeddablesSessionWithContext(context.Background(), in)
25+
}
26+
27+
// CreateEmbeddablesSessionWithContext performs the same operation as CreateEmbeddablesSession, but allows specifying a context that can interrupt the request.
28+
func (c *Client) CreateEmbeddablesSessionWithContext(ctx context.Context, in *EmbeddablesSessionParameters) (out *EmbeddablesSession, err error) {
29+
err = c.do(ctx, http.MethodPost, "embeddables/session", in, &out)
30+
return
31+
}

embeddable_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package easypost
2+
3+
func (c *ClientTests) TestCreateEmbeddablesSession() {
4+
client := c.ProdClient()
5+
assert, require := c.Assert(), c.Require()
6+
7+
childUsers, err := client.ListChildUsers(
8+
&ListOptions{
9+
PageSize: c.fixture.pageSize(),
10+
},
11+
)
12+
require.NoError(err)
13+
14+
session, err := client.CreateEmbeddablesSession(
15+
&EmbeddablesSessionParameters{
16+
OriginHost: "https://example.com",
17+
UserId: childUsers.Children[0].ID,
18+
},
19+
)
20+
require.NoError(err)
21+
22+
assert.Equal("EmbeddablesSession", session.Object)
23+
}

0 commit comments

Comments
 (0)