Skip to content

Commit f8c8263

Browse files
committed
Parse the new error_report value from the user pro status endpoint
1 parent 78dc032 commit f8c8263

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

include/session/pro_backend.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ typedef enum SESSION_PRO_BACKEND_USER_PRO_STATUS {
5555
SESSION_PRO_BACKEND_USER_PRO_STATUS_COUNT,
5656
} SESSION_PRO_BACKEND_USER_PRO_STATUS;
5757

58+
typedef enum SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT {
59+
SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_SUCCESS,
60+
SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_GENERIC_ERROR,
61+
SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_COUNT,
62+
} SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT;
63+
64+
5865
/// Bundle of hard-coded URLs that an application may want to redirect users to in various
5966
/// scenarios.
6067
typedef struct session_pro_urls session_pro_urls;
@@ -277,6 +284,7 @@ struct session_pro_backend_get_pro_status_response {
277284
session_pro_backend_pro_payment_item* items;
278285
size_t items_count;
279286
SESSION_PRO_BACKEND_USER_PRO_STATUS status;
287+
SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT error_report;
280288
bool auto_renewing;
281289
uint64_t expiry_unix_ts_ms;
282290
uint64_t grace_period_duration_ms;

include/session/pro_backend.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,11 @@ struct GetProStatusResponse : public ResponseHeader {
381381
/// Current Session Pro entitlement status for the master public key
382382
SESSION_PRO_BACKEND_USER_PRO_STATUS user_status;
383383

384+
/// Error code that indicates that the Session Pro Backend encountered an error book-keeping
385+
/// Session Pro entitlement for the user. If this value is not `SUCCESS` implementing clients
386+
/// can optionally prompt the user that they should contact support for investigation.
387+
SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT error_report;
388+
384389
/// Flag to indicate if the user will automatically renew their subscription.
385390
bool auto_renewing;
386391

src/pro_backend.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,15 @@ GetProStatusResponse GetProStatusResponse::parse(std::string_view json) {
455455
return result;
456456
}
457457
result.user_status = static_cast<SESSION_PRO_BACKEND_USER_PRO_STATUS>(user_status);
458+
459+
uint32_t error_report = json_require<uint32_t>(result_obj, "error_report", result.errors);
460+
if (error_report >= SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_COUNT) {
461+
result.errors.push_back(
462+
fmt::format("Error report value was out-of-bounds: {}", user_status));
463+
return result;
464+
}
465+
result.error_report = static_cast<SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT>(error_report);
466+
458467
result.auto_renewing = json_require<bool>(result_obj, "auto_renewing", result.errors);
459468

460469
uint64_t expiry_unix_ts_ms =
@@ -954,6 +963,7 @@ session_pro_backend_get_pro_status_response_parse(const char* json, size_t json_
954963
// Copy to C struct, this is guaranteed not to fail because we pre-allocated memory upfront.
955964
result.header.status = cpp.status;
956965
result.status = cpp.user_status;
966+
result.error_report = cpp.error_report;
957967
result.items_count = cpp.items.size();
958968
result.items = (session_pro_backend_pro_payment_item*)arena_alloc(
959969
&arena, result.items_count * sizeof(*result.items));

tests/test_pro_backend.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ TEST_CASE("Session Pro Backend C API", "[session_pro_backend]") {
548548
j["status"] = SESSION_PRO_BACKEND_STATUS_SUCCESS;
549549
j["result"] = {
550550
{"status", SESSION_PRO_BACKEND_USER_PRO_STATUS_EXPIRED},
551+
{"error_report", SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_GENERIC_ERROR},
551552
{"auto_renewing", true},
552553
{"expiry_unix_ts_ms", unix_ts_ms + 2},
553554
{"grace_period_duration_ms", 1000},
@@ -582,6 +583,8 @@ TEST_CASE("Session Pro Backend C API", "[session_pro_backend]") {
582583
REQUIRE(result.header.errors_count == 0);
583584
REQUIRE(result.header.errors == nullptr);
584585
REQUIRE(result.status == SESSION_PRO_BACKEND_USER_PRO_STATUS_EXPIRED);
586+
REQUIRE(result.error_report ==
587+
SESSION_PRO_BACKEND_GET_PRO_STATUS_ERROR_REPORT_GENERIC_ERROR);
585588
REQUIRE(result.items_count == 1);
586589
REQUIRE(result.auto_renewing == true);
587590
REQUIRE(result.grace_period_duration_ms == 1000);

0 commit comments

Comments
 (0)