@@ -26,7 +26,22 @@ public struct Coupon {
2626 public let dateModified : Date
2727
2828 /// Determines the type of discount that will be applied. Options: `.percent` `.fixedCart` and `.fixedProduct`
29- public let discountType : DiscountType
29+ public var discountType : DiscountType {
30+ if let type = mappedDiscountType {
31+ return type
32+ } else {
33+ // Returns default value for fallback case to avoid working with optionals.
34+ // Since `CouponListMapper` filters out nil `mappedDiscountType`,
35+ // this case is unlikely to happen.
36+ return . fixedCart
37+ }
38+ }
39+
40+ /// Discount type if matched with any of the ones supported by Core.
41+ /// Returns nil if other types are found.
42+ /// Used to filter only coupons with default types, so internal to this module only.
43+ ///
44+ internal let mappedDiscountType : DiscountType ?
3045
3146 public let description : String
3247
@@ -78,6 +93,9 @@ public struct Coupon {
7893 /// Email addresses of customers who have used this coupon
7994 public let usedBy : [ String ]
8095
96+ /// Discount types supported by Core.
97+ /// There are other types supported by other plugins, but those are not supported for now.
98+ ///
8199 public enum DiscountType : String {
82100 case percent = " percent "
83101 case fixedCart = " fixed_cart "
@@ -114,7 +132,7 @@ public struct Coupon {
114132 self . amount = amount
115133 self . dateCreated = dateCreated
116134 self . dateModified = dateModified
117- self . discountType = discountType
135+ self . mappedDiscountType = discountType
118136 self . description = description
119137 self . dateExpires = dateExpires
120138 self . usageCount = usageCount
@@ -148,7 +166,7 @@ extension Coupon: Codable {
148166 case amount
149167 case dateCreated = " dateCreatedGmt "
150168 case dateModified = " dateModifiedGmt "
151- case discountType
169+ case mappedDiscountType
152170 case description
153171 case dateExpires = " dateExpiresGmt "
154172 case usageCount
0 commit comments