Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,45 @@ yarn && yarn example

## Configuration

### React Native CLI

Add the following inside the `<application>` element in your app's
`android/app/src/main/AndroidManifest.xml`:

```xml
<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
```

For production, you will need to define the
`GOOGLE_PAY_ENVIRONMENT` property in your project's
`gradle.properties` file (typically `android/gradle.properties`):

```
```properties
GOOGLE_PAY_ENVIRONMENT=PRODUCTION
```

### Expo

Add the config plugin to your Expo app config. The `environment`
option accepts `TEST` (default) or `PRODUCTION`:

```json
{
"expo": {
"plugins": [
[
"@google/react-native-make-payment",
{
"environment": "PRODUCTION"
}
]
]
}
}
```

## Usage

Following is a minimal example. A complete example can be
Expand Down
1 change: 1 addition & 0 deletions app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./plugin/build');
3 changes: 2 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export default defineConfig([
{
ignores: [
'node_modules/',
'lib/'
'lib/',
'plugin/build/'
],
},
]);
17 changes: 17 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type ConfigPlugin } from '@expo/config-plugins';

import { withAndroidConfiguration } from './withAndroid';

export interface MakePaymentPluginProps {
environment?: string;
}

const withMakePayment: ConfigPlugin<MakePaymentPluginProps> = (
config,
props = {}
) => {
config = withAndroidConfiguration(config, props);
return config;
};

export default withMakePayment;
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
"src",
"README.md",
"LICENSE",
"package.json"
"package.json",
"app.plugin.js",
"plugin/build"
],
"scripts": {
"example": "yarn install & cd example && yarn install && yarn android",
"test": "jest",
"typecheck": "tsc",
"lint": "eslint \"**/*.{js,ts,tsx}\"",
"clean": "rm -rf yarn.lock, example/yarn.lock android/build example/android/build example/android/app/build lib node_modules example/node_modules",
"build": "bob build",
"prepack": "bob build",
"build": "bob build && yarn build:plugin",
"build:plugin": "tsc --project plugin/tsconfig.json",
"prepack": "yarn build",
"codegen": "cd example/android && ./gradlew generateCodegenArtifactsFromSchema && cd ../."
},
"keywords": [
Expand Down Expand Up @@ -59,6 +62,7 @@
"@eslint/compat": "^1.2.7",
"@eslint/eslintrc": "^3.3.0",
"@eslint/js": "^9.22.0",
"@expo/config-plugins": "~10.1.2",
"@react-native-community/cli": "17.0.1",
"@react-native/babel-preset": "0.79.2",
"@react-native/eslint-config": "^0.78.0",
Expand Down
17 changes: 17 additions & 0 deletions plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type ConfigPlugin } from '@expo/config-plugins';

import { withAndroidConfiguration } from './withAndroid';

export interface MakePaymentPluginProps {
environment?: string;
}

const withMakePayment: ConfigPlugin<MakePaymentPluginProps> = (
config,
props = {}
) => {
config = withAndroidConfiguration(config, props);
return config;
};

export default withMakePayment;
57 changes: 57 additions & 0 deletions plugin/src/withAndroid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
AndroidConfig,
type ConfigPlugin,
withAndroidManifest,
withGradleProperties,
} from '@expo/config-plugins';

import { type MakePaymentPluginProps } from './index';

const GOOGLE_PAY_ENABLED_KEY = 'com.google.android.gms.wallet.api.enabled';
const GOOGLE_PAY_ENVIRONMENT_KEY = 'GOOGLE_PAY_ENVIRONMENT';

const withGooglePayManifest: ConfigPlugin = (config) =>
withAndroidManifest(config, (config) => {
const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(
config.modResults
);

AndroidConfig.Manifest.addMetaDataItemToMainApplication(
mainApplication,
GOOGLE_PAY_ENABLED_KEY,
'true'
);

return config;
});

const withGooglePayEnvironment: ConfigPlugin<MakePaymentPluginProps> = (
config,
{ environment } = {}
) =>
withGradleProperties(config, (config) => {
config.modResults = config.modResults.filter(
(item) =>
!(item.type === 'property' && item.key === GOOGLE_PAY_ENVIRONMENT_KEY)
);

if (environment !== undefined) {
config.modResults.push({
type: 'property',
key: GOOGLE_PAY_ENVIRONMENT_KEY,
value: environment,
});
}

return config;
});

export const withAndroidConfiguration: ConfigPlugin<MakePaymentPluginProps> = (
config,
props = {}
) => {
config = withGooglePayManifest(config);
config = withGooglePayEnvironment(config, props);

return config;
};
12 changes: 12 additions & 0 deletions plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"declaration": true,
"module": "Node16",
"outDir": "build",
"rootDir": "src",
"skipLibCheck": true,
"strict": true,
"target": "ES2022"
},
"include": ["./src"]
}
57 changes: 57 additions & 0 deletions withAndroid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
AndroidConfig,
type ConfigPlugin,
withAndroidManifest,
withGradleProperties,
} from '@expo/config-plugins';

import { type MakePaymentPluginProps } from './index';

const GOOGLE_PAY_ENABLED_KEY = 'com.google.android.gms.wallet.api.enabled';
const GOOGLE_PAY_ENVIRONMENT_KEY = 'GOOGLE_PAY_ENVIRONMENT';

const withGooglePayManifest: ConfigPlugin = (config) =>
withAndroidManifest(config, (config) => {
const mainApplication = AndroidConfig.Manifest.getMainApplicationOrThrow(
config.modResults
);

AndroidConfig.Manifest.addMetaDataItemToMainApplication(
mainApplication,
GOOGLE_PAY_ENABLED_KEY,
'true'
);

return config;
});

const withGooglePayEnvironment: ConfigPlugin<MakePaymentPluginProps> = (
config,
{ environment } = {}
) =>
withGradleProperties(config, (config) => {
config.modResults = config.modResults.filter(
(item) =>
!(item.type === 'property' && item.key === GOOGLE_PAY_ENVIRONMENT_KEY)
);

if (environment !== undefined) {
config.modResults.push({
type: 'property',
key: GOOGLE_PAY_ENVIRONMENT_KEY,
value: environment,
});
}

return config;
});

export const withAndroidConfiguration: ConfigPlugin<MakePaymentPluginProps> = (
config,
props = {}
) => {
config = withGooglePayManifest(config);
config = withGooglePayEnvironment(config, props);

return config;
};
Loading
Loading