Created
July 12, 2024 12:15
-
-
Save vanGalilea/eddd936080ef5fd022b1390de5c991dc to your computer and use it in GitHub Desktop.
Expo plugin to enable Google Pay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add this plugin to you app.congi.js via plugins - https://docs.expo.dev/versions/latest/config/app/#plugins | |
// | |
// ... | |
// plugins: [ | |
// ... | |
// "enableGooglePay.js" | |
// ] | |
const { AndroidConfig, withAndroidManifest } = require("@expo/config-plugins"); | |
const { addMetaDataItemToMainApplication, getMainApplicationOrThrow } = | |
AndroidConfig.Manifest; | |
/** | |
* Adds the following to AndroidManifest.xml: | |
* | |
* <application> | |
* ... | |
* <meta-data | |
* android:name="com.google.android.gms.wallet.api.enabled" | |
* android:value="true|false" /> | |
* </application> | |
*/ | |
function setGooglePayMetaData(modResults) { | |
const GOOGLE_PAY_META_NAME = "com.google.android.gms.wallet.api.enabled"; | |
const mainApplication = getMainApplicationOrThrow(modResults); | |
addMetaDataItemToMainApplication( | |
mainApplication, | |
GOOGLE_PAY_META_NAME, | |
"true", | |
); | |
return modResults; | |
} | |
function withGooglePayAndroid(expoConfig) { | |
return withAndroidManifest(expoConfig, (config) => { | |
config.modResults = setGooglePayMetaData(config.modResults); | |
return config; | |
}); | |
} | |
module.exports = function withGooglePay(config, props) { | |
config = withGooglePayAndroid(config, props); | |
return config; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The props passed on line 45 don’t do anything and can be omitted.