capacitor-community / stripe

Stripe Mobile SDK wrapper for Capacitor
MIT License
185 stars 74 forks source link

Should we return boolean in the `isApplePayAvailable` and `isGooglePayAvailable` method? #124

Closed hideokamoto closed 2 years ago

hideokamoto commented 2 years ago

I think these methods should return boolean. And we can use the returned attributes to change the UI behavior.

if (!Stripe.isGooglePayAvailable()) {
  return null
}
return (
  <button>Pay with Google</button>
)

Can we replace these behavior?

rdlabo commented 2 years ago

Thanks. Capacitor Plugin's method must be Promise base. so I think is**Available should be resolve/reject .

junkycoder commented 2 years ago

I had the same thoughts @hideokamoto, but I understand @rdlabo. However here is a some sugar code I use to getting a boolean on a call:

function boolifyPromise(promise) {
  return promise.then(() => true).catch(() => false);
}

//
const isApplePayAvailable = await boolifyPromise(Stripe.isApplePayAvailable());
if (!isApplePayAvailable) {
  return null;
}