Skip to content
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
4 changes: 2 additions & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* text=auto

tests/cassettes/* -diff
tests/cassettes/* linguist-generated
cassettes/* -diff
cassettes/* linguist-generated
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## Next Release

- Adds the following functions:
- `CreateCustomerPortalAccountLink`
- `CreateEmbeddablesSession`

## v5.4.0 (2025-11-10)

- Adds support for `UspsShipAccount`
Expand Down
112 changes: 112 additions & 0 deletions cassettes/TestCreateCustomerPortalAccountLink.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 112 additions & 0 deletions cassettes/TestCreateEmbeddablesSession.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions customer_portal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package easypost

import (
"context"
"net/http"
)

// A CustomerPortalAccountLink object represents an object containing an AccountLink.
type CustomerPortalAccountLink struct {
Object string `json:"object,omitempty" url:"object,omitempty"`
Link string `json:"link,omitempty" url:"link,omitempty"`
CreatedAt *DateTime `json:"created_at,omitempty" url:"created_at,omitempty"`
ExpiresAt *DateTime `json:"expires_at,omitempty" url:"expires_at,omitempty"`
}

// CustomerPortalAccountLinkParameters is used to specify parameters for creating an AccountLink.
type CustomerPortalAccountLinkParameters struct {
SessionType string `json:"session_type,omitempty" url:"session_type,omitempty"`
UserId string `json:"user_id,omitempty" url:"user_id,omitempty"`
RefreshUrl string `json:"refresh_url,omitempty" url:"refresh_url,omitempty"`
ReturnUrl string `json:"return_url,omitempty" url:"return_url,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty" url:"metadata,omitempty"`
}

// CreateCustomerPortalAccountLink generates a one-time Customer Portal URL.
func (c *Client) CreateCustomerPortalAccountLink(in *CustomerPortalAccountLinkParameters) (out *CustomerPortalAccountLink, err error) {
return c.CreateCustomerPortalAccountLinkWithContext(context.Background(), in)
}

// CreateCustomerPortalAccountLinkWithContext performs the same operation as CreateCustomerPortalAccountLink, but allows specifying a context that can interrupt the request.
func (c *Client) CreateCustomerPortalAccountLinkWithContext(ctx context.Context, in *CustomerPortalAccountLinkParameters) (out *CustomerPortalAccountLink, err error) {
err = c.do(ctx, http.MethodPost, "customer_portal/account_link", in, &out)
return
}
25 changes: 25 additions & 0 deletions customer_portal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package easypost

func (c *ClientTests) TestCreateCustomerPortalAccountLink() {
client := c.ProdClient()
assert, require := c.Assert(), c.Require()

childUsers, err := client.ListChildUsers(
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
require.NoError(err)

accountLink, err := client.CreateCustomerPortalAccountLink(
&CustomerPortalAccountLinkParameters{
SessionType: "account_onboarding",
UserId: childUsers.Children[0].ID,
RefreshUrl: "https://example.com/refresh",
ReturnUrl: "https://example.com/return",
},
)
require.NoError(err)

assert.Equal("CustomerPortalAccountLink", accountLink.Object)
}
31 changes: 31 additions & 0 deletions embeddable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package easypost

import (
"context"
"net/http"
)

// A EmbeddablesSession object represents an object containing an AccountLink.
type EmbeddablesSession struct {
Object string `json:"object,omitempty" url:"object,omitempty"`
SessionId string `json:"session_id,omitempty" url:"session_id,omitempty"`
CreatedAt *DateTime `json:"created_at,omitempty" url:"created_at,omitempty"`
ExpiresAt *DateTime `json:"expires_at,omitempty" url:"expires_at,omitempty"`
}

// EmbeddablesSessionParameters is used to specify parameters for creating an AccountLink.
type EmbeddablesSessionParameters struct {
OriginHost string `json:"origin_host,omitempty" url:"origin_host,omitempty"`
UserId string `json:"user_id,omitempty" url:"user_id,omitempty"`
}

// CreateEmbeddablesSession creates a temporary session for initializing embeddable components.
func (c *Client) CreateEmbeddablesSession(in *EmbeddablesSessionParameters) (out *EmbeddablesSession, err error) {
return c.CreateEmbeddablesSessionWithContext(context.Background(), in)
}

// CreateEmbeddablesSessionWithContext performs the same operation as CreateEmbeddablesSession, but allows specifying a context that can interrupt the request.
func (c *Client) CreateEmbeddablesSessionWithContext(ctx context.Context, in *EmbeddablesSessionParameters) (out *EmbeddablesSession, err error) {
err = c.do(ctx, http.MethodPost, "embeddables/session", in, &out)
return
}
23 changes: 23 additions & 0 deletions embeddable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package easypost

func (c *ClientTests) TestCreateEmbeddablesSession() {
client := c.ProdClient()
assert, require := c.Assert(), c.Require()

childUsers, err := client.ListChildUsers(
&ListOptions{
PageSize: c.fixture.pageSize(),
},
)
require.NoError(err)

session, err := client.CreateEmbeddablesSession(
&EmbeddablesSessionParameters{
OriginHost: "https://example.com",
UserId: childUsers.Children[0].ID,
},
)
require.NoError(err)

assert.Equal("EmbeddablesSession", session.Object)
}
Loading