Reputation: 173
I am trying to implement the SetUp Apple Pay button on my iOS Xamarin application. I have added button and click handler for it. Then I Use PKPassLibrary.OpenPaymentSetup() to open Wallet. Then if user has successfully added Card into Wallet I need to handle this event via changing "SetUp ApplePay button" to "Pay with Apple Pay". But I can't find working any event handler or something like that.
What I have tried:
private PKPassLibrary _library;
private NSObject _walletNotificationSubscription;
private void OnSetuApplePayClicked(object button, EventArgs args)
{
_library = new PKPassLibrary();
_library.OpenPaymentSetup();
_walletNotificationSubscription = PKPassLibrary.Notifications.ObserveDidChange(_library, HandleEventHandler);
}
void HandleEventHandler(object sender, NSNotificationEventArgs e)
{
_walletNotificationSubscription.Dispose();
ViewModel.UpdateApplePay();
SetButtonVisibility();
}
but it does not work.
P.S.: I guess I maybe observe incorrect events.
Upvotes: 0
Views: 1354
Reputation: 173
It seems that there is no callbacks or events (at least at Xamarin). So, I had to switch a boolean property of controller when user is sent to the Wallet, and then, when user goes back to app I track "WillEnterForeground" App event where I check whether boolean property is true (if true then user returns from Wallet).
Please note that "ViewWillAppear" does not work in this case, it is not an analogue to the Android's "OnResume".
Also please note that card is activated after 15-20 seconds after adding it to wallet, so I am using "listening cycle" to track card activation.
When card is finally activated I am switching the button from Setup Apple Pay to Pay with Apple Pay.
Upvotes: 1
Reputation: 18861
Try to use the following code :
if(PKPaymentAuthorizationViewController.CanMakePayments)
{
//the device supports Apple Pay
//check whether the user can make a payment with a bank card ,such as Amex ,MasterCard,Visa,ChinaUnion and so on
NSString[] paymentString = { PKPaymentNetwork.Amex, PKPaymentNetwork.ChinaUnionPay, PKPaymentNetwork.MasterCard, PKPaymentNetwork.Visa };
if(PKPaymentAuthorizationViewController.CanMakePaymentsUsingNetworks(paymentString))
{
//user has added bank card ,do something you want
}
else
{
//user has not added bank card
}
}
else
{
//the device doesn't support Apple Pay
}
There are also some other way of payment ,you can check them in
public static class PKPaymentNetwork
Upvotes: 1