Skip to content

Commit 9b6fd0a

Browse files
committed
fix: Support message_id flow for purchases
1 parent 62a9d1d commit 9b6fd0a

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

build.cmd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
@echo off
22

33
set target=%1
4+
set verbostity=%2
45
if "%target%" == "" set target=Default
6+
if "%verbostity%" == "" set verbostity=Minimal
57

68
cd build\apps\build
79

8-
dotnet run --target %target%
10+
dotnet run --target %target% --verbostity %verbostity%

libs/SailthruSDK/Purchase/SailthruPurchaseExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ public static async Task<SailthruResponse> UpsertPurchaseAsync(
1313
string email,
1414
PurchaseItem[] items,
1515
bool incomplete = false,
16+
string? messageId = default,
1617
CancellationToken cancellationToken = default)
1718
{
1819
Ensure.IsNotNull(client, nameof(client));
1920

20-
var model = new UpsertPurchaseRequest(email, items, incomplete);
21+
var model = new UpsertPurchaseRequest(email, items, incomplete, messageId);
2122
var request = new SailthruRequest<UpsertPurchaseRequest>(
2223
HttpMethod.Post,
2324
SailthruEndpoints.Purchase,

libs/SailthruSDK/Purchase/UpsertPurchaseRequest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@ public class UpsertPurchaseRequest
1616
/// <param name="email">The user email address</param>
1717
/// <param name="items">The set of items.</param>
1818
/// <param name="incomplete">Specifies whether the purchase is incomplete (e.g. an active cart, not an order)</param>
19+
/// <param name="messageId">The message ID representing the email campaign. This is usually stored in the sailthru_bid cookie.</param>
1920
public UpsertPurchaseRequest(
2021
string email,
2122
PurchaseItem[] items,
22-
bool incomplete = false)
23+
bool incomplete = false,
24+
string? messageId = default)
2325
{
2426
Email = Ensure.IsNotNullOrEmpty(email, nameof(email));
2527
Items = Ensure.IsNotNull(items, nameof(items));
2628
Incomplete = incomplete;
29+
MessageId = messageId;
2730
}
2831

2932
/// <summary>
@@ -41,6 +44,11 @@ public UpsertPurchaseRequest(
4144
/// </summary>
4245
public PurchaseItem[] Items { get; }
4346

47+
/// <summary>
48+
/// Gets the message campaign ID. This is usually stored in the sailthru_bid cookie.
49+
/// </summary>
50+
public string? MessageId { get; }
51+
4452
internal class Convereter : ConverterBase<UpsertPurchaseRequest>
4553
{
4654
/// <inhertdoc />
@@ -62,6 +70,7 @@ public override void Write(Utf8JsonWriter writer, UpsertPurchaseRequest value, J
6270

6371
writer.WriteStringProperty("email", value.Email, options);
6472
writer.WriteBooleanProperty("incomplete", value.Incomplete, options);
73+
writer.WriteStringProperty("message_id", value.MessageId ?? "", options);
6574

6675
writer.WritePropertyName("items");
6776
writer.WriteStartArray();

samples/SailthruSDK.Samples.Console/Program.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,24 @@ static async Task Main()
3636
//);
3737

3838
//var user = await client.UpsertUserAsync(
39-
40-
// optOutEmailStatus: OptOutStatus.All,
39+
4140
// keys: new Map<string>
4241
// {
4342
// [SailthruUserKeyType.Email] = "[email protected]"
4443
// },
4544
// keyConflict: KeyConflict.Merge,
46-
// fields: new SailthruUserFields
45+
// cookies: new Map<string>
4746
// {
48-
// Activity = true,
49-
// Engagement = true,
50-
// Device = true,
51-
// Keys = true,
52-
// Lists = true,
53-
// Lifetime = true,
54-
// OptOutStatus = true,
55-
// PurchaseIncomplete = 10,
56-
// Purchases = 10,
57-
// SmartLists = true,
58-
// Vars = true
47+
// ["sailthru_bid"] = "28309054.31001"
5948
// });
6049

6150
var response = await client.UpsertPurchaseAsync(
62-
"me+spaseekers@matthewabbott.dev",
51+
"me+sailthru@matthewabbott.dev",
6352
new[] {
6453
new PurchaseItem("MonetaryVoucher-50", "£50.00 - Voucher", 5000, 1, "https://www.spaseekers.com/spa-vouchers?value=50.00")
6554
},
66-
incomplete: false
55+
incomplete: false,
56+
messageId: "28309054.31001"
6757
);
6858
}
6959

0 commit comments

Comments
 (0)