a0c7b9984e7ee719975959062859254395df9109
[WebKit-https.git] / Source / WebCore / platform / spi / cocoa / PassKitSPI.h
1 /*
2  * Copyright (C) 2016 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
33 #else
34
35 #if PLATFORM(IOS)
36
37 #import <PassKit/PassKit.h>
38
39 #elif PLATFORM(MAC)
40
41 #import <Contacts/Contacts.h>
42 #import <Foundation/Foundation.h>
43
44 NS_ASSUME_NONNULL_BEGIN
45
46 typedef NS_OPTIONS(NSUInteger, PKAddressField) {
47     PKAddressFieldNone = 0UL,
48     PKAddressFieldPostalAddress = 1UL << 0,
49     PKAddressFieldPhone = 1UL << 1,
50     PKAddressFieldEmail = 1UL << 2,
51     PKAddressFieldName = 1UL << 3,
52     PKAddressFieldAll = (PKAddressFieldPostalAddress|PKAddressFieldPhone|PKAddressFieldEmail|PKAddressFieldName)
53 };
54
55 typedef NS_OPTIONS(NSUInteger, PKMerchantCapability) {
56     PKMerchantCapability3DS = 1UL << 0,
57     PKMerchantCapabilityEMV = 1UL << 1,
58     PKMerchantCapabilityCredit = 1UL << 2,
59     PKMerchantCapabilityDebit = 1UL << 3
60 };
61
62 typedef NS_ENUM(NSInteger, PKPaymentAuthorizationStatus) {
63     PKPaymentAuthorizationStatusSuccess,
64     PKPaymentAuthorizationStatusFailure,
65     PKPaymentAuthorizationStatusInvalidBillingPostalAddress,
66     PKPaymentAuthorizationStatusInvalidShippingPostalAddress,
67     PKPaymentAuthorizationStatusInvalidShippingContact,
68     PKPaymentAuthorizationStatusPINRequired,
69     PKPaymentAuthorizationStatusPINIncorrect,
70     PKPaymentAuthorizationStatusPINLockout,
71 };
72
73 typedef NS_ENUM(NSUInteger, PKPaymentMethodType) {
74     PKPaymentMethodTypeUnknown = 0,
75     PKPaymentMethodTypeDebit,
76     PKPaymentMethodTypeCredit,
77     PKPaymentMethodTypePrepaid,
78     PKPaymentMethodTypeStore
79 };
80
81 typedef NS_ENUM(NSUInteger, PKPaymentPassActivationState) {
82     PKPaymentPassActivationStateActivated,
83     PKPaymentPassActivationStateRequiresActivation,
84     PKPaymentPassActivationStateActivating,
85     PKPaymentPassActivationStateSuspended,
86     PKPaymentPassActivationStateDeactivated
87 };
88
89 typedef NS_ENUM(NSUInteger, PKPaymentSummaryItemType) {
90     PKPaymentSummaryItemTypeFinal,
91     PKPaymentSummaryItemTypePending
92 };
93
94 typedef NS_ENUM(NSUInteger, PKShippingType) {
95     PKShippingTypeShipping,
96     PKShippingTypeDelivery,
97     PKShippingTypeStorePickup,
98     PKShippingTypeServicePickup
99 };
100
101 typedef NSString * PKPaymentNetwork NS_EXTENSIBLE_STRING_ENUM;
102
103 @protocol PKPaymentAuthorizationViewControllerDelegate;
104
105 @interface PKObject : NSObject
106 @end
107
108 @interface PKPass : PKObject
109 @end
110
111 @interface PKPaymentPass : PKPass
112 @property (nonatomic, copy, readonly) NSString *primaryAccountIdentifier;
113 @property (nonatomic, copy, readonly) NSString *primaryAccountNumberSuffix;
114 @property (weak, readonly) NSString *deviceAccountIdentifier;
115 @property (weak, readonly) NSString *deviceAccountNumberSuffix;
116 @property (nonatomic, readonly) PKPaymentPassActivationState activationState;
117 @end
118
119 @interface PKPaymentMethod : NSObject
120 @property (nonatomic, copy, readonly, nullable) NSString *displayName;
121 @property (nonatomic, copy, readonly, nullable) PKPaymentNetwork network;
122 @property (nonatomic, readonly) PKPaymentMethodType type;
123 @property (nonatomic, copy, readonly, nullable) PKPaymentPass *paymentPass;
124 @end
125
126 @interface PKPaymentToken : NSObject
127 @property (nonatomic, strong, readonly) PKPaymentMethod *paymentMethod;
128 @property (nonatomic, copy, readonly) NSString *transactionIdentifier;
129 @property (nonatomic, copy, readonly) NSData *paymentData;
130 @end
131
132 @interface PKContact : NSObject
133 @property (nonatomic, strong, nullable) NSPersonNameComponents *name;
134 @property (nonatomic, strong, nullable) CNPostalAddress *postalAddress;
135 @property (nonatomic, strong, nullable) NSString *emailAddress;
136 @property (nonatomic, strong, nullable) CNPhoneNumber *phoneNumber;
137 @property (nonatomic, retain, nullable) NSString *supplementarySubLocality;
138 @end
139
140 @interface PKPayment : NSObject
141 @property (nonatomic, strong, readonly, nonnull) PKPaymentToken *token;
142 @property (nonatomic, strong, readonly, nullable) PKContact *billingContact;
143 @property (nonatomic, strong, readonly, nullable) PKContact *shippingContact;
144 @end
145
146 @interface PKPaymentSummaryItem : NSObject
147 + (instancetype)summaryItemWithLabel:(NSString *)label amount:(NSDecimalNumber *)amount;
148 + (instancetype)summaryItemWithLabel:(NSString *)label amount:(NSDecimalNumber *)amount type:(PKPaymentSummaryItemType)type;
149 @property (nonatomic, copy) NSString *label;
150 @property (nonatomic, copy) NSDecimalNumber *amount;
151 @end
152
153 @interface PKShippingMethod : PKPaymentSummaryItem
154 @property (nonatomic, copy, nullable) NSString *identifier;
155 @property (nonatomic, copy, nullable) NSString *detail;
156 @end
157
158 @interface PKPaymentRequest : NSObject
159 @property (nonatomic, copy) NSString *countryCode;
160 @property (nonatomic, copy) NSArray<PKPaymentNetwork> *supportedNetworks;
161 @property (nonatomic, assign) PKMerchantCapability merchantCapabilities;
162 @property (nonatomic, copy) NSArray<PKPaymentSummaryItem *> *paymentSummaryItems;
163 @property (nonatomic, copy) NSString *currencyCode;
164 @property (nonatomic, assign) PKAddressField requiredBillingAddressFields;
165 @property (nonatomic, strong, nullable) PKContact *billingContact;
166 @property (nonatomic, assign) PKAddressField requiredShippingAddressFields;
167 @property (nonatomic, strong, nullable) PKContact *shippingContact;
168 @property (nonatomic, copy, nullable) NSArray<PKShippingMethod *> *shippingMethods;
169 @property (nonatomic, assign) PKShippingType shippingType;
170 @property (nonatomic, copy, nullable) NSData *applicationData;
171 @end
172
173 @interface PKPaymentAuthorizationViewController : NSViewController
174 + (void)requestViewControllerWithPaymentRequest:(PKPaymentRequest *)paymentRequest completion:(void(^)(PKPaymentAuthorizationViewController *viewController, NSError *error))completion;
175 + (BOOL)canMakePayments;
176 @property (nonatomic, assign, nullable) id<PKPaymentAuthorizationViewControllerDelegate> delegate;
177 @end
178
179 @protocol PKPaymentAuthorizationViewControllerDelegate <NSObject>
180 @required
181 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didAuthorizePayment:(PKPayment *)payment completion:(void (^)(PKPaymentAuthorizationStatus status))completion;
182 - (void)paymentAuthorizationViewControllerDidFinish:(PKPaymentAuthorizationViewController *)controller;
183
184 @optional
185 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingMethod:(PKShippingMethod *)shippingMethod completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKPaymentSummaryItem *> *summaryItems))completion;
186 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectShippingContact:(PKContact *)contact completion:(void (^)(PKPaymentAuthorizationStatus status, NSArray<PKShippingMethod *> *shippingMethods, NSArray<PKPaymentSummaryItem *> *summaryItems))completion;
187 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didSelectPaymentMethod:(PKPaymentMethod *)paymentMethod completion:(void (^)(NSArray<PKPaymentSummaryItem *> *summaryItems))completion;
188 @end
189
190 NS_ASSUME_NONNULL_END
191
192 #endif
193
194 NS_ASSUME_NONNULL_BEGIN
195
196 @protocol PKPaymentAuthorizationViewControllerPrivateDelegate;
197
198 @interface PKPaymentMerchantSession : NSObject <NSSecureCoding, NSCopying>
199 - (instancetype)initWithDictionary:(NSDictionary *)dictionary;
200 @end
201
202 @interface PKPaymentAuthorizationViewController ()
203 + (void)paymentServicesMerchantURL:(void(^)(NSURL *merchantURL, NSError *error))completion;
204 @property (nonatomic, assign, nullable) id<PKPaymentAuthorizationViewControllerPrivateDelegate> privateDelegate;
205 @end
206
207 @protocol PKPaymentAuthorizationViewControllerPrivateDelegate <NSObject>
208 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller willFinishWithError:(NSError *)error;
209
210 @optional
211 - (void)paymentAuthorizationViewController:(PKPaymentAuthorizationViewController *)controller didRequestMerchantSession:(void(^)(PKPaymentMerchantSession *, NSError *))sessionBlock;
212 @end
213
214 NS_ASSUME_NONNULL_END
215
216 #endif