forked from xamarin/xamarin-macios
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tj_devel709
committed
Oct 9, 2023
1 parent
1158356
commit bca6d1c
Showing
4 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#nullable enable | ||
|
||
#if IOS | ||
|
||
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, bool eligible); | ||
static PKPayLaterValidateAmountCompletionHandler static_ValidateAmount = TrampolineValidateAmount; | ||
|
||
[MonoPInvokeCallback (typeof (PKPayLaterValidateAmountCompletionHandler))] | ||
#else | ||
[UnmanagedCallersOnly] | ||
#endif | ||
static void TrampolineValidateAmount (IntPtr block, bool eligible) | ||
{ | ||
var del = BlockLiteral.GetTarget<Action<bool>> (block); | ||
if (del is not null) { | ||
del (eligible); | ||
} | ||
} | ||
|
||
#if NET | ||
[SupportedOSPlatform ("ios17.0")] | ||
[UnsupportedOSPlatform ("macos")] | ||
[UnsupportedOSPlatform ("maccatalyst")] | ||
[UnsupportedOSPlatform ("tvos")] | ||
#else | ||
[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst] | ||
#endif | ||
[BindingImpl (BindingImplOptions.Optimizable)] | ||
public void ValidateAmount (decimal amount, string currencyCode, Action<bool> callback) | ||
{ | ||
if (callback is null) | ||
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (callback)); | ||
|
||
unsafe { | ||
#if NET | ||
delegate* unmanaged<IntPtr, bool, 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, nsCurrencyCode.Handle, &block); | ||
} | ||
} | ||
|
||
#if NET | ||
[SupportedOSPlatform ("ios17.0")] | ||
[UnsupportedOSPlatform ("macos")] | ||
[UnsupportedOSPlatform ("maccatalyst")] | ||
[UnsupportedOSPlatform ("tvos")] | ||
#else | ||
[NoWatch, NoTV, NoMac, iOS (17, 0), NoMacCatalyst] | ||
#endif | ||
[DllImport (Constants.PassKitLibrary)] | ||
unsafe static extern void PKPayLaterValidateAmount (decimal amount, IntPtr /* NSString */ currencyCode, BlockLiteral* callback); | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#if IOS | ||
|
||
using System; | ||
using Foundation; | ||
using UIKit; | ||
using PassKit; | ||
using NUnit.Framework; | ||
|
||
namespace MonoTouchFixtures.PassKit { | ||
|
||
[TestFixture] | ||
[Preserve (AllMembers = true)] | ||
public class PKPayLaterViewTest { | ||
|
||
[Test] | ||
public void ValidateAmountTest () | ||
{ | ||
TestRuntime.AssertXcodeVersion (15, 0); | ||
|
||
var payLaterView = new PKPayLaterView (100, "USD"); | ||
payLaterView.ValidateAmount(50, "USD", (eligible) => { | ||
Assert.True (eligible); | ||
}); | ||
|
||
payLaterView.ValidateAmount(1, "USD", (eligible) => { | ||
Assert.False (eligible); | ||
}); | ||
|
||
payLaterView.ValidateAmount(1000000, "USD", (eligible) => { | ||
Assert.False (eligible); | ||
}); | ||
|
||
payLaterView.ValidateAmount(50, "USD", (eligible) => { | ||
Assert.True (eligible); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters