Skip to content

Commit

Permalink
Merge pull request woocommerce#4921 from woocommerce/issue/4426-no-pa…
Browse files Browse the repository at this point in the history
…yments-for-subscriptions

[Mobile Payments] Don't allow mobile payments in orders with subscriptions
  • Loading branch information
koke authored Sep 3, 2021
2 parents 69e1850 + 5684b07 commit 5424195
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Networking/Networking/Model/Product/ProductType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum ProductType: Codable, Hashable, GeneratedFakeable {
case grouped
case affiliate
case variable
case subscription
case custom(String) // in case there are extensions modifying product types
}

Expand All @@ -28,6 +29,8 @@ extension ProductType: RawRepresentable {
self = .affiliate
case Keys.variable:
self = .variable
case Keys.subscription:
self = .subscription
default:
self = .custom(rawValue)
}
Expand All @@ -41,6 +44,7 @@ extension ProductType: RawRepresentable {
case .grouped: return Keys.grouped
case .affiliate: return Keys.affiliate
case .variable: return Keys.variable
case .subscription: return Keys.subscription
case .custom(let payload): return payload
}
}
Expand All @@ -57,6 +61,8 @@ extension ProductType: RawRepresentable {
return NSLocalizedString("External/Affiliate", comment: "Display label for affiliate product type.")
case .variable:
return NSLocalizedString("Variable", comment: "Display label for variable product type.")
case .subscription:
return NSLocalizedString("Subscription", comment: "Display label for subscription product type.")
case .custom(let payload):
return payload // unable to localize at runtime.
}
Expand All @@ -67,8 +73,9 @@ extension ProductType: RawRepresentable {
/// Enum containing the 'Known' ProductType Keys
///
private enum Keys {
static let simple = "simple"
static let grouped = "grouped"
static let affiliate = "external"
static let variable = "variable"
static let simple = "simple"
static let grouped = "grouped"
static let affiliate = "external"
static let variable = "variable"
static let subscription = "subscription"
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ final class OrderDetailsDataSource: NSObject {
return isOrderAmountEligibleForCardPayment() &&
isOrderStatusEligibleForCardPayment() &&
isOrderPaymentMethodEligibleForCardPayment() &&
hasCardPresentEligiblePaymentGatewayAccount()
hasCardPresentEligiblePaymentGatewayAccount() &&
!orderContainsAnySubscription()
}

/// Whether the button to create shipping labels should be visible.
Expand Down Expand Up @@ -1478,6 +1479,12 @@ private extension OrderDetailsDataSource {
func hasCardPresentEligiblePaymentGatewayAccount() -> Bool {
resultsControllers.paymentGatewayAccounts.contains(where: \.isCardPresentEligible)
}

func orderContainsAnySubscription() -> Bool {
order.items.contains { item in
lookUpProduct(by: item.productID)?.productType == .subscription
}
}
}

// MARK: - Private Utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public enum BottomSheetProductType: Hashable {
self = .affiliate
case .grouped:
self = .grouped
case .subscription:
// We need to be aware of subscriptions for Payments
// but we don't handle them in the UI yet
self = .custom("subscription")
case .custom(let string):
self = .custom(string)
}
Expand Down

0 comments on commit 5424195

Please sign in to comment.