1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, QueryBuilder, RequestOptions};
use reqwest::Method;
pub struct MembershipsClient {
pub http_client: HttpClient,
}
impl MembershipsClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Lists every membership the caller can read: an account API key its account's; a user credential their own plus those of every account they manage. `account_id` and `user_id` only narrow that list — values outside the caller's reach return fewer results, not an error.
///
/// # Arguments
///
/// * `account_id` - Narrow to one account (`biz_` tag). With read access to the account this lists all of its memberships; without, only the caller's own memberships in it.
/// * `user_id` - Narrow to one user's memberships (`user_` tag, or `me` for the caller). A user outside the caller's visible set returns an empty list.
/// * `status` - Filter by billing state. `canceling` matches active memberships set to cancel at period end; `paused` matches memberships with payment collection paused.
/// * `product_id` - Filter to memberships of this product (`prod_` tag). Repeat as product_ids[] for several.
/// * `plan_id` - Filter to memberships of this plan (`plan_` tag). Repeat as plan_ids[] for several.
/// * `created_after` - Only memberships created after this ISO 8601 timestamp.
/// * `created_before` - Only memberships created before this ISO 8601 timestamp.
/// * `order` - Sort field.
/// * `direction` - Sort direction.
/// * `first` - Number of memberships to return from the start of the window.
/// * `after` - Cursor to paginate forwards from.
/// * `last` - Number of memberships to return from the end of the window.
/// * `before` - Cursor to paginate backwards from.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .list(
/// &MembershipsListQueryRequest {
/// ..Default::default()
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn list(
&self,
request: &MembershipsListQueryRequest,
options: Option<RequestOptions>,
) -> Result<ListMembershipsResponse, ApiError> {
self.http_client
.execute_request(
Method::GET,
"memberships",
None,
QueryBuilder::new()
.string("account_id", request.account_id.clone())
.string("user_id", request.user_id.clone())
.serialize("status", request.status.clone())
.string("product_id", request.product_id.clone())
.string("plan_id", request.plan_id.clone())
.string("created_after", request.created_after.clone())
.string("created_before", request.created_before.clone())
.serialize("order", request.order.clone())
.serialize("direction", request.direction.clone())
.int("first", request.first.clone())
.string("after", request.after.clone())
.int("last", request.last.clone())
.string("before", request.before.clone())
.build(),
options,
)
.await
}
/// Sends an email inviting one recipient to join the account through a free plan. Identify the recipient by exactly one of `user_id` or `email`. The invitation is bound to that recipient; after signing in, accepting it immediately grants the membership without checkout. This Experimental endpoint is available only to accounts enabled for membership invitations.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .invite(
/// &InviteMembershipsRequestBody::InviteMembershipsRequestBodyUserID(
/// InviteMembershipsRequestBodyUserID {
/// plan_id: "plan_xxxxxxxxxxxxxx".to_string(),
/// user_id: "user_xxxxxxxxxxxxxx".to_string(),
/// ..Default::default()
/// },
/// ),
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn invite(
&self,
request: &InviteMembershipsRequestBody,
options: Option<RequestOptions>,
) -> Result<InviteMembershipsResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"memberships/invite",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Retrieves a membership by ID or license key. Accessible to the account and to the membership's own user.
///
/// # Arguments
///
/// * `id` - Membership ID (`mem_` tag), or a software license key.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client.memberships.retrieve(&"id".to_string(), None).await;
/// }
/// ```
pub async fn retrieve(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::GET,
&format!("memberships/{}", id),
None,
None,
options,
)
.await
}
/// Updates a membership: merge metadata key-value pairs, or toggle `cancel_at_period_end` — `true` schedules the cancellation for the end of the current billing period, `false` reverses a pending one.
///
/// # Arguments
///
/// * `id` - Membership ID (`mem_` tag), or a software license key.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .update(
/// &"id".to_string(),
/// &UpdateMembershipsRequest {
/// ..Default::default()
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn update(
&self,
id: &str,
request: &UpdateMembershipsRequest,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::PATCH,
&format!("memberships/{}", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Add free days to extend a membership's current billing period, expiration date, or Stripe trial.
///
/// Required permissions:
/// - `member:manage`
/// - `member:email:read`
/// - `member:basic:read`
///
/// # Arguments
///
/// * `id` - The unique identifier of the membership.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .add_free_days_membership(
/// &"mem_xxxxxxxxxxxxxx".to_string(),
/// &AddFreeDaysMembershipRequest { free_days: 42 },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn add_free_days_membership(
&self,
id: &str,
request: &AddFreeDaysMembershipRequest,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/add_free_days", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Cancels a membership. Pass `cancel_at_period_end: true` to stop auto-renewal and keep access until the current billing period ends. Omit it (or pass `false`) to revoke access immediately. Buyers cannot cancel buy-now-pay-later (`splitit`, `sezzle`) or non-trial split-pay memberships.
///
/// # Arguments
///
/// * `id` - Membership ID (`mem_` tag).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .cancel(
/// &"id".to_string(),
/// &CancelMembershipsRequest {
/// ..Default::default()
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn cancel(
&self,
id: &str,
request: &CancelMembershipsRequest,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/cancel", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Adds free days to a membership, extending its current billing period, expiration date, or trial depending on the plan type.
///
/// # Arguments
///
/// * `id` - Membership ID (`mem_` tag).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .extend(
/// &"id".to_string(),
/// &ExtendMembershipsRequest { days: 7 },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn extend(
&self,
id: &str,
request: &ExtendMembershipsRequest,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/extend", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Pauses a membership's recurring payment collection. The customer keeps access but is not charged until the membership is resumed.
///
/// # Arguments
///
/// * `id` - Membership ID (`mem_` tag).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .pause(
/// &"id".to_string(),
/// &PauseMembershipsRequest {
/// ..Default::default()
/// },
/// None,
/// )
/// .await;
/// }
/// ```
pub async fn pause(
&self,
id: &str,
request: &PauseMembershipsRequest,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/pause", id),
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Resumes a previously paused membership's recurring payment collection. Billing resumes on the next cycle.
///
/// # Arguments
///
/// * `id` - Membership ID (`mem_` tag).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client.memberships.resume(&"id".to_string(), None).await;
/// }
/// ```
pub async fn resume(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/resume", id),
None,
None,
options,
)
.await
}
/// Re-run access fulfillment for a membership. Recomputes the member's content access on Whop, re-validates their Discord link (re-adding them to the server and re-assigning roles if needed), and re-fulfills TradingView indicator access. Telegram access is invite-based and cannot be resynced here. The outcome is written to the membership's logs.
///
/// Required permissions:
/// - `membership:resync_access`
/// - `member:email:read`
/// - `member:basic:read`
///
/// # Arguments
///
/// * `id` - The unique identifier of the membership to resync access for.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .resync_access_membership(&"mem_xxxxxxxxxxxxxx".to_string(), None)
/// .await;
/// }
/// ```
pub async fn resync_access_membership(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/resync_access", id),
None,
None,
options,
)
.await
}
/// Creates a one-use transfer URL for a membership. Opening the URL while logged into a different Whop account claims the membership onto that account. The membership's buyer can generate a link for their own membership with `membership:transfer` when the product allows transfers and the membership is `trialing`, `active`, or `completed`. An account credential with `membership:update` bypasses both restrictions.
///
/// # Arguments
///
/// * `id` - Membership ID (`mem_` tag).
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client.memberships.transfer(&"id".to_string(), None).await;
/// }
/// ```
pub async fn transfer(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<TransferMembershipsResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/transfer", id),
None,
None,
options,
)
.await
}
/// Reverse a pending cancellation for a membership that was scheduled to cancel at period end.
///
/// Required permissions:
/// - `member:manage`
/// - `member:email:read`
/// - `member:basic:read`
///
/// # Arguments
///
/// * `id` - The unique identifier of the membership to uncancel.
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
///
/// # Examples
///
/// ```no_run
/// use whop_sdk::prelude::*;
///
/// #[tokio::main]
/// async fn main() {
/// let config = ClientConfig {
/// token: Some("<token>".to_string()),
/// ..Default::default()
/// };
/// let client = Whop::new(config).expect("Failed to build client");
/// client
/// .memberships
/// .uncancel_membership(&"mem_xxxxxxxxxxxxxx".to_string(), None)
/// .await;
/// }
/// ```
pub async fn uncancel_membership(
&self,
id: &str,
options: Option<RequestOptions>,
) -> Result<Membership, ApiError> {
self.http_client
.execute_request(
Method::POST,
&format!("memberships/{}/uncancel", id),
None,
None,
options,
)
.await
}
}