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
//! # promotion_kit
//!
//! A powerful Rust toolkit for managing dynamic promotions with flexible rules and seamless integration.
//!
//! This crate provides a lightweight and extensible toolkit for managing promotions,
//! vouchers, and discounts in any transactional system, such as e-commerce, SaaS,
//! digital products, or other service platforms.
//!
//! ---
//!
//! ## ✅ Features
//!
//! - Define flexible promotions with percentage or fixed amount discounts
//! - Configure minimum transaction amounts, usage limits, and validity periods
//! - Apply promotions and calculate discounts using a clean, composable API
//! - Track usage counts and validate conditions with a minimal rule engine
//!
//! ---
//!
//! ## ✨ Quick Start
//!
//! ```rust
//! use promotion_kit::promotion::{Promotion, DiscountType, TargetScope};
//! use promotion_kit::service::apply_promotion;
//!
//! let promo = Promotion {
//! code: "WELCOME10".into(),
//! description: "10% off for new users".into(),
//! discount: DiscountType::Percentage(10.0),
//! usage_limit: Some(100),
//! used: 0,
//! valid_from: 1_700_000_000,
//! valid_until: 1_800_000_000,
//! min_transaction: Some(100.0),
//! target: TargetScope::Global,
//! currency: Some("IDR".to_string()),
//! };
//!
//! let discount = apply_promotion(&promo, 200.0, 1_750_000_000).unwrap();
//! assert_eq!(discount, 20.0);
//! ```
//!
//! ---
//!
//! ## 📄 License
//!
//! Licensed under the [Apache-2.0 license](http://www.apache.org/licenses/LICENSE-2.0.txt)
//!
//! ---
//!
//! ## 👨 Author
//!
//! Jerry Maheswara <jerrymaheswara@gmail.com>
//!
//! ---
//!
//! ## ❤️ Built with Love in Rust
//!
//! This project is built with ❤️ using **Rust** — a systems programming language that is safe, fast, and concurrent.
//! Rust is the perfect choice for building reliable and efficient applications.
//!
//! ---
//!
//! ## 🤝 Contributing
//!
//! Pull requests, issues, and feedback are welcome!
//! If you find this crate useful, give it a ⭐ and share it with others in the Rustacean community.
//!
/// Contains the main application logic for validating and applying promotions.
///
/// This is the entry point for consuming systems to evaluate if a promotion can be applied.
/// Defines all errors related to promotion validation and application.
///
/// Uses the `thiserror` crate for ergonomic error handling and clear descriptions.
/// Contains the core data structures for defining a promotion and discount rules.
///
/// Includes `Promotion`, `DiscountType`, and `TargetScope` types.
/// Implements the logic for calculating the monetary value of a discount
/// based on the provided promotion and transaction amount.
/// Provides a lightweight rule engine and context model for validating promotions.
///
/// Used internally by the service layer and externally for basic checks like filtering valid promos.