@@ -47,7 +47,7 @@ struct ApplePayButton: View {
47
47
private let eventHandlers : EventHandlers
48
48
49
49
/// The Apple Pay button label style
50
- private var label : PayWithApplePayButtonLabel = . plain
50
+ private var label : ApplePayButtonLabel = . plain
51
51
52
52
/// The corner radius for the button
53
53
private let cornerRadius : CGFloat ?
@@ -80,7 +80,7 @@ struct ApplePayButton: View {
80
80
}
81
81
}
82
82
83
- public func withLabel ( _ label: PayWithApplePayButtonLabel ) -> some View {
83
+ public func label ( _ label: ApplePayButtonLabel ) -> some View {
84
84
var view = self
85
85
view. label = label
86
86
return view
@@ -93,7 +93,7 @@ struct ApplePayButton: View {
93
93
@available ( macOS, unavailable)
94
94
struct Internal_ApplePayButton : View {
95
95
/// The Apple Pay button label style
96
- private var label : PayWithApplePayButtonLabel = . plain
96
+ private var label : ApplePayButtonLabel = . plain
97
97
98
98
/// The view controller for the Apple Pay button
99
99
private var controller : ApplePayViewController
@@ -109,7 +109,7 @@ struct Internal_ApplePayButton: View {
109
109
/// - eventHandlers: The event handlers for checkout events (defaults to EventHandlers())
110
110
init (
111
111
identifier: CheckoutIdentifier ,
112
- label: PayWithApplePayButtonLabel ,
112
+ label: ApplePayButtonLabel ,
113
113
configuration: ApplePayConfigurationWrapper ,
114
114
eventHandlers: EventHandlers = EventHandlers ( ) ,
115
115
cornerRadius: CGFloat ?
@@ -132,15 +132,100 @@ struct Internal_ApplePayButton: View {
132
132
133
133
var body : some View {
134
134
PayWithApplePayButton (
135
- label,
135
+ label. toPayWithApplePayButtonLabel ,
136
136
action: {
137
137
Task { await controller. startPayment ( ) }
138
138
} ,
139
139
fallback: {
140
- // content == nil ? Text("errors.applePay.unsupported") : content
141
140
Text ( " errors.applePay.unsupported " . localizedString)
142
141
}
143
142
)
144
143
. walletButtonStyle ( cornerRadius: cornerRadius)
145
144
}
146
145
}
146
+
147
+ /// Used to set the label of the Apple Pay button
148
+ /// see `.applePayLabel(label:)`
149
+ public enum ApplePayButtonLabel {
150
+ /// A button with the Apple Pay logo only
151
+ case plain
152
+ /// A button that uses the phrase "Buy with" in conjunction with the Apple Pay logo
153
+ case buy
154
+ /// A button that uses the phrase "Add Money with" in conjunction with the Apple Pay logo
155
+ case addMoney
156
+ /// A button that uses the phrase "Book with" in conjunction with the Apple Pay logo
157
+ case book
158
+ /// A button that uses the phrase "Check out with" in conjunction with the Apple Pay logo
159
+ case checkout
160
+ /// A button that uses the phrase "Continue with" in conjunction with the Apple Pay logo
161
+ case `continue`
162
+ /// A button that uses the phrase "Contribute with" in conjunction with the Apple Pay logo
163
+ case contribute
164
+ /// A button that uses the phrase "Donate with" in conjunction with the Apple Pay logo
165
+ case donate
166
+ /// A button that uses the phrase "Pay with" in conjunction with the Apple Pay logo
167
+ case inStore
168
+ /// A button that uses the phrase "Order with" in conjunction with the Apple Pay logo
169
+ case order
170
+ /// A button that uses the phrase "Reload with" in conjunction with the Apple Pay logo
171
+ case reload
172
+ /// A button that uses the phrase "Rent with" in conjunction with the Apple Pay logo
173
+ case rent
174
+ /// A button that prompts the user to set up Apple Pay
175
+ case setUp
176
+ /// A button that uses the phrase "Subscribe with" in conjunction with the Apple Pay logo
177
+ case subscribe
178
+ /// A button that uses the phrase "Support with" in conjunction with the Apple Pay logo
179
+ case support
180
+ /// A button that uses the phrase "Tip with" in conjunction with the Apple Pay logo
181
+ case tip
182
+ /// A button that uses the phrase "Top Up with" in conjunction with the Apple Pay logo
183
+ case topUp
184
+
185
+ /// SwiftUI interop - will be removed when migrating to support iOS 15
186
+ @available ( iOS 17 . 0 , * )
187
+ var toPayWithApplePayButtonLabel : PayWithApplePayButtonLabel {
188
+ switch self {
189
+ case . plain: return . plain
190
+ case . buy: return . buy
191
+ case . addMoney: return . addMoney
192
+ case . book: return . book
193
+ case . checkout: return . checkout
194
+ case . continue: return . continue
195
+ case . contribute: return . contribute
196
+ case . donate: return . donate
197
+ case . inStore: return . inStore
198
+ case . order: return . order
199
+ case . reload: return . reload
200
+ case . rent: return . rent
201
+ case . setUp: return . setUp
202
+ case . subscribe: return . subscribe
203
+ case . support: return . support
204
+ case . tip: return . tip
205
+ case . topUp: return . topUp
206
+ }
207
+ }
208
+
209
+ @available ( iOS 15 . 0 , * )
210
+ var toPKPaymentButtonType : PKPaymentButtonType {
211
+ switch self {
212
+ case . plain: return . plain
213
+ case . buy: return . buy
214
+ case . addMoney: return . addMoney
215
+ case . book: return . book
216
+ case . checkout: return . checkout
217
+ case . continue: return . continue
218
+ case . contribute: return . contribute
219
+ case . donate: return . donate
220
+ case . inStore: return . inStore
221
+ case . order: return . order
222
+ case . reload: return . reload
223
+ case . rent: return . rent
224
+ case . setUp: return . setUp
225
+ case . subscribe: return . subscribe
226
+ case . support: return . support
227
+ case . tip: return . tip
228
+ case . topUp: return . topUp
229
+ }
230
+ }
231
+ }
0 commit comments