Class PlatformPay
Apple Pay and Google Pay: shows the platform payment sheet and hands back the encrypted payment token for the app's payment service provider (PSP).
This class never charges anyone. It returns the token the wallet produced,
and the app sends that token to its server, which passes it to Stripe,
Adyen, Braintree or another PSP. In-app purchases of digital goods go
through Purchase instead; the stores do not allow wallet payments for
those.
Referencing this class makes the build add PassKit on iOS and
play-services-wallet on Android. On iOS the merchant ids go in the
ios.applePayMerchantIds build hint, which writes the
com.apple.developer.in-app-payments entitlement; the Android build
installs the Google Pay provider.
PlatformPay.Request req = new PlatformPay.Request("Coffee", "4.50", "USD", "US");
req.setMerchantId("merchant.com.example.shop");
req.setGateway("stripe", "pk_test_123");
PlatformPay.requestPayment(req, new SuccessCallback<PlatformPay.Result>() {
public void onSucess(PlatformPay.Result r) {
if (r.getStatus() == PlatformPay.Result.SUCCESS) {
Log.p("Send to the PSP: " + r.getToken());
// Once the server answers, close the sheet with the outcome:
r.complete(true);
}
}
});
On iOS the Apple Pay sheet stays up, showing progress, until the app calls
Result#complete(boolean) with the outcome of the charge. If the app does
not call it within 30 seconds the sheet reports a failure. Google Pay closes
its sheet as soon as it hands over the token, so there complete does
nothing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe wallet integration of a port that needs a dependency the port jar cannot carry.static final classA single payment: one total, in one currency.static final classThe outcome of#requestPayment(Request, SuccessCallback). -
Method Summary
Modifier and TypeMethodDescriptionstatic voidisReadyToPay(PlatformPay.Request request, SuccessCallback<Boolean> callback) Answers whether the user can pay for this request, for example to decide whether to show an Apple Pay or Google Pay button.static booleanAnswers whether this platform has a wallet integration at all.static voidrequestPayment(PlatformPay.Request request, SuccessCallback<PlatformPay.Result> callback) Shows the platform payment sheet.static voidsetImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use onlystatic voidsetProvider(PlatformPay.Provider provider) Installs the wallet provider, or removes it with null.
-
Method Details
-
setImplementation
public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
Parameters
impl: implementation instance
-
setProvider
Installs the wallet provider, or removes it with null. Internal: for ports and generated code, which inject the platform implementation here; applications do not call it.
Parameters
provider: the provider
-
isSupported
public static boolean isSupported()Answers whether this platform has a wallet integration at all.
Returns
true on iOS with PassKit and on Android with the Google Pay provider
-
isReadyToPay
Answers whether the user can pay for this request, for example to decide whether to show an Apple Pay or Google Pay button.
Parameters
-
request: the payment the button would start -
callback: receives the answer on the EDT
-
-
requestPayment
public static void requestPayment(PlatformPay.Request request, SuccessCallback<PlatformPay.Result> callback) Shows the platform payment sheet.
Parameters
-
request: what to charge -
callback: receives the result on the EDT
-
-