[Apple Pay] Introduce new values for -apple-pay-button-type
[WebKit-https.git] / Source / WebCore / PAL / pal / spi / cocoa / PassKitSPI.h
1 /*
2  * Copyright (C) 2016-2017 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #if USE(APPLE_INTERNAL_SDK)
29
30 #import <PassKit/PassKit.h>
31 #import <PassKit/PKPaymentAuthorizationViewController_Private.h>
32 #import <PassKit/PKPaymentRequest_Private.h>
33
34 #else
35
36 #if PLATFORM(IOS)
37
38 #import <PassKit/PassKit.h>
39
40 #elif PLATFORM(MAC)
41
42 #import <Contacts/Contacts.h>
43 #import <Foundation/Foundation.h>
44
45 NS_ASSUME_NONNULL_BEGIN
46
47 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
48
49 @class PKPaymentAuthorizationResult;
50 @class PKPaymentRequestUpdate;
51 @class PKPaymentRequestPaymentMethodUpdate;
52 @class PKPaymentRequestShippingMethodUpdate;
53 @class PKPaymentRequestShippingContactUpdate;
54
55 typedef NSString *PKContactField;
56
57 extern NSString * const PKPaymentErrorDomain;
58 typedef NS_ERROR_ENUM(PKPaymentErrorDomain, PKPaymentErrorCode) {
59     PKPaymentUnknownError = -1,
60     PKPaymentShippingContactInvalidError = 1,
61     PKPaymentBillingContactInvalidError,
62     PKPaymentShippingAddressUnserviceableError,
63 };
64
65 #endif
66
67 typedef NS_OPTIONS(NSUInteger, PKAddressField) {
68     PKAddressFieldNone = 0UL,
69     PKAddressFieldPostalAddress = 1UL << 0,
70     PKAddressFieldPhone = 1UL << 1,
71     PKAddressFieldEmail = 1UL << 2,
72     PKAddressFieldName = 1UL << 3,
73     PKAddressFieldAll = (PKAddressFieldPostalAddress | PKAddressFieldPhone | PKAddressFieldEmail | PKAddressFieldName)
74 };
75
76 typedef NS_OPTIONS(NSUInteger, PKMerchantCapability) {
77     PKMerchantCapability3DS = 1UL << 0,
78     PKMerchantCapabilityEMV = 1UL << 1,
79     PKMerchantCapabilityCredit = 1UL << 2,
80     PKMerchantCapabilityDebit = 1UL << 3
81 };
82
83 typedef NS_ENUM(NSInteger, PKPaymentAuthorizationStatus) {
84     PKPaymentAuthorizationStatusSuccess,
85     PKPaymentAuthorizationStatusFailure,
86     PKPaymentAuthorizationStatusInvalidBillingPostalAddress,
87     PKPaymentAuthorizationStatusInvalidShippingPostalAddress,
88     PKPaymentAuthorizationStatusInvalidShippingContact,
89     PKPaymentAuthorizationStatusPINRequired,
90     PKPaymentAuthorizationStatusPINIncorrect,
91     PKPaymentAuthorizationStatusPINLockout,
92 };
93
94 typedef NS_ENUM(NSUInteger, PKPaymentMethodType) {
95     PKPaymentMethodTypeUnknown = 0,
96     PKPaymentMethodTypeDebit,
97     PKPaymentMethodTypeCredit,
98     PKPaymentMethodTypePrepaid,
99     PKPaymentMethodTypeStore
100 };
101
102 typedef NS_ENUM(NSUInteger, PKPaymentPassActivationState) {
103     PKPaymentPassActivationStateActivated,
104     PKPaymentPassActivationStateRequiresActivation,
105     PKPaymentPassActivationStateActivating,
106     PKPaymentPassActivationStateSuspended,
107     PKPaymentPassActivationStateDeactivated
108 };
109
110 typedef NS_ENUM(NSUInteger, PKPaymentSummaryItemType) {
111     PKPaymentSummaryItemTypeFinal,
112     PKPaymentSummaryItemTypePending
113 };
114
115 typedef NS_ENUM(NSUInteger, PKShippingType) {
116     PKShippingTypeShipping,
117     PKShippingTypeDelivery,
118     PKShippingTypeStorePickup,
119     PKShippingTypeServicePickup
120 };
121
122 typedef NSString * PKPaymentNetwork NS_EXTENSIBLE_STRING_ENUM;
123
124 @protocol PKPaymentAuthorizationViewControllerDelegate;
125
126 @interface PKObject : NSObject
127 @end
128
129 @interface PKPass : PKObject
130 @end
131
132 @interface PKPaymentPass : PKPass
133 @property (nonatomic, copy, readonly) NSString *primaryAccountIdentifier;
134 @property (nonatomic, copy, readonly) NSString *primaryAccountNumberSuffix;
135 @property (weak, readonly) NSString *deviceAccountIdentifier;
136 @property (weak, readonly) NSString *deviceAccountNumberSuffix;
137 @property (nonatomic, readonly) PKPaymentPassActivationState activationState;
138 @end
139
140 @interface PKPaymentMethod : NSObject
141 @property (nonatomic, copy, readonly, nullable) NSString *displayName;
142 @property (nonatomic, copy, readonly, nullable) PKPaymentNetwork network;
143 @property (nonatomic, readonly) PKPaymentMethodType type;
144 @property (nonatomic, copy, readonly, nullable) PKPaymentPass *paymentPass;
145 @end
146
147 @interface PKPaymentToken : NSObject
148 @property (nonatomic, strong, readonly) PKPaymentMethod *paymentMethod;
149 @property (nonatomic, copy, readonly) NSString *transactionIdentifier;
150 @property (nonatomic, copy, readonly) NSData *paymentData;
151 @end
152
153 @interface PKContact : NSObject
154 @property (nonatomic, strong, nullable) NSPersonNameComponents *name;
155 @property (nonatomic, strong, nullable) CNPostalAddress *postalAddress;
156 @property (nonatomic, strong, nullable) NSString *emailAddress;
157 @property (nonatomic, strong, nullable) CNPhoneNumber *phoneNumber;
158 @property (nonatomic, retain, nullable) NSString *supplementarySubLocality;
159 @end
160
161 @interface PKPayment : NSObject
162 @property (nonatomic, strong, readonly, nonnull) PKPaymentToken *token;
163 @property (nonatomic, strong, readonly, nullable) PKContact *billingContact;
164 @property (nonatomic, strong, readonly, nullable) PKContact *shippingContact;
165 @end
166
167 @interface PKPaymentSummaryItem : NSObject
168 + (instancetype)summaryItemWithLabel:(NSString *)label amount:(NSDecimalNumber *)amount;
169 + (instancetype)summaryItemWithLabel:(NSString *)label amount:(NSDecimalNumber *)amount type:(PKPaymentSummaryItemType)type;
170 @property (nonatomic, copy) NSString *label;
171 @property (nonatomic, copy) NSDecimalNumber *amount;
172 @end
173
174 @interface PKShippingMethod : PKPaymentSummaryItem
175 @property (nonatomic, copy, nullable) NSString *identifier;
176 @property (nonatomic, copy, nullable) NSString *detail;
177 @end
178
179 @interface PKPaymentRequest : NSObject
180 + (NSArray<PKPaymentNetwork> *)availableNetworks;
181 @property (nonatomic, copy) NSString *countryCode;
182 @property (nonatomic, copy) NSArray<PKPaymentNetwork> *supportedNetworks;
183 @property (nonatomic, assign) PKMerchantCapability merchantCapabilities;
184 @property (nonatomic, copy) NSArray<PKPaymentSummaryItem *> *paymentSummaryItems;
185 @property (nonatomic, copy) NSString *currencyCode;
186 @property (nonatomic, assign) PKAddressField requiredBillingAddressFields;
187 @property (nonatomic, strong, nullable) PKContact *billingContact;
188 @property (nonatomic, assign) PKAddressField requiredShippingAddressFields;
189 @property (nonatomic, strong, nullable) PKContact *shippingContact;
190 @property (nonatomic, copy, nullable) NSArray<PKShippingMethod *> *shippingMethods;
191 @property (nonatomic, assign) PKShippingType shippingType;
192 @property (nonatomic, copy, nullable) NSData *applicationData;
193 #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
194 @property (nonatomic, copy, nullable) NSSet<NSString *> *supportedCountries;
195 @property (nonatomic, strong) NSSet<PKContactField> *requiredShippingContactFields;
196 @property (nonatomic, strong) NSSet<PKContactField> *requiredBillingContactFields;
197 #endif
198 @end
199
200 @interface PKPaymentAuthorizationViewController : NSViewController
201 + (void)requestViewControllerWithPaymentRequest:(PKPaymentRequest *)paymentRequest completion:(void(^)(PKPaymentAuthorizationViewController *viewController, NSError *error))completion;
202 + (BOOL)canMakePayments;
203 @property (nonatomic, assign, nullable) id<PKPaymentAuthorizationViewControllerDelegate> delegate;
204 @end
205
206 @protocol PKPaymentAuthorizationViewControllerDelegate <NSObject>
207 @required
208
209 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
210 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment handler:(void (^)(PKPaymentAuthorizationResult *result))completion;
211 #else
212 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion;
213 #endif
214
215 - (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller;
216
217 @optional
218 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKPaymentSummaryItem *> *summaryItems))completion;
219 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> *shippingMethods, NSArray<PKPaymentSummaryItem *> *summaryItems))completion;
220 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectPaymentMethod:(PKPaymentMethod *)paymentMethod completion:(void (^)(NSArray<PKPaymentSummaryItem *> *summaryItems))completion;
221 @end
222
223 @interface PKPassLibrary : NSObject
224 @end
225
226 NS_ASSUME_NONNULL_END
227
228 #endif
229
230 NS_ASSUME_NONNULL_BEGIN
231
232 @protocol PKPaymentAuthorizationViewControllerPrivateDelegate;
233
234 @interface PKPaymentMerchantSession : NSObject <NSSecureCoding, NSCopying>
235 - (instancetype)initWithDictionary:(NSDictionary *)dictionary;
236 @end
237
238 @interface PKPaymentAuthorizationViewController ()
239 + (void)paymentServicesMerchantURL:(void(^)(NSURL *merchantURL, NSError *error))completion;
240 @property (nonatomic, assign, nullable) id<PKPaymentAuthorizationViewControllerPrivateDelegate> privateDelegate;
241 @end
242
243 @protocol PKPaymentAuthorizationViewControllerPrivateDelegate <NSObject>
244 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller willFinishWithError:(NSError *)error;
245
246 @optional
247 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didRequestMerchantSession:(void(^)(PKPaymentMerchantSession *, NSError *))sessionBlock;
248 @end
249
250 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101304) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110300)
251 typedef NS_ENUM(NSUInteger, PKPaymentRequestAPIType) {
252     PKPaymentRequestAPITypeInApp = 0,
253     PKPaymentRequestAPITypeWebJS,
254     PKPaymentRequestAPITypeWebPaymentRequest,
255 };
256
257 @interface PKPaymentRequest ()
258 @property (nonatomic, assign) PKPaymentRequestAPIType APIType;
259 @end
260 #endif
261
262 NS_ASSUME_NONNULL_END
263
264 #endif
265
266 #if PLATFORM(MAC) && !USE(APPLE_INTERNAL_SDK)
267 typedef NS_ENUM(NSInteger, PKPaymentButtonStyle) {
268     PKPaymentButtonStyleWhite = 0,
269     PKPaymentButtonStyleWhiteOutline,
270     PKPaymentButtonStyleBlack
271 };
272
273 typedef NS_ENUM(NSInteger, PKPaymentButtonType) {
274     PKPaymentButtonTypePlain = 0,
275     PKPaymentButtonTypeBuy,
276     PKPaymentButtonTypeSetUp,
277     PKPaymentButtonTypeInStore,
278     PKPaymentButtonTypeDonate,
279 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 120000)
280     PKPaymentButtonTypeCheckout,
281     PKPaymentButtonTypeBook,
282     PKPaymentButtonTypeSubscribe,
283 #endif
284 };
285 #endif
286
287 #if PLATFORM(MAC) && !USE(APPLE_INTERNAL_SDK) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
288
289 NS_ASSUME_NONNULL_BEGIN
290
291 @interface PKPaymentAuthorizationResult : NSObject
292 - (instancetype)initWithStatus:(PKPaymentAuthorizationStatus)status errors:(nullable NSArray<NSError *> *)errors;
293 @property (nonatomic, assign) PKPaymentAuthorizationStatus status;
294 @end
295
296 @interface PKPaymentRequestPaymentMethodUpdate : NSObject
297 - (instancetype)initWithPaymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)paymentSummaryItems;
298 @end
299
300 @interface PKPaymentRequestUpdate : NSObject
301 @end
302
303 @interface PKPaymentRequestShippingContactUpdate : PKPaymentRequestUpdate
304 - (instancetype)initWithPaymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)summaryItems shippingMethods:(nonnull NSArray<PKShippingMethod *> *)shippingMethods;
305 - (instancetype)initWithErrors:(nullable NSArray<NSError *> *)errors paymentSummaryItems:(nonnull NSArray<PKPaymentSummaryItem *> *)summaryItems shippingMethods:(nonnull NSArray<PKShippingMethod *> *)shippingMethods;
306 @end
307
308 NS_ASSUME_NONNULL_END
309
310 #endif
311
312 extern "C"
313 void PKDrawApplePayButton(_Nonnull CGContextRef, CGRect drawRect, CGFloat scale, PKPaymentButtonType, PKPaymentButtonStyle, NSString * _Nullable languageCode);
314
315 NS_ASSUME_NONNULL_BEGIN
316
317 @interface PKPassLibrary ()
318 - (void)openPaymentSetupForMerchantIdentifier:(NSString *)identifier domain:(NSString *)domain completion:(void(^)(BOOL success))completion;
319 @end
320
321 @interface PKPaymentRequest ()
322 @property (nonatomic, strong) NSString *sourceApplicationBundleIdentifier;
323 @property (nonatomic, strong) NSString *sourceApplicationSecondaryIdentifier;
324 @property (nonatomic, strong) NSString *CTDataConnectionServiceType;
325 @end
326
327 NS_ASSUME_NONNULL_END