Skip to content

Commit 5b3e4e7

Browse files
authored
Merge pull request #634 from EasyPost/SHPE-594_sessions
feat: add portal and embeddable sessions
2 parents 93aa101 + 80c5f5a commit 5b3e4e7

File tree

14 files changed

+532
-6
lines changed

14 files changed

+532
-6
lines changed

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+
- `CustomerPortal.CreateAccountLink`
7+
- `Embeddable.CreateSession`
8+
39
## v7.3.0 (2025-11-10)
410

511
- Adds support for `UspsShipAccount`

EasyPost.Integration/TestUtils.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ public class Utils
1212

1313
private static readonly List<string> BodyCensors =
1414
[
15-
"api_keys",
16-
"children",
1715
"client_ip",
1816
"credentials",
1917
"email",
18+
"fields",
2019
"key",
21-
"keys",
2220
"phone_number",
2321
"phone",
2422
"test_credentials"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using EasyPost.Models.API;
5+
using EasyPost.Parameters.CustomerPortal;
6+
using EasyPost.Parameters.User;
7+
using EasyPost.Tests._Utilities;
8+
using EasyPost.Tests._Utilities.Attributes;
9+
using EasyPost.Utilities.Internal.Attributes;
10+
using Xunit;
11+
12+
namespace EasyPost.Tests.ServicesTests.WithParameters
13+
{
14+
public class CustomerPortalServiceTests : UnitTest
15+
{
16+
public CustomerPortalServiceTests() : base("customer_portal_service_with_parameters", TestUtils.ApiKey.Production)
17+
{
18+
}
19+
20+
#region Tests
21+
22+
#region Test CRUD Operations
23+
24+
[Fact]
25+
[CrudOperations.Read]
26+
[Testing.Function]
27+
public async Task TestCreateAccountLink()
28+
{
29+
UseVCR("create_account_link");
30+
31+
Dictionary<string, object> fixture = new Dictionary<string, object> { { "page_size", Fixtures.PageSize } };
32+
AllChildren childrenParameters = Fixtures.Parameters.Users.AllChildren(fixture);
33+
ChildUserCollection childUserCollection = await Client.User.AllChildren(childrenParameters);
34+
35+
Parameters.CustomerPortal.CreateAccountLink parameters = new()
36+
{
37+
SessionType = "account_onboarding",
38+
UserId = childUserCollection.Children[0].Id,
39+
RefreshUrl = "https://example.com/refresh",
40+
ReturnUrl = "https://example.com/return",
41+
};
42+
CustomerPortalAccountLink accountLink = await Client.CustomerPortal.CreateAccountLink(parameters);
43+
44+
Assert.IsType<CustomerPortalAccountLink>(accountLink);
45+
}
46+
47+
#endregion
48+
49+
#endregion
50+
}
51+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
using EasyPost.Models.API;
5+
using EasyPost.Parameters.Embeddable;
6+
using EasyPost.Parameters.User;
7+
using EasyPost.Tests._Utilities;
8+
using EasyPost.Tests._Utilities.Attributes;
9+
using EasyPost.Utilities.Internal.Attributes;
10+
using Xunit;
11+
12+
namespace EasyPost.Tests.ServicesTests.WithParameters
13+
{
14+
public class EmbeddableServiceTests : UnitTest
15+
{
16+
public EmbeddableServiceTests() : base("embeddable_service_with_parameters", TestUtils.ApiKey.Production)
17+
{
18+
}
19+
20+
#region Tests
21+
22+
#region Test CRUD Operations
23+
24+
[Fact]
25+
[CrudOperations.Read]
26+
[Testing.Function]
27+
public async Task TestCreateSession()
28+
{
29+
UseVCR("create_session");
30+
31+
Dictionary<string, object> fixture = new Dictionary<string, object> { { "page_size", Fixtures.PageSize } };
32+
AllChildren childrenParameters = Fixtures.Parameters.Users.AllChildren(fixture);
33+
ChildUserCollection childUserCollection = await Client.User.AllChildren(childrenParameters);
34+
35+
Parameters.Embeddable.CreateSession parameters = new()
36+
{
37+
OriginHost = "https://example.com",
38+
UserId = childUserCollection.Children[0].Id,
39+
};
40+
EmbeddablesSession session = await Client.Embeddable.CreateSession(parameters);
41+
42+
Assert.IsType<EmbeddablesSession>(session);
43+
}
44+
45+
#endregion
46+
47+
#endregion
48+
}
49+
}

EasyPost.Tests/TestUtils.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ public class TestUtils
2323

2424
private static readonly List<string> BodyCensors =
2525
[
26-
"api_keys",
27-
"children",
2826
"client_ip",
2927
"credentials",
3028
"email",
29+
"fields",
3130
"key",
32-
"keys",
3331
"phone_number",
3432
"phone",
3533
"test_credentials"

EasyPost.Tests/cassettes/net/customer_portal_service_with_parameters/create_account_link.json

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

EasyPost.Tests/cassettes/net/embeddable_service_with_parameters/create_session.json

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

EasyPost/Client.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ public class Client : EasyPostClient
5353
/// </summary>
5454
public ClaimService Claim => new ClaimService(this);
5555

56+
/// <summary>
57+
/// Access CustomerPortal-related functionality.
58+
/// </summary>
59+
public CustomerPortalService CustomerPortal => new CustomerPortalService(this);
60+
5661
/// <summary>
5762
/// Access Customs Info-related functionality.
5863
/// </summary>
@@ -63,6 +68,11 @@ public class Client : EasyPostClient
6368
/// </summary>
6469
public CustomsItemService CustomsItem => new CustomsItemService(this);
6570

71+
/// <summary>
72+
/// Access Embeddable-related functionality.
73+
/// </summary>
74+
public EmbeddableService Embeddable => new EmbeddableService(this);
75+
6676
/// <summary>
6777
/// Access EndShipper-related functionality.
6878
/// </summary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using EasyPost._base;
2+
using Newtonsoft.Json;
3+
4+
namespace EasyPost.Models.API
5+
{
6+
/// <summary>
7+
/// Class representing a CustomerPortalAccountLink.
8+
/// </summary>
9+
public class CustomerPortalAccountLink : EphemeralEasyPostObject
10+
{
11+
#region JSON Properties
12+
13+
/// <summary>
14+
/// One-time-use session URL for initiating the Customer Portal.
15+
/// </summary>
16+
[JsonProperty("link")]
17+
public string? Link { get; set; }
18+
19+
/// <summary>
20+
/// One-time-use session URL for initiating the Customer Portal.
21+
/// </summary>
22+
[JsonProperty("created_at")]
23+
public string? CreatedAt { get; set; }
24+
25+
/// <summary>
26+
/// ISO 8601 timestamp when the link will expire (5 minutes from creation).
27+
/// </summary>
28+
[JsonProperty("expires_at")]
29+
public string? ExpiresAt { get; set; }
30+
31+
#endregion
32+
}
33+
}

0 commit comments

Comments
 (0)