Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class PlatformPay
- Object
- 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 types
interface PlatformPay.Provider | The wallet integration of a port that needs a dependency the port jar cannot carry. |
class PlatformPay.Request | A single payment: one total, in one currency. |
class PlatformPay.Result | The outcome of #requestPayment(Request, SuccessCallback). |
Methods
public static void setImplementation(CodenameOneImplementation impl) | Invoked internally from Display, this method is for internal use only |
public static void setProvider(PlatformPay.Provider provider) | Installs the wallet provider, or removes it with null. |
public static boolean isSupported() | Answers whether this platform has a wallet integration at all. |
public static void isReadyToPay(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. |
public static void requestPayment(PlatformPay.Request request, SuccessCallback<PlatformPay.Result> callback) | Shows the platform payment sheet. |
Inherited methods
Method details
setImplementation
public static void setImplementation(CodenameOneImplementation impl)Parameters
implCodenameOneImplementation- implementation instance
setProvider
public static void setProvider(PlatformPay.Provider provider)Parameters
providerPlatformPay.Provider- the provider
isSupported
public static boolean isSupported()Returns
isReadyToPay
public static void isReadyToPay(PlatformPay.Request request, SuccessCallback<Boolean> callback)Parameters
requestPlatformPay.Request- the payment the button would start
callbackSuccessCallback<Boolean>- receives the answer on the EDT
requestPayment
public static void requestPayment(PlatformPay.Request request, SuccessCallback<PlatformPay.Result> callback)Parameters
requestPlatformPay.Request- what to charge
callbackSuccessCallback<PlatformPay.Result>- receives the result on the EDT