Skip to content
Open
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
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,36 @@ yarn && yarn example

## Configuration

### React Native CLI

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/'
],
},
]);
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;
34 changes: 34 additions & 0 deletions plugin/src/withAndroid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { type ConfigPlugin, withGradleProperties } from '@expo/config-plugins';

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

const GOOGLE_PAY_ENVIRONMENT_KEY = 'GOOGLE_PAY_ENVIRONMENT';

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

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

return modConfig;
});

export const withAndroidConfiguration: ConfigPlugin<MakePaymentPluginProps> = (
config,
props = {}
) => {
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"]
}
Loading
Loading