Skip to content

chadsmith/react-native-play-licensing

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Native Play Licensing

Adds Client-Side License Verification to React Native applications. Works on both Android and iOS, but only verifies licenses on Android.

Installing

npm install react-native-play-licensing

Linking Native Dependencies

Automatic Linking

react-native link react-native-play-licensing

Manual Linking

  1. In android/settings.gradle

    ...
    include ':react-native-play-licensing'
    project(':react-native-play-licensing').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-play-licensing/android')
    
  2. In android/app/build.gradle

    ...
    dependencies {
        ...
        implementation project(':react-native-play-licensing')
    }
    
  3. Register module in MainApplication.java

    import com.github.chadsmith.playlicensing.PlayLicensingPackage;  // <--- import
    
    public class MainApplication extends Application implements ReactApplication {
      ......
    
      @Override
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              ......
              new PlayLicensingPackage(),  // <--- add package
          );
      }
    
      ......
    
    }

Usage

To use the react-native-play-licensing package in your codebase, use the PlayLicensing module:

import PlayLicensing from 'react-native-play-licensing';
export default function(App) {
  // ...
  const [licensed, setLicensed] = useState(null);
  useEffect(() => {
    PlayLicensing.verify('MIIBIjANBgkqhkiG...')
      .then(setLicensed);
  }, []);

  // do something if app is not licensed

  // ...
}

API

  • verify(BASE64_PUBLIC_KEY, STRING_FOR_SALT)
PlayLicensing.verify(BASE64_PUBLIC_KEY)
  .then(licensed => {
    if(licensed === true) {
      // app was purchased from Google Play
    }
    else if (licensed === false) {
      // app was not purchased from Google Play
    }
    else {
      // verification failed, retry later
    }
  })

About

React Native library for verifying Google Play license

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 99.7%
  • JavaScript 0.3%