forked from Smartdevs17/SubTrackr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcancellation.rs
More file actions
24 lines (19 loc) · 886 Bytes
/
Copy pathcancellation.rs
File metadata and controls
24 lines (19 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use soroban_sdk::{Env, Address, Symbol, log};
use crate::storage_types::{Subscription, Status};
pub fn request_cancellation(e: Env, sub_id: Symbol) {
let mut sub: Subscription = e.storage().instance().get(&sub_id).unwrap();
// Instead of immediate deletion, we set an end date
// to allow the user to enjoy the remaining paid period.
let current_ts = e.ledger().timestamp();
sub.status = Status::ScheduledForCancellation;
sub.end_date = Some(sub.next_billing_date);
sub.updated_at = current_ts;
e.storage().instance().set(&sub_id, &sub);
log!(&e, "Subscription scheduled for cancellation", sub_id);
}
pub fn undo_cancellation(e: Env, sub_id: Symbol) {
let mut sub: Subscription = e.storage().instance().get(&sub_id).unwrap();
sub.status = Status::Active;
sub.end_date = None;
e.storage().instance().set(&sub_id, &sub);
}