Skip to content

Commit

Permalink
Added customPayloadString public property to PaywallModel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Skifcha committed Dec 9, 2020
1 parent e894d4a commit 91a3f95
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Adapty/Classes/PaywallModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class PaywallModel: NSObject, JSONCodable, Codable {
case isPromo
case products
case visualPaywall
case internalCustomPayload
case customPayloadString
}

@objc public var developerId: String
Expand All @@ -25,9 +25,9 @@ public class PaywallModel: NSObject, JSONCodable, Codable {
@objc public var isPromo: Bool = false
@objc public var products: [ProductModel] = []
@objc public var visualPaywall: String = ""
private var internalCustomPayload: String = ""
@objc public var customPayloadString: String = ""
@objc public lazy var customPayload: Parameters = {
if let data = self.internalCustomPayload.data(using: .utf8), let customPayload = try? JSONSerialization.jsonObject(with: data, options: []) as? Parameters {
if let data = self.customPayloadString.data(using: .utf8), let customPayload = try? JSONSerialization.jsonObject(with: data, options: []) as? Parameters {
return customPayload
}
return Parameters()
Expand All @@ -53,7 +53,7 @@ public class PaywallModel: NSObject, JSONCodable, Codable {
if let revision = attributes?["revision"] as? Int { self.revision = revision }
if let isPromo = attributes?["is_promo"] as? Bool { self.isPromo = isPromo }
if let visualPaywall = attributes?["visual_paywall"] as? String { self.visualPaywall = visualPaywall }
if let internalCustomPayload = attributes?["custom_payload"] as? String { self.internalCustomPayload = internalCustomPayload }
if let customPayloadString = attributes?["custom_payload"] as? String { self.customPayloadString = customPayloadString }

guard let products = attributes?["products"] as? [Parameters] else {
throw AdaptyError.missingParam("PaywallModel - products")
Expand All @@ -78,7 +78,7 @@ public class PaywallModel: NSObject, JSONCodable, Codable {
return false
}

return self.developerId == object.developerId && self.variationId == object.variationId && self.revision == object.revision && self.isPromo == object.isPromo && self.products == object.products && self.visualPaywall == object.visualPaywall && self.internalCustomPayload == object.internalCustomPayload
return self.developerId == object.developerId && self.variationId == object.variationId && self.revision == object.revision && self.isPromo == object.isPromo && self.products == object.products && self.visualPaywall == object.visualPaywall && self.customPayloadString == object.customPayloadString
}

}
Expand Down
1 change: 1 addition & 0 deletions Documentation/Models.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ This model contains info about paywall.
| products | An array of [`ProductModel`](#productmodel) related to this paywall. |
| visualPaywall | HTML representation of the paywall. |
| customPayload | Dictionary of paywall's custom properties. |
| customPayloadString | String representation of paywall's custom properties. |

## `PromoModel`

Expand Down

0 comments on commit 91a3f95

Please sign in to comment.