paddle-rust-sdk 0.17.0

Rust SDK for working with the Paddle API in server-side apps. (Unofficial)
Documentation
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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
//! Builders for making requests to the Paddle API for subscription entities.
//!
//! See the [Paddle API](https://developer.paddle.com/api-reference/subscriptions/overview) documentation for more information.

use chrono::prelude::*;
use reqwest::Method;
use serde::Serialize;
use serde_with::skip_serializing_none;

use crate::entities::{
    BillingDetails, Subscription, SubscriptionDiscountEffectiveFrom, SubscriptionPreview,
    SubscriptionWithInclude,
};
use crate::enums::{
    CollectionMode, CurrencyCode, EffectiveFrom, ProrationBillingMode, ScheduledChangeAction,
    SubscriptionInclude, SubscriptionOnPaymentFailure, SubscriptionOnResume, SubscriptionStatus,
};
use crate::ids::{AddressID, BusinessID, CustomerID, PriceID, SubscriptionID};
use crate::paginated::Paginated;
use crate::transactions::TransactionItem;
use crate::{Paddle, Result};

/// Request builder for fetching subscriptions from Paddle API.
#[skip_serializing_none]
#[derive(Serialize)]
pub struct SubscriptionsList<'a> {
    #[serde(skip)]
    client: &'a Paddle,
    #[serde(serialize_with = "crate::comma_separated")]
    address_id: Option<Vec<AddressID>>,
    after: Option<SubscriptionID>,
    collection_mode: Option<CollectionMode>,
    #[serde(serialize_with = "crate::comma_separated")]
    customer_id: Option<Vec<CustomerID>>,
    #[serde(serialize_with = "crate::comma_separated")]
    id: Option<Vec<SubscriptionID>>,
    order_by: Option<String>,
    per_page: Option<usize>,
    #[serde(serialize_with = "crate::comma_separated")]
    price_id: Option<Vec<PriceID>>,
    #[serde(serialize_with = "crate::comma_separated_enum")]
    scheduled_change_action: Option<Vec<ScheduledChangeAction>>,
    #[serde(serialize_with = "crate::comma_separated_enum")]
    status: Option<Vec<SubscriptionStatus>>,
}

impl<'a> SubscriptionsList<'a> {
    pub fn new(client: &'a Paddle) -> Self {
        Self {
            client,
            address_id: None,
            after: None,
            collection_mode: None,
            customer_id: None,
            id: None,
            order_by: None,
            per_page: None,
            price_id: None,
            scheduled_change_action: None,
            status: None,
        }
    }

    /// Return entities related to the specified addresses.
    pub fn address_ids(
        &mut self,
        address_ids: impl IntoIterator<Item = impl Into<AddressID>>,
    ) -> &mut Self {
        self.address_id = Some(address_ids.into_iter().map(Into::into).collect());
        self
    }

    /// Return entities after the specified Paddle ID when working with paginated endpoints. Used in the `meta.pagination.next` URL in responses for list operations.
    pub fn after(&mut self, id: impl Into<SubscriptionID>) -> &mut Self {
        self.after = Some(id.into());
        self
    }

    /// Return entities that match the specified collection mode.
    pub fn collection_mode(&mut self, mode: CollectionMode) -> &mut Self {
        self.collection_mode = Some(mode);
        self
    }

    /// Return entities related to the specified customers.
    pub fn customer_id(
        &mut self,
        customer_ids: impl IntoIterator<Item = impl Into<CustomerID>>,
    ) -> &mut Self {
        self.customer_id = Some(customer_ids.into_iter().map(Into::into).collect());
        self
    }

    /// Return only the IDs specified.
    pub fn id(&mut self, ids: impl IntoIterator<Item = impl Into<SubscriptionID>>) -> &mut Self {
        self.id = Some(ids.into_iter().map(Into::into).collect());
        self
    }

    /// Order returned entities by the specified field. Valid fields for ordering: `id`
    pub fn order_by_asc(&mut self, field: &str) -> &mut Self {
        self.order_by = Some(format!("{}[ASC]", field));
        self
    }

    /// Order returned entities by the specified field. Valid fields for ordering: `id`
    pub fn order_by_desc(&mut self, field: &str) -> &mut Self {
        self.order_by = Some(format!("{}[DESC]", field));
        self
    }

    /// Set how many entities are returned per page. Paddle returns the maximum number of results if a number greater than the maximum is requested.
    /// Check `meta.pagination.per_page` in the response to see how many were returned.
    ///
    /// Default: `50`; Maximum: `200`.
    pub fn per_page(&mut self, entities_per_page: usize) -> &mut Self {
        self.per_page = Some(entities_per_page);
        self
    }

    /// Return entities related to the specified prices.
    pub fn price_ids(
        &mut self,
        price_ids: impl IntoIterator<Item = impl Into<PriceID>>,
    ) -> &mut Self {
        self.price_id = Some(price_ids.into_iter().map(Into::into).collect());
        self
    }

    /// Return subscriptions that have a scheduled changes.
    pub fn scheduled_change_action(
        &mut self,
        actions: impl IntoIterator<Item = ScheduledChangeAction>,
    ) -> &mut Self {
        self.scheduled_change_action = Some(actions.into_iter().collect());
        self
    }

    /// Return entities that match the specified subscription statuses.
    pub fn status(&mut self, statuses: impl IntoIterator<Item = SubscriptionStatus>) -> &mut Self {
        self.status = Some(statuses.into_iter().collect());
        self
    }

    /// Returns a paginator for fetching pages of entities from Paddle
    pub fn send(&self) -> Paginated<'_, Vec<Subscription>> {
        Paginated::new(self.client, "/subscriptions", self)
    }
}

/// Request builder for fetching a specific subscription.
#[skip_serializing_none]
#[derive(Serialize)]
pub struct SubscriptionGet<'a> {
    #[serde(skip)]
    client: &'a Paddle,
    #[serde(skip)]
    subscription_id: SubscriptionID,
    #[serde(serialize_with = "crate::comma_separated_enum")]
    include: Option<Vec<SubscriptionInclude>>,
}

impl<'a> SubscriptionGet<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            include: None,
        }
    }

    /// Include related entities in the response.
    pub fn include(
        &mut self,
        entities: impl IntoIterator<Item = SubscriptionInclude>,
    ) -> &mut Self {
        self.include = Some(entities.into_iter().collect());
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<SubscriptionWithInclude> {
        self.client
            .send(
                self,
                Method::GET,
                &format!("/subscriptions/{}", self.subscription_id.as_ref()),
            )
            .await
    }
}

// Note: Unlike other structs we cannot use this directly for the preview request because we need to
// serialize null values to indicate that they should be removed from the subscription preview.

/// Request builder for getting a preview of changes to a subscription without actually applying them.
///
/// Typically used for previewing proration before making changes to a subscription.
pub struct SubscriptionPreviewUpdate<'a> {
    client: &'a Paddle,
    subscription_id: SubscriptionID,
    data: serde_json::Value,
}

impl<'a> SubscriptionPreviewUpdate<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            data: serde_json::json!({}),
        }
    }

    /// The customer ID to use for the preview. Include to change the customer for a subscription.
    pub fn customer_id(&mut self, customer_id: impl Into<CustomerID>) -> &mut Self {
        self.data["customer_id"] = serde_json::json!(customer_id.into());
        self
    }

    /// The address ID to use for the preview. Include to change the address for a subscription.
    pub fn address_id(&mut self, address_id: impl Into<AddressID>) -> &mut Self {
        self.data["address_id"] = serde_json::json!(address_id.into());
        self
    }

    /// The business ID to use for the preview. Include to change the business for a subscription.
    pub fn business_id(&mut self, business_id: impl Into<BusinessID>) -> &mut Self {
        self.data["business_id"] = serde_json::json!(business_id.into());
        self
    }

    /// Supported currency code. Include to change the currency that a subscription bills in.
    ///
    /// When changing `collection_mode` to `manual`, you may need to change currency code to `USD`, `EUR`, or `GBP`.
    pub fn currency_code(&mut self, currency_code: CurrencyCode) -> &mut Self {
        self.data["currency_code"] = serde_json::json!(currency_code);
        self
    }

    /// Datetime of when this subscription is next scheduled to be billed. Include to change the next billing date.
    pub fn next_billed_at(&mut self, next_billed_at: DateTime<Utc>) -> &mut Self {
        self.data["next_billed_at"] = serde_json::json!(next_billed_at);
        self
    }

    /// Details of the discount applied to this subscription. Include to add a discount to a subscription. None to remove a discount.
    pub fn set_discount(
        &mut self,
        discount: Option<SubscriptionDiscountEffectiveFrom>,
    ) -> &mut Self {
        self.data["discount"] = serde_json::json!(discount);
        self
    }

    /// How payment is collected for transactions created for this subscription. `automatic` for checkout, `manual` for invoices.
    pub fn collection_mode(&mut self, mode: CollectionMode) -> &mut Self {
        self.data["collection_mode"] = serde_json::json!(mode);
        self
    }

    /// Details for invoicing. Required if `collection_mode` is `manual`. `None` if changing `collection_mode` to `automatic`.
    pub fn billing_details(&mut self, billing_details: Option<BillingDetails>) -> &mut Self {
        self.data["billing_details"] = serde_json::json!(billing_details);
        self
    }

    /// Change that's scheduled to be applied to a subscription.
    ///
    /// When updating, you may only set to `null` to remove a scheduled change.
    ///
    /// Use the pause subscription, cancel subscription, and resume subscription operations to create scheduled changes.
    pub fn unset_scheduled_change(&mut self) -> &mut Self {
        self.data["scheduled_change"] = serde_json::json!(null);
        self
    }

    /// List of items on this subscription. Only recurring items may be added. Send the complete list of items that should be on this subscription, including existing items to retain.
    pub fn items(&mut self, items: impl IntoIterator<Item = TransactionItem>) -> &mut Self {
        self.data["items"] = serde_json::json!(items.into_iter().collect::<Vec<_>>());
        self
    }

    /// Your own structured key-value data.
    pub fn custom_data(&mut self, custom_data: serde_json::Value) -> &mut Self {
        self.data["custom_data"] = custom_data;
        self
    }

    /// How Paddle should handle proration calculation for changes made to a subscription or its items. Required when making changes that impact billing.
    ///
    /// For automatically-collected subscriptions, responses may take longer than usual if a proration billing mode that collects for payment immediately is used.
    pub fn proration_billing_mode(&mut self, mode: ProrationBillingMode) -> &mut Self {
        self.data["proration_billing_mode"] = serde_json::json!(mode);
        self
    }

    /// How Paddle should handle changes made to a subscription or its items if the payment fails during update. If omitted, defaults to `prevent_change`.
    pub fn on_payment_failure(&mut self, mode: SubscriptionOnPaymentFailure) -> &mut Self {
        self.data["on_payment_failure"] = serde_json::json!(mode);
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<SubscriptionPreview> {
        self.client
            .send(
                &self.data,
                Method::PATCH,
                &format!("/subscriptions/{}/preview", self.subscription_id.as_ref()),
            )
            .await
    }
}

// Note: Unlike other structs we cannot use this directly for the preview request because we need to
// serialize null values to indicate that they should be removed from the subscription preview.

/// Request builder for updating a subscription using its ID.
///
/// When making changes to items or the next billing date for a subscription, you must include the `proration_billing_mode` field to tell Paddle how to bill for those changes.
///
/// Send the complete list of items that you'd like to be on a subscription — including existing items. If you omit items, they're removed from the subscription.
///
/// For each item, send `price_id` and `quantity`. Paddle responds with the full price object for each price. If you're updating an existing item, you can omit the `quantity` if you don't want to update it.
///
/// If successful, your response includes a copy of the updated subscription entity. When an update results in an immediate charge, responses may take longer than usual while a payment attempt is processed.
pub struct SubscriptionUpdate<'a> {
    client: &'a Paddle,
    subscription_id: SubscriptionID,
    data: serde_json::Value,
}

impl<'a> SubscriptionUpdate<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            data: serde_json::json!({}),
        }
    }

    /// The customer ID to use for the preview. Include to change the customer for a subscription.
    pub fn customer_id(&mut self, customer_id: impl Into<CustomerID>) -> &mut Self {
        self.data["customer_id"] = serde_json::json!(customer_id.into());
        self
    }

    /// The address ID to use for the preview. Include to change the address for a subscription.
    pub fn address_id(&mut self, address_id: impl Into<AddressID>) -> &mut Self {
        self.data["address_id"] = serde_json::json!(address_id.into());
        self
    }

    /// The business ID to use for the preview. Include to change the business for a subscription.
    pub fn business_id(&mut self, business_id: impl Into<BusinessID>) -> &mut Self {
        self.data["business_id"] = serde_json::json!(business_id.into());
        self
    }

    /// Supported currency code. Include to change the currency that a subscription bills in.
    ///
    /// When changing `collection_mode` to `manual`, you may need to change currency code to `USD`, `EUR`, or `GBP`.
    pub fn currency_code(&mut self, currency_code: CurrencyCode) -> &mut Self {
        self.data["currency_code"] = serde_json::json!(currency_code);
        self
    }

    /// Datetime of when this subscription is next scheduled to be billed. Include to change the next billing date.
    pub fn next_billed_at(&mut self, next_billed_at: DateTime<Utc>) -> &mut Self {
        self.data["next_billed_at"] = serde_json::json!(next_billed_at);
        self
    }

    /// Details of the discount applied to this subscription. Include to add a discount to a subscription. None to remove a discount.
    pub fn set_discount(
        &mut self,
        discount: Option<SubscriptionDiscountEffectiveFrom>,
    ) -> &mut Self {
        self.data["discount"] = serde_json::json!(discount);
        self
    }

    /// How payment is collected for transactions created for this subscription. `automatic` for checkout, `manual` for invoices.
    pub fn collection_mode(&mut self, mode: CollectionMode) -> &mut Self {
        self.data["collection_mode"] = serde_json::json!(mode);
        self
    }

    /// Details for invoicing. Required if `collection_mode` is `manual`. `None` if changing `collection_mode` to `automatic`.
    pub fn billing_details(&mut self, billing_details: Option<BillingDetails>) -> &mut Self {
        self.data["billing_details"] = serde_json::json!(billing_details);
        self
    }

    /// Change that's scheduled to be applied to a subscription.
    ///
    /// When updating, you may only set to `null` to remove a scheduled change.
    ///
    /// Use the pause subscription, cancel subscription, and resume subscription operations to create scheduled changes.
    pub fn unset_scheduled_change(&mut self) -> &mut Self {
        self.data["scheduled_change"] = serde_json::json!(null);
        self
    }

    /// List of items on this subscription. Only recurring items may be added. Send the complete list of items that should be on this subscription, including existing items to retain.
    pub fn items(&mut self, items: impl IntoIterator<Item = TransactionItem>) -> &mut Self {
        self.data["items"] = serde_json::json!(items.into_iter().collect::<Vec<_>>());
        self
    }

    /// Your own structured key-value data.
    pub fn custom_data(&mut self, custom_data: serde_json::Value) -> &mut Self {
        self.data["custom_data"] = custom_data;
        self
    }

    /// How Paddle should handle proration calculation for changes made to a subscription or its items. Required when making changes that impact billing.
    ///
    /// For automatically-collected subscriptions, responses may take longer than usual if a proration billing mode that collects for payment immediately is used.
    pub fn proration_billing_mode(&mut self, mode: ProrationBillingMode) -> &mut Self {
        self.data["proration_billing_mode"] = serde_json::json!(mode);
        self
    }

    /// How Paddle should handle changes made to a subscription or its items if the payment fails during update. If omitted, defaults to `prevent_change`.
    pub fn on_payment_failure(&mut self, mode: SubscriptionOnPaymentFailure) -> &mut Self {
        self.data["on_payment_failure"] = serde_json::json!(mode);
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<Subscription> {
        self.client
            .send(
                &self.data,
                Method::PATCH,
                &format!("/subscriptions/{}", self.subscription_id.as_ref()),
            )
            .await
    }
}

/// Request builder for creating a preview of one-time charge for a subscription without billing that charge.
#[skip_serializing_none]
#[derive(Serialize)]
pub struct SubscriptionOneTimeChargePreview<'a> {
    #[serde(skip)]
    client: &'a Paddle,
    #[serde(skip)]
    subscription_id: SubscriptionID,
    effective_from: Option<EffectiveFrom>,
    items: Vec<TransactionItem>,
    on_payment_failure: Option<SubscriptionOnPaymentFailure>,
}

impl<'a> SubscriptionOneTimeChargePreview<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            effective_from: None,
            items: Vec::default(),
            on_payment_failure: None,
        }
    }

    /// When one-time charges should be billed.
    pub fn effective_from(&mut self, effective_from: EffectiveFrom) -> &mut Self {
        self.effective_from = Some(effective_from);
        self
    }

    /// List of one-time charges to bill for. Only prices where the `billing_cycle` is `null` may be added.
    ///
    /// You can charge for items that you've added to your catalog by passing the Paddle ID of an existing price entity, or you can charge for non-catalog items by passing a price object.
    ///
    /// Non-catalog items can be for existing products, or you can pass a product object as part of your price to charge for a non-catalog product.
    pub fn items(&mut self, items: impl IntoIterator<Item = TransactionItem>) -> &mut Self {
        self.items = items.into_iter().collect();
        self
    }

    /// How Paddle should handle changes made to a subscription or its items if the payment fails during update. If omitted, defaults to `prevent_change`.
    pub fn on_payment_failure(&mut self, mode: SubscriptionOnPaymentFailure) -> &mut Self {
        self.on_payment_failure = Some(mode);
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<SubscriptionPreview> {
        self.client
            .send(
                self,
                Method::POST,
                &format!(
                    "/subscriptions/{}/charge/preview",
                    self.subscription_id.as_ref()
                ),
            )
            .await
    }
}

/// Request builder for creating a new one-time charge for a subscription.
#[skip_serializing_none]
#[derive(Serialize)]
pub struct SubscriptionOneTimeCharge<'a> {
    #[serde(skip)]
    client: &'a Paddle,
    #[serde(skip)]
    subscription_id: SubscriptionID,
    effective_from: Option<EffectiveFrom>,
    items: Vec<TransactionItem>,
    on_payment_failure: Option<SubscriptionOnPaymentFailure>,
}

impl<'a> SubscriptionOneTimeCharge<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            effective_from: None,
            items: Vec::default(),
            on_payment_failure: None,
        }
    }

    /// When one-time charges should be billed.
    pub fn effective_from(&mut self, effective_from: EffectiveFrom) -> &mut Self {
        self.effective_from = Some(effective_from);
        self
    }

    /// List of one-time charges to bill for. Only prices where the `billing_cycle` is `null` may be added.
    ///
    /// You can charge for items that you've added to your catalog by passing the Paddle ID of an existing price entity, or you can charge for non-catalog items by passing a price object.
    ///
    /// Non-catalog items can be for existing products, or you can pass a product object as part of your price to charge for a non-catalog product.
    pub fn items(&mut self, items: impl IntoIterator<Item = TransactionItem>) -> &mut Self {
        self.items = items.into_iter().collect();
        self
    }

    /// How Paddle should handle changes made to a subscription or its items if the payment fails during update. If omitted, defaults to `prevent_change`.
    pub fn on_payment_failure(&mut self, mode: SubscriptionOnPaymentFailure) -> &mut Self {
        self.on_payment_failure = Some(mode);
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<Subscription> {
        self.client
            .send(
                self,
                Method::POST,
                &format!("/subscriptions/{}/charge", self.subscription_id.as_ref()),
            )
            .await
    }
}

/// Request builder for pausing a subscription.
#[skip_serializing_none]
#[derive(Serialize)]
pub struct SubscriptionPause<'a> {
    #[serde(skip)]
    client: &'a Paddle,
    #[serde(skip)]
    subscription_id: SubscriptionID,
    effective_from: Option<EffectiveFrom>,
    resume_at: Option<DateTime<Utc>>,
    on_resume: Option<SubscriptionOnResume>,
}

impl<'a> SubscriptionPause<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            effective_from: None,
            resume_at: None,
            on_resume: None,
        }
    }

    /// When this subscription change should take effect from.
    ///
    /// Defaults to `next_billing_period` for active subscriptions, which creates a `scheduled_change` to apply the subscription change at the end of the billing period.
    pub fn effective_from(&mut self, effective_from: EffectiveFrom) -> &mut Self {
        self.effective_from = Some(effective_from);
        self
    }

    /// Datetime of when the paused subscription should resume. Omit to pause indefinitely until resumed.
    pub fn resume_at(&mut self, datetime: DateTime<Utc>) -> &mut Self {
        self.resume_at = Some(datetime);
        self
    }

    /// How Paddle should set the billing period for the subscription when resuming. If omitted, defaults to `start_new_billing_period`.
    pub fn on_resume(&mut self, value: SubscriptionOnResume) -> &mut Self {
        self.on_resume = Some(value);
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<Subscription> {
        self.client
            .send(
                self,
                Method::POST,
                &format!("/subscriptions/{}/pause", self.subscription_id.as_ref()),
            )
            .await
    }
}

/// Request builder for resuming a subscription.
#[skip_serializing_none]
#[derive(Serialize)]
pub struct SubscriptionResume<'a> {
    #[serde(skip)]
    client: &'a Paddle,
    #[serde(skip)]
    subscription_id: SubscriptionID,
    // Defaults to `immediately` if omitted.
    effective_from: Option<DateTime<Utc>>,
    on_resume: Option<SubscriptionOnResume>,
}

impl<'a> SubscriptionResume<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            effective_from: None,
            on_resume: None,
        }
    }

    /// When this subscription change should take effect from.
    ///
    /// Defaults to `next_billing_period` for active subscriptions, which creates a `scheduled_change` to apply the subscription change at the end of the billing period.
    pub fn effective_from(&mut self, effective_from: DateTime<Utc>) -> &mut Self {
        self.effective_from = Some(effective_from);
        self
    }

    /// How Paddle should set the billing period for the subscription when resuming. If omitted, defaults to `start_new_billing_period`.
    pub fn on_resume(&mut self, value: SubscriptionOnResume) -> &mut Self {
        self.on_resume = Some(value);
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<Subscription> {
        self.client
            .send(
                self,
                Method::POST,
                &format!("/subscriptions/{}/resume", self.subscription_id.as_ref()),
            )
            .await
    }
}

/// Request builder for resuming a subscription.
#[skip_serializing_none]
#[derive(Serialize)]
pub struct SubscriptionCancel<'a> {
    #[serde(skip)]
    client: &'a Paddle,
    #[serde(skip)]
    subscription_id: SubscriptionID,
    effective_from: Option<EffectiveFrom>,
}

impl<'a> SubscriptionCancel<'a> {
    pub fn new(client: &'a Paddle, subscription_id: impl Into<SubscriptionID>) -> Self {
        Self {
            client,
            subscription_id: subscription_id.into(),
            effective_from: None,
        }
    }

    /// When this subscription change should take effect from.
    ///
    /// Defaults to `next_billing_period` for active subscriptions, which creates a `scheduled_change` to apply the subscription change at the end of the billing period.
    pub fn effective_from(&mut self, effective_from: EffectiveFrom) -> &mut Self {
        self.effective_from = Some(effective_from);
        self
    }

    /// Send the request to Paddle and return the response.
    pub async fn send(&self) -> Result<Subscription> {
        self.client
            .send(
                self,
                Method::POST,
                &format!("/subscriptions/{}/cancel", self.subscription_id.as_ref()),
            )
            .await
    }
}