Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: placement to pageType and textAlignment to textAlign #26

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Demo/Demo/Extensions/PayPalMessageExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PayPalMessages
// MARK: - Enum Displaying Helpers
typealias PayPalMessageEnumType = CaseIterable & CustomStringConvertible & Equatable

extension PayPalMessageTextAlignment: CustomStringConvertible {
extension PayPalMessageTextAlign: CustomStringConvertible {

public var description: String {
switch self {
Expand Down
14 changes: 7 additions & 7 deletions Demo/Demo/SwiftUIContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ struct SwiftUIContentView: View {

@State private var logoType: PayPalMessageLogoType = defaultMessageConfig.style.logoType
@State private var messageColor: PayPalMessageColor = defaultMessageConfig.style.color
@State private var textAlignment: PayPalMessageTextAlignment = defaultMessageConfig.style.textAlignment
@State private var textAlign: PayPalMessageTextAlign = defaultMessageConfig.style.textAlign

@State private var clientID: String = defaultMessageConfig.data.clientID
@State private var amount: Double? = defaultMessageConfig.data.amount
@State private var placement: PayPalMessagePlacement? = defaultMessageConfig.data.placement
@State private var pageType: PayPalMessagePageType? = defaultMessageConfig.data.pageType
@State private var offerType: PayPalMessageOfferType? = defaultMessageConfig.data.offerType
@State private var buyerCountry: String = defaultMessageConfig.data.buyerCountry ?? ""
@State private var ignoreCache: Bool = defaultMessageConfig.data.ignoreCache
Expand All @@ -32,13 +32,13 @@ struct SwiftUIContentView: View {
clientID: clientID,
environment: defaultMessageConfig.data.environment,
amount: amount,
placement: placement,
pageType: pageType,
offerType: offerType
),
style: .init(
logoType: logoType,
color: messageColor,
textAlignment: textAlignment
textAlign: textAlign
)
)

Expand Down Expand Up @@ -98,8 +98,8 @@ struct SwiftUIContentView: View {
}

// Text Alignment
ReusablePicker(options: PayPalMessageTextAlignment.allCases, selectedOption: $textAlignment)
.onChange(of: textAlignment) { _ in
ReusablePicker(options: PayPalMessageTextAlign.allCases, selectedOption: $textAlign)
.onChange(of: textAlign) { _ in
debounceConfigUpdate()
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ struct SwiftUIContentView: View {

logoType = defaultStyle.logoType
messageColor = defaultStyle.color
textAlignment = defaultStyle.textAlignment
textAlign = defaultStyle.textAlign
offerType = defaultData.offerType
amount = defaultData.amount
buyerCountry = defaultData.buyerCountry ?? ""
Expand Down
10 changes: 5 additions & 5 deletions Demo/Demo/UIKitContentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class UIKitContentViewController: UIViewController {

lazy var alignmentTypePicker: UISegmentedControl = getSegmentedControl(
action: #selector(updatePayPalMessageMessage),
forType: PayPalMessageTextAlignment.self
forType: PayPalMessageTextAlign.self
)

lazy var offerTypePicker: UISegmentedControl = getSegmentedControl(
Expand Down Expand Up @@ -173,7 +173,7 @@ class UIKitContentViewController: UIViewController {
private func loadDefaultSelections() {
loadSegmentedIndex(item: defaultMessageConfig.style.logoType, picker: logoTypePicker)
loadSegmentedIndex(item: defaultMessageConfig.style.color, picker: colorTypePicker)
loadSegmentedIndex(item: defaultMessageConfig.style.textAlignment, picker: alignmentTypePicker)
loadSegmentedIndex(item: defaultMessageConfig.style.textAlign, picker: alignmentTypePicker)
buyerCountryField.text = defaultMessageConfig.data.buyerCountry
ignoreCacheSwitch.isOn = defaultMessageConfig.data.ignoreCache

Expand Down Expand Up @@ -236,7 +236,7 @@ class UIKitContentViewController: UIViewController {
style: .init(
logoType: getCurrentLogoType(),
color: getCurrentMessageColor(),
textAlignment: getCurrentAlignment()
textAlign: getCurrentAlignment()
)
)

Expand All @@ -255,8 +255,8 @@ class UIKitContentViewController: UIViewController {
PayPalMessageColor.allCases[colorTypePicker.selectedSegmentIndex]
}

private func getCurrentAlignment() -> PayPalMessageTextAlignment {
PayPalMessageTextAlignment.allCases[alignmentTypePicker.selectedSegmentIndex]
private func getCurrentAlignment() -> PayPalMessageTextAlign {
PayPalMessageTextAlign.allCases[alignmentTypePicker.selectedSegmentIndex]
}

private func getCurrentOfferType() -> PayPalMessageOfferType? {
Expand Down
16 changes: 8 additions & 8 deletions PayPalMessages.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
C635F4CB2A964A020096F9FF /* PayPalMessageOfferType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F49B2A964A020096F9FF /* PayPalMessageOfferType.swift */; };
C635F4CC2A964A020096F9FF /* BuildInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F49C2A964A020096F9FF /* BuildInfo.swift */; };
C635F4CD2A964A020096F9FF /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F49D2A964A020096F9FF /* Environment.swift */; };
C635F4CE2A964A020096F9FF /* PayPalMessageTextAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F49E2A964A020096F9FF /* PayPalMessageTextAlignment.swift */; };
C635F4CE2A964A020096F9FF /* PayPalMessageTextAlign.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F49E2A964A020096F9FF /* PayPalMessageTextAlign.swift */; };
C635F4CF2A964A020096F9FF /* PayPalMessageColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F49F2A964A020096F9FF /* PayPalMessageColor.swift */; };
C635F4D02A964A020096F9FF /* PayPalMessagePlacement.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F4A02A964A020096F9FF /* PayPalMessagePlacement.swift */; };
C635F4D02A964A020096F9FF /* PayPalMessagePageType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F4A02A964A020096F9FF /* PayPalMessagePageType.swift */; };
C635F4D12A964A020096F9FF /* ImageAsset.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F4A12A964A020096F9FF /* ImageAsset.swift */; };
C635F4D22A964A020096F9FF /* PayPalMessageError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F4A22A964A020096F9FF /* PayPalMessageError.swift */; };
C635F4D32A964A020096F9FF /* HTTPHeaders.swift in Sources */ = {isa = PBXBuildFile; fileRef = C635F4A32A964A020096F9FF /* HTTPHeaders.swift */; };
Expand Down Expand Up @@ -101,9 +101,9 @@
C635F49B2A964A020096F9FF /* PayPalMessageOfferType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessageOfferType.swift; sourceTree = "<group>"; };
C635F49C2A964A020096F9FF /* BuildInfo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BuildInfo.swift; sourceTree = "<group>"; };
C635F49D2A964A020096F9FF /* Environment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Environment.swift; sourceTree = "<group>"; };
C635F49E2A964A020096F9FF /* PayPalMessageTextAlignment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessageTextAlignment.swift; sourceTree = "<group>"; };
C635F49E2A964A020096F9FF /* PayPalMessageTextAlign.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessageTextAlign.swift; sourceTree = "<group>"; };
C635F49F2A964A020096F9FF /* PayPalMessageColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessageColor.swift; sourceTree = "<group>"; };
C635F4A02A964A020096F9FF /* PayPalMessagePlacement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessagePlacement.swift; sourceTree = "<group>"; };
C635F4A02A964A020096F9FF /* PayPalMessagePageType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessagePageType.swift; sourceTree = "<group>"; };
C635F4A12A964A020096F9FF /* ImageAsset.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageAsset.swift; sourceTree = "<group>"; };
C635F4A22A964A020096F9FF /* PayPalMessageError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PayPalMessageError.swift; sourceTree = "<group>"; };
C635F4A32A964A020096F9FF /* HTTPHeaders.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPHeaders.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -252,9 +252,9 @@
C635F49B2A964A020096F9FF /* PayPalMessageOfferType.swift */,
C635F49C2A964A020096F9FF /* BuildInfo.swift */,
C635F49D2A964A020096F9FF /* Environment.swift */,
C635F49E2A964A020096F9FF /* PayPalMessageTextAlignment.swift */,
C635F49E2A964A020096F9FF /* PayPalMessageTextAlign.swift */,
C635F49F2A964A020096F9FF /* PayPalMessageColor.swift */,
C635F4A02A964A020096F9FF /* PayPalMessagePlacement.swift */,
C635F4A02A964A020096F9FF /* PayPalMessagePageType.swift */,
C635F4A12A964A020096F9FF /* ImageAsset.swift */,
C635F4A22A964A020096F9FF /* PayPalMessageError.swift */,
C635F4A32A964A020096F9FF /* HTTPHeaders.swift */,
Expand Down Expand Up @@ -485,7 +485,7 @@
C635F4E22A964A020096F9FF /* UIColor.swift in Sources */,
C635F4D92A964A020096F9FF /* MessageResponse.swift in Sources */,
C635F4D22A964A020096F9FF /* PayPalMessageError.swift in Sources */,
C635F4CE2A964A020096F9FF /* PayPalMessageTextAlignment.swift in Sources */,
C635F4CE2A964A020096F9FF /* PayPalMessageTextAlign.swift in Sources */,
C635F4D72A964A020096F9FF /* MerchantProfileRequest.swift in Sources */,
C635F4CB2A964A020096F9FF /* PayPalMessageOfferType.swift in Sources */,
C635F4E72A964A020096F9FF /* CGFloat.swift in Sources */,
Expand All @@ -506,7 +506,7 @@
C635F4E42A964A020096F9FF /* UserDefaults.swift in Sources */,
C635F4C42A964A020096F9FF /* AnalyticsService.swift in Sources */,
C635F4C62A964A020096F9FF /* AnyCodable.swift in Sources */,
C635F4D02A964A020096F9FF /* PayPalMessagePlacement.swift in Sources */,
C635F4D02A964A020096F9FF /* PayPalMessagePageType.swift in Sources */,
C635F4E92A964A020096F9FF /* PayPalMessageDelegates.swift in Sources */,
C635F4CC2A964A020096F9FF /* BuildInfo.swift in Sources */,
C635F4E62A964A020096F9FF /* HTTPURLResponse.swift in Sources */,
Expand Down
8 changes: 4 additions & 4 deletions Sources/PayPalMessages/Analytics/AnalyticsLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AnalyticsLogger: Encodable {
// Integration Details
case offerType = "offer_type"
case amount = "amount"
case placement = "placement"
case pageType = "page_type"
case buyerCountryCode = "buyer_country_code"
case channel = "channel"
// Message Only
Expand Down Expand Up @@ -73,19 +73,19 @@ class AnalyticsLogger: Encodable {
try container.encode("message", forKey: .type)
try container.encodeIfPresent(message.offerType?.rawValue, forKey: .offerType)
try container.encodeIfPresent(message.amount, forKey: .amount)
try container.encodeIfPresent(message.placement?.rawValue, forKey: .placement)
try container.encodeIfPresent(message.pageType?.rawValue, forKey: .pageType)
try container.encodeIfPresent(message.buyerCountry, forKey: .buyerCountryCode)
try container.encodeIfPresent(message.logoType.rawValue, forKey: .styleLogoType)
try container.encodeIfPresent(message.color.rawValue, forKey: .styleColor)
try container.encodeIfPresent(message.alignment.rawValue, forKey: .styleTextAlign)
try container.encodeIfPresent(message.textAlign.rawValue, forKey: .styleTextAlign)

case .modal(let weakModal):
guard let modal = weakModal.value else { return }

try container.encode("modal", forKey: .type)
try container.encodeIfPresent(modal.offerType?.rawValue, forKey: .offerType)
try container.encodeIfPresent(modal.amount, forKey: .amount)
try container.encodeIfPresent(modal.placement?.rawValue, forKey: .placement)
try container.encodeIfPresent(modal.pageType?.rawValue, forKey: .pageType)
try container.encodeIfPresent(modal.buyerCountry, forKey: .buyerCountryCode)
}
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/PayPalMessages/Config/PayPalMessageConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class PayPalMessageData: NSObject {
/// Price expressed in cents amount based on the current context (i.e. individual product price vs total cart price)
public var amount: Double?
/// Message screen location (e.g. product, cart, home)
public var placement: PayPalMessagePlacement?
public var pageType: PayPalMessagePageType?
/// Preferred message offer to display
public var offerType: PayPalMessageOfferType?
/// Consumer's country (Integrations must be approved by PayPal to use this option)
Expand All @@ -26,12 +26,12 @@ public class PayPalMessageData: NSObject {
clientID: String,
environment: Environment,
amount: Double? = nil,
placement: PayPalMessagePlacement? = nil,
pageType: PayPalMessagePageType? = nil,
offerType: PayPalMessageOfferType? = nil
) {
self.clientID = clientID
self.amount = amount
self.placement = placement
self.pageType = pageType
self.offerType = offerType
self.environment = environment
}
Expand All @@ -43,14 +43,14 @@ public class PayPalMessageData: NSObject {
environment: Environment,
partnerAttributionID: String,
amount: Double? = nil,
placement: PayPalMessagePlacement? = nil,
pageType: PayPalMessagePageType? = nil,
offerType: PayPalMessageOfferType? = nil
) {
self.clientID = clientID
self.merchantID = merchantID
self.partnerAttributionID = partnerAttributionID
self.amount = amount
self.placement = placement
self.pageType = pageType
self.offerType = offerType
self.environment = environment
}
Expand All @@ -65,16 +65,16 @@ public class PayPalMessageStyle: NSObject {
/// Text and logo color
public var color: PayPalMessageColor
/// Text alignment
public var textAlignment: PayPalMessageTextAlignment
public var textAlign: PayPalMessageTextAlign

public init(
logoType: PayPalMessageLogoType = .inline,
color: PayPalMessageColor = .black,
textAlignment: PayPalMessageTextAlignment = .right
textAlign: PayPalMessageTextAlign = .right
) {
self.logoType = logoType
self.color = color
self.textAlignment = textAlignment
self.textAlign = textAlign
}

deinit {}
Expand Down
14 changes: 7 additions & 7 deletions Sources/PayPalMessages/Config/PayPalMessageModalConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PayPalMessageModalDataConfig: NSObject {
var amount: Double?
var buyerCountry: String?
var offerType: PayPalMessageOfferType?
var placement: PayPalMessagePlacement?
var pageType: PayPalMessagePageType?
var channel: String?
var ignoreCache: Bool? // swiftlint:disable:this discouraged_optional_boolean
var modalCloseButton: ModalCloseButtonConfig
Expand All @@ -48,13 +48,13 @@ class PayPalMessageModalDataConfig: NSObject {
clientID: String,
environment: Environment,
amount: Double? = nil,
placement: PayPalMessagePlacement? = nil,
pageType: PayPalMessagePageType? = nil,
offerType: PayPalMessageOfferType? = nil,
modalCloseButton: ModalCloseButtonConfig = ModalCloseButtonConfig()
) {
self.clientID = clientID
self.amount = amount
self.placement = placement
self.pageType = pageType
self.offerType = offerType
self.modalCloseButton = modalCloseButton
self.environment = environment
Expand All @@ -67,15 +67,15 @@ class PayPalMessageModalDataConfig: NSObject {
environment: Environment,
partnerAttributionID: String,
amount: Double? = nil,
placement: PayPalMessagePlacement? = nil,
pageType: PayPalMessagePageType? = nil,
offerType: PayPalMessageOfferType? = nil,
modalCloseButton: ModalCloseButtonConfig = ModalCloseButtonConfig()
) {
self.clientID = clientID
self.merchantID = merchantID
self.partnerAttributionID = partnerAttributionID
self.amount = amount
self.placement = placement
self.pageType = pageType
self.offerType = offerType
self.modalCloseButton = modalCloseButton
self.environment = environment
Expand Down Expand Up @@ -118,7 +118,7 @@ class PayPalMessageModalConfig: NSObject, Encodable {
case buyerCountry
case offerType = "offer"
case channel
case placement
case pageType
case ignoreCache
}

Expand All @@ -132,7 +132,7 @@ class PayPalMessageModalConfig: NSObject, Encodable {
try container.encodeIfPresent(data.buyerCountry, forKey: .buyerCountry)
try container.encodeIfPresent(data.offerType?.rawValue, forKey: .offerType)
try container.encodeIfPresent(data.channel, forKey: .channel)
try container.encodeIfPresent(data.placement?.rawValue, forKey: .placement)
try container.encodeIfPresent(data.pageType?.rawValue, forKey: .pageType)
try container.encodeIfPresent(data.ignoreCache, forKey: .ignoreCache)
}
}
17 changes: 17 additions & 0 deletions Sources/PayPalMessages/Enums/PayPalMessagePageType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// Message location within an application
public enum PayPalMessagePageType: String, CaseIterable {
/// Home view
case home
/// Multiple products listing view
case productListing = "product-listing"
/// Individual product details view
case productDetails = "product-details"
/// Shopping cart view
case cart
/// Popover shopping cart view that covers part of the view
case miniCart = "mini-cart"
/// Checkout view
case checkout
/// Search results
case searchResults = "search-results"
}
13 changes: 0 additions & 13 deletions Sources/PayPalMessages/Enums/PayPalMessagePlacement.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Text alignment option for a PayPal Message
public enum PayPalMessageTextAlignment: String, CaseIterable {
public enum PayPalMessageTextAlign: String, CaseIterable {
/// Text aligned to the left
case left
/// Text aligned to the center
Expand Down
4 changes: 2 additions & 2 deletions Sources/PayPalMessages/IO/MessageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct MessageRequestParameters {
let partnerAttributionID: String?
let logoType: PayPalMessageLogoType
let buyerCountry: String?
let placement: PayPalMessagePlacement?
let pageType: PayPalMessagePageType?
let amount: Double?
let offerType: PayPalMessageOfferType?
let merchantProfileHash: String?
Expand Down Expand Up @@ -43,7 +43,7 @@ class MessageRequest: MessageRequestable {
"partner_attribution_id": parameters.partnerAttributionID,
"logo_type": parameters.logoType.rawValue,
"buyer_country": parameters.buyerCountry,
"placement": parameters.placement?.rawValue,
"page_type": parameters.pageType?.rawValue,
"amount": parameters.amount?.description,
"offer": parameters.offerType?.rawValue,
"merchant_config": parameters.merchantProfileHash,
Expand Down
4 changes: 2 additions & 2 deletions Sources/PayPalMessages/PayPalMessageModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ final class PayPalMessageModal: UIViewController, WKUIDelegate {
var channel: String?

// Location within the application
@Proxy(\.viewModel.placement)
var placement: PayPalMessagePlacement?
@Proxy(\.viewModel.pageType)
var pageType: PayPalMessagePageType?

// Skip Juno cache
@Proxy(\.viewModel.ignoreCache)
Expand Down
Loading
Loading