Skip to content

Commit

Permalink
Changes for PassKit Xcode15
Browse files Browse the repository at this point in the history
  • Loading branch information
tj_devel709 committed Oct 16, 2023
1 parent c661ef5 commit 2de0968
Show file tree
Hide file tree
Showing 14 changed files with 319 additions and 287 deletions.
37 changes: 36 additions & 1 deletion src/PassKit/PKEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public enum PKMerchantCapability : ulong {
ThreeDS = 1 << 0,
EMV = 1 << 1,
Credit = 1 << 2,
Debit = 1 << 3
Debit = 1 << 3,
[iOS (17, 0), Mac (14, 0), Watch (10, 0), NoTV, MacCatalyst (17, 0)]
InstantFundsOut = 1 << 7,
}

[NoMac]
Expand Down Expand Up @@ -386,4 +388,37 @@ public enum PKVehicleConnectionSessionConnectionState : long {
Connecting,
FailedToConnect,
}

[iOS (17, 0), Mac (14, 0), Watch (10, 0), TV (17, 0), MacCatalyst (17, 0)]
[Native]
public enum PKApplePayLaterAvailability : long {
Available,
UnavailableItemIneligible,
UnavailableRecurringTransaction,
}

[NoWatch, NoTV, NoMac, iOS (17, 0), MacCatalyst (17, 0)]
[Native]
[ErrorDomain ("PKDisbursementErrorDomain")]
public enum PKDisbursementErrorCode : long {
UnknownError = -1,
UnsupportedCardError = 1,
RecipientContactInvalidError,
}

[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst]
[Native]
public enum PKPayLaterAction : long {
LearnMore = 0,
Calculator,
}

[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst]
[Native]
public enum PKPayLaterDisplayStyle : long {
Standard = 0,
Badge,
Checkout,
Price,
}
}
66 changes: 66 additions & 0 deletions src/PassKit/PKPayLaterView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#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 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
using var nsCurrencyCode = new NSString (currencyCode);
PKPayLaterValidateAmount (amount.Handle, nsCurrencyCode.Handle, &block);
}
}

[DllImport (Constants.PassKitLibrary)]
unsafe static extern void PKPayLaterValidateAmount (IntPtr /* NSDecimalNumber */ amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback);
}
}

#endif
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,7 @@ PASSKIT_API_SOURCES = \

PASSKIT_SOURCES = \
PassKit/PKCompat.cs \
PassKit/PKPayLaterView.cs \
PassKit/PKPaymentRequest.cs \
PassKit/PKShareablePassMetadata.cs \

Expand Down
171 changes: 169 additions & 2 deletions src/passkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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; }
Expand All @@ -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

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 { }
Expand Down Expand Up @@ -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

[NoWatch]
[iOS (12, 2)]
Expand All @@ -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
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)]
Expand Down Expand Up @@ -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; }
}
Expand Down Expand Up @@ -2645,4 +2754,62 @@ interface PKDeferredPaymentRequest {
[DesignatedInitializer]
NativeHandle Constructor (string paymentDescription, PKDeferredPaymentSummaryItem deferredBilling, NSUrl managementUrl);
}

[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst]
[BaseType (typeof (UIView))]
[DisableDefaultCtor]
interface PKPayLaterView {
// [DesignatedInitializer]
[Export ("initWithAmount:currencyCode:")]
NativeHandle Constructor (NSDecimalNumber amount, string currencyCode);

[Export ("delegate", ArgumentSemantic.Assign)]
IPKPayLaterViewDelegate Delegate { 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 {
}
}
Loading

0 comments on commit 2de0968

Please sign in to comment.