In supporting browsers, the process starts by requesting a payment method manifest file from each URL. A payment method manifest is typically called something like payment-manifest.json
(the exact name can be whatever you like), and should be structured like this:
{
"default_applications": ["https://bobbucks.dev/manifest.json"],
"supported_origins": ["https://alicepay.friendsofalice.example"]
}
Given a payment method identifier like https://bobbucks.dev/pay
, the browser:
- Starts loading
https://bobbucks.dev/pay
and checks its HTTP headers.
- If a
Link
header is found with rel="payment-method-manifest"
, then it downloads the payment method manifest at that location instead (see Optionally route the browser to find the payment method manifest in another location for details).
- Otherwise, parse the response body of
https://bobbucks.dev/pay
as the payment method manifest.
- Parses the downloaded content as JSON with
default_applications
and supported_origins
members.
These members have the following purposes:
default_applications
tells the browser where to find the default payment app that can use the BobBucks payment method if it doesn't already have one installed.
supported_origins
tells the browser what other payment apps are permitted to handle the BobBucks payment if needed. If they are already installed on the device, they will be presented to the user as alternative payment options alongside the default application.
From the payment method manifest, the browser gets the URL of the default payment apps' web app manifest files, which can be called whatever you like, and look something like this:
{
"name": "Pay with BobBucks",
"short_name": "BobBucks",
"description": "This is an example of the Payment Handler API.",
"icons": [
{
"src": "images/manifest/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "images/manifest/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"serviceworker": {
"src": "service-worker.js",
"scope": "/",
"use_cache": false
},
"start_url": "/",
"display": "standalone",
"theme_color": "#3f51b5",
"background_color": "#3f51b5",
"related_applications": [
{
"platform": "play",
"id": "com.example.android.samplepay",
"min_version": "1",
"fingerprints": [
{
"type": "sha256_cert",
"value": "4C:FC:14:C6:97:DE:66:4E:66:97:50:C0:24:CE:5F:27:00:92:EE:F3:7F:18:B3:DA:77:66:84:CD:9D:E9:D2:CB"
}
]
}
]
}
When the icons
information found in each manifest to present the payment apps to the user in the browser-provided Payment Request UI.
- If there are multiple payment app options, a list of options is presented to the user for them to choose from. Selecting a payment app will start the payment flow, which causes the browser to Just-In-Time (JIT) install the web app if necessary, registering the service worker specified in the
serviceworker
member so it can handle the payment.
- If there is only one payment app option, the
PaymentRequest.show()
method will start the payment flow with this payment app, JIT-installing it if necessary, as described above. This is an optimization to avoid presenting the user with a list that contains only one payment app choice.
Note:
If related_applications
to handle the payment (if it is available) instead of the web payment app.
See Serve a web app manifest for more details.