Skip to content

Commit ea3a83a

Browse files
authored
Shipping Labels: Prevent label purchase without payment methods (#15752)
2 parents 4b72d88 + 69f7031 commit ea3a83a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsView.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct WooShippingCreateLabelsView: View {
3939

4040
@State private var showingCustomsForm = false
4141
@State private var showingSplitShipments = false
42-
@State private var showingPaymentMethods = false
4342

4443
/// Whether the destination address is verified.
4544
private var isDestinationAddressVerified: Bool {
@@ -106,12 +105,12 @@ struct WooShippingCreateLabelsView: View {
106105
isShipmentDetailsExpanded = false
107106
}
108107
}
109-
.sheet(isPresented: $showingPaymentMethods) {
108+
.sheet(isPresented: $viewModel.showingPaymentMethods) {
110109
if let paymentMethodsViewModel = viewModel.paymentMethodsViewModel {
111110
WooShippingPaymentMethodsView(viewModel: paymentMethodsViewModel,
112111
onAccountSettingsUpdate: { settings in
113112
viewModel.didUpdateAccountSettings(settings)
114-
showingPaymentMethods = false
113+
viewModel.showingPaymentMethods = false
115114
})
116115
.presentationDetents([.fraction(0.7), .large])
117116
}
@@ -468,7 +467,7 @@ private extension WooShippingCreateLabelsView {
468467

469468
var addPaymentMethodLine: some View {
470469
Button(action: {
471-
showingPaymentMethods = true
470+
viewModel.showingPaymentMethods = true
472471
}) {
473472
HStack {
474473
Image(systemName: "plus")
@@ -487,7 +486,7 @@ private extension WooShippingCreateLabelsView {
487486
_ cardLineViewModel: WooShippingPaymentMethodLine.CardPaymentMethodLineViewModel
488487
) -> some View {
489488
Button(action: {
490-
showingPaymentMethods = true
489+
viewModel.showingPaymentMethods = true
491490
}) {
492491
HStack {
493492
Text(cardLineViewModel.title)

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShippingCreateLabelsViewModel.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ final class WooShippingCreateLabelsViewModel: ObservableObject {
182182
/// Closure to execute after the label is successfully purchased.
183183
let onLabelPurchase: ((_ markOrderComplete: Bool) -> Void)?
184184

185+
@Published var showingPaymentMethods = false
185186
@Published private var paymentMethod: ShippingLabelPaymentMethod?
186187
@Published private(set) var paymentMethodLine: WooShippingPaymentMethodLine?
187188

@@ -296,6 +297,10 @@ final class WooShippingCreateLabelsViewModel: ObservableObject {
296297
/// Purchases a shipping label with the provided label details and settings.
297298
@MainActor
298299
func purchaseLabel(shouldRefreshPackageAndRate: Bool) async {
300+
guard paymentMethod != nil else {
301+
showingPaymentMethods = true
302+
return
303+
}
299304
isPurchasingLabel = true
300305
labelPurchaseErrorNotice = nil
301306

0 commit comments

Comments
 (0)