-
Notifications
You must be signed in to change notification settings - Fork 516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PassKit] Add support Xcode15 Beta 7 #19139
Changes from 3 commits
2de0968
c91f292
d167a8a
049c2de
984f796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#nullable enable | ||
|
||
#if IOS && !__MACCATALYST__ | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Runtime.CompilerServices; | ||
using ObjCRuntime; | ||
using Foundation; | ||
using PassKit; | ||
|
||
#if !NET | ||
using NativeHandle = System.IntPtr; | ||
#endif | ||
|
||
namespace PassKit { | ||
|
||
public partial class PKPayLaterView { | ||
|
||
#if !NET | ||
delegate void PKPayLaterValidateAmountCompletionHandler (IntPtr block, byte eligible); | ||
static PKPayLaterValidateAmountCompletionHandler static_ValidateAmount = TrampolineValidateAmount; | ||
|
||
[MonoPInvokeCallback (typeof (PKPayLaterValidateAmountCompletionHandler))] | ||
#else | ||
[UnmanagedCallersOnly] | ||
#endif | ||
static void TrampolineValidateAmount (IntPtr block, byte eligible) | ||
{ | ||
var del = BlockLiteral.GetTarget<Action<bool>> (block); | ||
if (del is not null) { | ||
del (eligible != 0); | ||
} | ||
} | ||
|
||
#if NET | ||
[SupportedOSPlatform ("ios17.0")] | ||
[UnsupportedOSPlatform ("maccatalyst")] | ||
[UnsupportedOSPlatform ("macos")] | ||
[UnsupportedOSPlatform ("tvos")] | ||
#endif | ||
[BindingImpl (BindingImplOptions.Optimizable)] | ||
public static void ValidateAmount (NSDecimalNumber amount, string currencyCode, Action<bool> callback) | ||
{ | ||
if (callback is null) | ||
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback)); | ||
|
||
unsafe { | ||
#if NET | ||
delegate* unmanaged<IntPtr, byte, void> trampoline = &TrampolineValidateAmount; | ||
using var block = new BlockLiteral (trampoline, callback, typeof (PKPayLaterView), nameof (TrampolineValidateAmount)); | ||
#else | ||
using var block = new BlockLiteral (); | ||
block.SetupBlockUnsafe (static_ValidateAmount, callback); | ||
#endif | ||
var nsCurrencyCodePtr = NSString.CreateNative (currencyCode); | ||
try { | ||
PKPayLaterValidateAmount (amount.Handle, nsCurrencyCodePtr, &block); | ||
} finally { | ||
NSString.ReleaseNative (nsCurrencyCodePtr); | ||
} | ||
} | ||
} | ||
|
||
[DllImport (Constants.PassKitLibrary)] | ||
unsafe static extern void PKPayLaterValidateAmount (IntPtr /* NSDecimalNumber */ amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback); | ||
} | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
using UIViewController = AppKit.NSViewController; | ||
using UIWindow = AppKit.NSWindow; | ||
using UIControl = AppKit.NSControl; | ||
using UIView = AppKit.NSView; | ||
#else | ||
using UIKit; | ||
#if IOS | ||
|
@@ -406,6 +407,10 @@ interface PKPaymentAuthorizationViewController { | |
[Export ("initWithPaymentRequest:")] | ||
NativeHandle Constructor (PKPaymentRequest request); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Export ("initWithDisbursementRequest:")] | ||
NativeHandle Constructor (PKDisbursementRequest request); | ||
|
||
[Export ("delegate", ArgumentSemantic.UnsafeUnretained)] | ||
[NullAllowed] | ||
NSObject WeakDelegate { get; set; } | ||
|
@@ -425,6 +430,21 @@ interface PKPaymentAuthorizationViewController { | |
[Static] | ||
[Export ("canMakePaymentsUsingNetworks:capabilities:")] | ||
bool CanMakePaymentsUsingNetworks (string [] supportedNetworks, PKMerchantCapability capabilties); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Static] | ||
[Export ("supportsDisbursements")] | ||
bool SupportsDisbursements (); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Static] | ||
[Export ("supportsDisbursementsUsingNetworks:")] | ||
bool SupportsDisbursements (string [] supportedNetworks); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Static] | ||
[Export ("supportsDisbursementsUsingNetworks:capabilities:")] | ||
bool SupportsDisbursements (string [] supportedNetworks, PKMerchantCapability capabilities); | ||
} | ||
#endif | ||
|
||
|
@@ -646,6 +666,10 @@ interface PKPaymentRequest { | |
[NoWatch, Mac (13, 3), iOS (16, 4), MacCatalyst (16, 4), NoTV] | ||
[Export ("deferredPaymentRequest", ArgumentSemantic.Strong)] | ||
PKDeferredPaymentRequest DeferredPaymentRequest { get; set; } | ||
|
||
[iOS (17, 0), Mac (14, 0), Watch (10, 0), NoTV, MacCatalyst (17, 0)] | ||
[Export ("applePayLaterAvailability", ArgumentSemantic.Assign)] | ||
PKApplePayLaterAvailability ApplePayLaterAvailability { get; set; } | ||
} | ||
|
||
[Mac (11, 0)] | ||
|
@@ -1141,6 +1165,14 @@ interface PKPaymentNetwork { | |
[iOS (16, 0), Mac (13, 0), Watch (9, 0), NoTV, MacCatalyst (16, 0)] | ||
[Field ("PKPaymentNetworkBancontact")] | ||
NSString Bancontact { get; } | ||
|
||
[iOS (17, 0), Mac (14, 0), Watch (10, 0), NoTV, MacCatalyst (17, 0)] | ||
[Field ("PKPaymentNetworkPagoBancomat")] | ||
NSString PagoBancomat { get; } | ||
|
||
[iOS (17, 0), Mac (14, 0), Watch (10, 0), NoTV, MacCatalyst (17, 0)] | ||
[Field ("PKPaymentNetworkTmoney")] | ||
NSString Tmoney { get; } | ||
} | ||
|
||
#if !WATCH | ||
|
@@ -1229,6 +1261,25 @@ interface PKPaymentAuthorizationController { | |
[Async] | ||
[Export ("dismissWithCompletion:")] | ||
void Dismiss ([NullAllowed] Action completion); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Static] | ||
[Export ("supportsDisbursements")] | ||
bool SupportsDisbursements (); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Static] | ||
[Export ("supportsDisbursementsUsingNetworks:")] | ||
bool SupportsDisbursements (string [] supportedNetworks); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Static] | ||
[Export ("supportsDisbursementsUsingNetworks:capabilities:")] | ||
bool SupportsDisbursements (string [] supportedNetworks, PKMerchantCapability capabilities); | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Export ("initWithDisbursementRequest:")] | ||
NativeHandle Constructor (PKDisbursementRequest request); | ||
} | ||
|
||
interface IPKPaymentAuthorizationControllerDelegate { } | ||
|
@@ -1554,15 +1605,19 @@ interface PKPaymentErrorKeys { | |
|
||
interface IPKDisbursementAuthorizationControllerDelegate { } | ||
|
||
#if !XAMCORE_5_0 | ||
[NoMac] // only used in non-macOS API | ||
[NoWatch] | ||
[iOS (12, 2)] | ||
[MacCatalyst (13, 1)] | ||
[Obsoleted (PlatformName.iOS, 17, 0, message: "No longer used.")] | ||
[Obsoleted (PlatformName.MacCatalyst, 17, 0, message: "No longer used.")] | ||
[Native] | ||
public enum PKDisbursementRequestSchedule : long { | ||
OneTime, | ||
Future, | ||
} | ||
#endif | ||
tj-devel709 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[NoWatch] | ||
[iOS (12, 2)] | ||
|
@@ -1571,11 +1626,65 @@ public enum PKDisbursementRequestSchedule : long { | |
[BaseType (typeof (NSObject))] | ||
interface PKDisbursementRequest { | ||
|
||
#if XAMCORE_5_0 | ||
[Export ("currencyCode")] | ||
#else | ||
[NullAllowed, Export ("currencyCode")] | ||
#endif | ||
string CurrencyCode { get; set; } | ||
|
||
#if XAMCORE_5_0 | ||
[Export ("summaryItems", ArgumentSemantic.Copy)] | ||
#else | ||
[NullAllowed, Export ("summaryItems", ArgumentSemantic.Copy)] | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have mixed feelings about this two #if.. in one hand I do understand them, we moved from 'string?' to 'string'. Peres is not an API breaking change, and code will compile unless the developer has the nullability warnings sets as errors. So the removal of the ? will move use from a possible runtime error (we passed null) to a compiler warning possible error. I prefer users to get a warning than a runtime error in their applications when they are deployed to iOS 15 and later, specially when we do not have a clear date for XAMCORE_5_0. @dalexsoto @rolfbjarne thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other side is that if the API is actually nullable (for instance by accident on Apple's side), removing the nullability on our side will now result in a C# exception (ArgumentNullException) when the code previously worked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CurrencyCode might have not been an accident based on the documentation from the service https://developer.apple.com/documentation/passkit/apple_pay/payment_token_format_reference?language=objc
And it uses https://www.iso.org/iso-4217-currency-codes.html which AFAIK does not have a way to represent null. Similar to the summary items https://developer.apple.com/documentation/passkit/pkdisbursementrequest/3112810-summaryitems?changes=l_4&language=objc
If we allow null values, the requests to the payment service won't be valid at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either way works for me :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My take is that we should try to expose the truth of the headers as much as we can, in this case: -@property (nonatomic, copy, nullable) NSArray<PKPaymentSummaryItem *> *summaryItems API_AVAILABLE(ios(12.2)) API_UNAVAILABLE(tvos, watchos, macos);
+@property (nonatomic, copy) NSArray<PKPaymentSummaryItem *> *summaryItems; Apple in theory has audited this header for nullability (see Also from the docs standpoint it changed: -// The summary items are optional. The final amount summary item will be prepopulated by the amount specified above.
+// Array of PKPaymentSummaryItem objects which should be presented to the user.
+// The last item should be the total you wish to disburse, and should not be pending. So from the wording I think the change is intentional, it kind of matches what it is being done with the API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good! I went ahead and removed those Xamcore conditionals! @rolfbjarne @mandel-macaque |
||
PKPaymentSummaryItem [] SummaryItems { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Export ("merchantIdentifier")] | ||
string MerchantIdentifier { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Export ("regionCode")] | ||
string RegionCode { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Export ("supportedNetworks", ArgumentSemantic.Copy)] | ||
string [] SupportedNetworks { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Export ("merchantCapabilities", ArgumentSemantic.Assign)] | ||
PKMerchantCapability MerchantCapabilities { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Export ("requiredRecipientContactFields", ArgumentSemantic.Strong)] | ||
string [] RequiredRecipientContactFields { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[NullAllowed, Export ("recipientContact", ArgumentSemantic.Strong)] | ||
PKContact RecipientContact { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[NullAllowed, Export ("supportedRegions", ArgumentSemantic.Copy)] | ||
string [] SupportedRegions { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[NullAllowed, Export ("applicationData", ArgumentSemantic.Copy)] | ||
NSData ApplicationData { get; set; } | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Export ("initWithMerchantIdentifier:currencyCode:regionCode:supportedNetworks:merchantCapabilities:summaryItems:")] | ||
NativeHandle Constructor (string merchantIdentifier, string currencyCode, string regionCode, string [] supportedNetworks, PKMerchantCapability merchantCapabilities, PKPaymentSummaryItem [] summaryItems); | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Static] | ||
[Export ("disbursementContactInvalidErrorWithContactField:localizedDescription:")] | ||
NSError GetDisbursementContactInvalidError (string field, [NullAllowed] string localizedDescription); | ||
|
||
[iOS (17, 0), NoMac, NoWatch, NoTV, NoMacCatalyst] | ||
[Static] | ||
[Export ("disbursementCardUnsupportedError")] | ||
NSError DisbursementCardUnsupportedError { get; } | ||
} | ||
|
||
[Mac (11, 0)] | ||
|
@@ -1671,12 +1780,12 @@ interface PKAddCarKeyPassConfiguration { | |
PKRadioTechnology SupportedRadioTechnologies { get; set; } | ||
|
||
// headers say [Watch (9,0)] but PKAddSecureElementPassConfiguration is not supported for watch | ||
[iOS (16, 0), Mac (13, 0), NoMacCatalyst, NoTV, NoWatch] | ||
[iOS (16, 0), Mac (13, 0), MacCatalyst (16, 0), NoTV, NoWatch] | ||
[Export ("manufacturerIdentifier")] | ||
string ManufacturerIdentifier { get; set; } | ||
|
||
// headers say [Watch (9,0)] but PKAddSecureElementPassConfiguration is not supported for watch | ||
[iOS (16, 0), Mac (13, 0), NoMacCatalyst, NoTV, NoWatch] | ||
[iOS (16, 0), Mac (13, 0), MacCatalyst (16, 0), NoTV, NoWatch] | ||
[NullAllowed, Export ("provisioningTemplateIdentifier", ArgumentSemantic.Strong)] | ||
string ProvisioningTemplateIdentifier { get; set; } | ||
} | ||
|
@@ -2645,4 +2754,65 @@ interface PKDeferredPaymentRequest { | |
[DesignatedInitializer] | ||
NativeHandle Constructor (string paymentDescription, PKDeferredPaymentSummaryItem deferredBilling, NSUrl managementUrl); | ||
} | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst] | ||
[BaseType (typeof (UIView))] | ||
[DisableDefaultCtor] | ||
interface PKPayLaterView { | ||
|
||
[Export ("initWithAmount:currencyCode:")] | ||
NativeHandle Constructor (NSDecimalNumber amount, string currencyCode); | ||
|
||
[NullAllowed, Wrap ("WeakDelegate")] | ||
IPKPayLaterViewDelegate Delegate { get; set; } | ||
|
||
[NullAllowed, Export ("delegate", ArgumentSemantic.Assign)] | ||
NSObject WeakDelegate { get; set; } | ||
|
||
[Export ("amount", ArgumentSemantic.Copy)] | ||
NSDecimalNumber Amount { get; set; } | ||
|
||
[Export ("currencyCode")] | ||
string CurrencyCode { get; set; } | ||
|
||
[Export ("displayStyle", ArgumentSemantic.Assign)] | ||
PKPayLaterDisplayStyle DisplayStyle { get; set; } | ||
|
||
[Export ("action", ArgumentSemantic.Assign)] | ||
PKPayLaterAction Action { get; set; } | ||
} | ||
|
||
interface IPKPayLaterViewDelegate { } | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst] | ||
#if NET | ||
[Protocol, Model] | ||
#else | ||
[Protocol, Model (AutoGeneratedName = true)] | ||
#endif | ||
[BaseType (typeof (NSObject))] | ||
interface PKPayLaterViewDelegate { | ||
[Abstract] | ||
[Export ("payLaterViewDidUpdateHeight:")] | ||
void PayLaterViewDidUpdateHeight (PKPayLaterView view); | ||
} | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[Static] | ||
interface PKDirbursementError { | ||
[Field ("PKDisbursementErrorContactFieldUserInfoKey")] | ||
NSString ContactFieldUserInfoKey { get; } | ||
} | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[BaseType (typeof (PKPaymentSummaryItem))] | ||
[DisableDefaultCtor] | ||
interface PKInstantFundsOutFeeSummaryItem : NSCoding, NSCopying, NSSecureCoding { | ||
} | ||
|
||
[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)] | ||
[BaseType (typeof (PKPaymentSummaryItem))] | ||
[DisableDefaultCtor] | ||
interface PKDisbursementSummaryItem : NSCoding, NSCopying, NSSecureCoding { | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact, 'TMoney' was my fake rapper name in Jr. Highschool