<commit_before>#Atomic Plugins for In-App Purchases

This repo contains In-App purchase APIs designed using the [Atomic Plugins](#about-atomic-plugins) paradigm. You can integrate IAPs in your app and take advantage of all the features provided: elegant API, local and server-side receipt validation, secure consumable and non-consumable purchase tracking, local product cache and more. The API is already available in many languagues and we plan to add more in the future:

  * [Objective-C API for pure iOS/Mac apps](#ios-api)
  * [Java API for pure Android apps](#android-api)
  * [JavaScript API for Cordova or Cocoon based Apps](#javascript-api)
  * [C++ API for C++ based apps and games](#c-api)

Currently there are 3 in-app purchase providers implemented but new ones can be easily added:

* Apple AppStore (iOS/Mac)
* GooglePlay
* Amazon AppStore. 

You can contribute and help to create more awesome plugins.

##About Atomic Plugins

Atomic Plugins provide an elegant and minimalist API and are designed with portability in mind from the beginning. Framework dependencies are avoided by design so the plugins can run on any platform and can be integrated with any app framework or game engine. 

#Provided APIs

* [iOS API](#ios-api)
  * [API Reference](#api-reference)
  * [Introduction](#introduction)
  * [Setup your project](#setup-your-project)
  * [Example](#example)
* [Android API](#android-api)
  * [API Reference](#api-reference-1)
  * [Introduction](#introduction-1)
  * [Setup your project](#setup-your-project-1)
  * [Example](#example-1)
* [JavaScript API](#javascript-api)
  * [API Reference](#api-reference-2)
  * [Introduction](#introduction-2)
  * [Setup your project](#setup-your-project-2)
  * [Example](#example-2)
* [C++ API](#c-api)
  * [API Reference](#api-reference-3)
  * [Introduction](#introduction-3)
  * [Setup your project](#setup-your-project-3)
  * [Example](#example-3)
  
##iOS API:

###API Reference

See [API Documentation](http://ludei.github.io/atomic-plugins-inapps/dist/doc/ios/html/annotated.html)

See [`LDInAppService.h`](src/atomic/ios/appstore/LDInAppService.h) header file for a complete overview of the capabilities of the class.

See [`InAppTest`](test/ios)  for a complete project that tests all the features provided in the API.

###Introduction 

LDInAppService class provides an easy to use and secure in-app purchase API. Built-in support for local and server-side receipt validation, consumable and non-consumable purchase tracking and local product cache. Completed purchases are secured using Apple's keychain services and are remembered even if the user deletes the app.

###Setup your project

You can use CocoaPods:

    pod 'LDInAppService'

###Example

```objc
LDInAppService * service = [[LDInAppService alloc] init];

[service addPurchaseObserver: self]; //optional delegate to observe purchases
[service start]; //start processing transactions

[service fetchProducts:@[@"productIds"] completion:^(NSArray *products, NSError *error) {
     //fetch products from remote server
}];

service.products; //local cached products

[service purchase:productId quantity:2 completion:^(NSError *error) {
    //purchase consumable or non consumable products
}];
[service consume:productId quantity:1]; //consume product

[service isPurchased:productId]; //check if a productId is purchased
[service stockOfProduct:productId]; //check available stock of consumable products

[service restorePurchases:^(NSError *error) {
     //restore non-consumable purchases
}];
[service setValidationHandler:^(NSData *validationReceipt, NSString *productId, LDValidationCompletion completion) {
    //custom server validation
    completion(nil); //Call completion with nil error if validation succeeds
}];
[service setLudeiServerValidationHandler]; //validate using Ludei's Cloud server
```

##Android API:

###API Reference

See [API Documentation](http://ludei.github.io/atomic-plugins-inapps/dist/doc/android/html/annotated.html)

See [`InAppTest`](test/android) for a complete project that tests all the features provided in the API. In order to test Android In-Apps select the googlePlayRelelease or amazonRelease built variant in Android Studio. You must set your custom productIds in [`MainActivity.java`](test/android/InAppTest/testapp/src/main/java/com/ludei/inapptest/MainActivity.java) and set your bundleId and versionCode in the [`build.gradle`](test/android/InAppTest/testapp/build.gradle)

You also have to configure your release signingConfig. Add these properties to your global gradle.properties file

    STORE_FILE=/Users/user/.android/company.keystore
    STORE_PASSWORD=<PASSWORD>
    KEY_ALIAS=xxxxxxx
    KEY_PASSWORD=<PASSWORD>

###Introduction 

InAppService interface provides an easy to use and secure in-app purchase API. Built-in support for local and server-side receipt validation, consumable and non-consumable purchase tracking and local product cache. Single API for multiple IAP providers.

## Setup your project

Releases are deployed to Maven Central. You only have to add the desired dependencies in your build.gradle:

    dependencies {
        compile 'com.ludei.inapps.googleplay:1.0.0' //Google Play IAP Provider
        compile 'com.ludei.inapps.amazon:1.0.0' //Amazon AppStore IAP Provider
    }

###Example

```java
//create the service instance using the desired provider
InAppService service =  new GooglePlayInAppService(context);
//service =  new AmazonInAppService(context);

service.fetchProducts(productIds, new InAppService.FetchCallback() {
    public void onComplete(List<InAppProduct> products, InAppService.Error error) {
        //fetch products from store
    }
});

service.getProducts(); // Local cached products

service.purchase(productId, new InAppService.PurchaseCallback() {
    public void onComplete(InAppPurchase purchase, InAppService.Error error) {
        //purchase product
    }
});

service.consume(productId, 1, new InAppService.ConsumeCallback() {
    public void onComplete(int consumed, InAppService.Error error) {
        //consume product
    }
});

service.isPurchased(productId); //check if a product is purchased
service.stockOfProduct(productId); //check available stock of consumable products 

service.restorePurchases(new InAppService.RestoreCallback() {
    public void onComplete(InAppService.Error error) {
        //Restore completed purchases
    }
});

service.setValidationHandler(new InAppService.ValidationHandler() {
    public void onValidate(String receipt, String productId, InAppService.ValidationCompletion completion) {
        //custom server validation
    }
});

service.setLudeiServerValidationHandler(); //Validate using Ludei's Cloud server
```

Remember to notify onActivityResult and onDestroy events

```java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    boolean handled = service.onActivityResult(requestCode, resultCode, data);
    if (!handled) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

@Override
public void onDestroy()
{
    service.onDestroy();
    super.onDestroy();
}

```

##JavaScript API:

###API Reference

See [API Documentation](http://ludei.github.io/cocoon-common/dist/doc/js/Cocoon.InApp.html)

For a complete project that tests all the features provided in the API run the following command:

    gulp create-cordova

A cordova project is created in test/cordova/InAppTest

###Introduction 

Cocoon.InApp class provides a multiplatform, easy to use and secure in-app purchase API. Built-in support for local and server-side receipt validation, consumable and non-consumable purchase tracking and local product cache. Single JavaScript API for multiple IAP providers.

###Setup your project

Releases are deployed to Cordova Plugin Registry. You only have to install the desired plugins using Cordova CLI, CocoonJS CLI or Ludei's Cocoon Cloud Server.

    cordova plugin add cocoon-plugin-inapps-ios-appstore;
    cordova plugin add cocoon-plugin-inapps-android-googleplay;
    cordova plugin add cocoon-plugin-inapps-android-amazon;

The following JavaScript file is included automatically:

[`cocoon_inapps.js`](src/cordova/js/cocoon_inapps.js)

###Example

```javascript
// Basic usage, register callbacks first
var service = Cocoon.InApp;
service.on("purchase", {
    start: function(productId) {<commit_msg>Updated README.md links<commit_after>#Atomic Plugins for In-App Purchases

This repo contains In-App purchase APIs designed using the [Atomic Plugins](#about-atomic-plugins) paradigm. You can integrate IAPs in your app and take advantage of all the features provided: elegant API, local and server-side receipt validation, secure consumable and non-consumable purchase tracking, local product cache and more. The API is already available in many languagues and we plan to add more in the future:

  * [Objective-C API for pure iOS/Mac apps](#ios-api)
  * [Java API for pure Android apps](#android-api)
  * [JavaScript API for Cordova or Cocoon based Apps](#javascript-api)
  * [C++ API for C++ based apps and games](#c-api)

Currently there are 3 in-app purchase providers implemented but new ones can be easily added:

* Apple AppStore (iOS/Mac)
* GooglePlay
* Amazon AppStore. 

You can contribute and help to create more awesome plugins.

##About Atomic Plugins

Atomic Plugins provide an elegant and minimalist API and are designed with portability in mind from the beginning. Framework dependencies are avoided by design so the plugins can run on any platform and can be integrated with any app framework or game engine. 

#Provided APIs

* [iOS API](#ios-api)
  * [API Reference](#api-reference)
  * [Introduction](#introduction)
  * [Setup your project](#setup-your-project)
  * [Example](#example)
* [Android API](#android-api)
  * [API Reference](#api-reference-1)
  * [Introduction](#introduction-1)
  * [Setup your project](#setup-your-project-1)
  * [Example](#example-1)
* [JavaScript API](#javascript-api)
  * [API Reference](#api-reference-2)
  * [Introduction](#introduction-2)
  * [Setup your project](#setup-your-project-2)
  * [Example](#example-2)
* [C++ API](#c-api)
  * [API Reference](#api-reference-3)
  * [Introduction](#introduction-3)
  * [Setup your project](#setup-your-project-3)
  * [Example](#example-3)
  
##iOS API:

###API Reference

See [API Documentation](http://ludei.github.io/atomic-plugins-inapps/dist/doc/ios/html/annotated.html)

See [`LDInAppService.h`](src/atomic/ios/appstore/LDInAppService.h) header file for a complete overview of the capabilities of the class.

See [`InAppTest`](test/ios)  for a complete project that tests all the features provided in the API.

###Introduction 

LDInAppService class provides an easy to use and secure in-app purchase API. Built-in support for local and server-side receipt validation, consumable and non-consumable purchase tracking and local product cache. Completed purchases are secured using Apple's keychain services and are remembered even if the user deletes the app.

###Setup your project

You can use CocoaPods:

    pod 'LDInAppService'

###Example

```objc
LDInAppService * service = [[LDInAppService alloc] init];

[service addPurchaseObserver: self]; //optional delegate to observe purchases
[service start]; //start processing transactions

[service fetchProducts:@[@"productIds"] completion:^(NSArray *products, NSError *error) {
     //fetch products from remote server
}];

service.products; //local cached products

[service purchase:productId quantity:2 completion:^(NSError *error) {
    //purchase consumable or non consumable products
}];
[service consume:productId quantity:1]; //consume product

[service isPurchased:productId]; //check if a productId is purchased
[service stockOfProduct:productId]; //check available stock of consumable products

[service restorePurchases:^(NSError *error) {
     //restore non-consumable purchases
}];
[service setValidationHandler:^(NSData *validationReceipt, NSString *productId, LDValidationCompletion completion) {
    //custom server validation
    completion(nil); //Call completion with nil error if validation succeeds
}];
[service setLudeiServerValidationHandler]; //validate using Ludei's Cloud server
```

##Android API:

###API Reference

See [API Documentation](http://ludei.github.io/atomic-plugins-inapps/dist/doc/android/html/annotated.html)

See [`InAppTest`](test/android) for a complete project that tests all the features provided in the API. In order to test Android In-Apps select the googlePlayRelelease or amazonRelease built variant in Android Studio. You must set your custom productIds in [`MainActivity.java`](test/android/InAppTest/testapp/src/main/java/com/ludei/inapptest/MainActivity.java) and set your bundleId and versionCode in the [`build.gradle`](test/android/InAppTest/testapp/build.gradle)

You also have to configure your release signingConfig. Add these properties to your global gradle.properties file

    STORE_FILE=/Users/user/.android/company.keystore
    STORE_PASSWORD=<PASSWORD>
    KEY_ALIAS=xxxxxxx
    KEY_PASSWORD=<PASSWORD>

###Introduction 

InAppService interface provides an easy to use and secure in-app purchase API. Built-in support for local and server-side receipt validation, consumable and non-consumable purchase tracking and local product cache. Single API for multiple IAP providers.

## Setup your project

Releases are deployed to Maven Central. You only have to add the desired dependencies in your build.gradle:

    dependencies {
        compile 'com.ludei.inapps.googleplay:1.0.0' //Google Play IAP Provider
        compile 'com.ludei.inapps.amazon:1.0.0' //Amazon AppStore IAP Provider
    }

###Example

```java
//create the service instance using the desired provider
InAppService service =  new GooglePlayInAppService(context);
//service =  new AmazonInAppService(context);

service.fetchProducts(productIds, new InAppService.FetchCallback() {
    public void onComplete(List<InAppProduct> products, InAppService.Error error) {
        //fetch products from store
    }
});

service.getProducts(); // Local cached products

service.purchase(productId, new InAppService.PurchaseCallback() {
    public void onComplete(InAppPurchase purchase, InAppService.Error error) {
        //purchase product
    }
});

service.consume(productId, 1, new InAppService.ConsumeCallback() {
    public void onComplete(int consumed, InAppService.Error error) {
        //consume product
    }
});

service.isPurchased(productId); //check if a product is purchased
service.stockOfProduct(productId); //check available stock of consumable products 

service.restorePurchases(new InAppService.RestoreCallback() {
    public void onComplete(InAppService.Error error) {
        //Restore completed purchases
    }
});

service.setValidationHandler(new InAppService.ValidationHandler() {
    public void onValidate(String receipt, String productId, InAppService.ValidationCompletion completion) {
        //custom server validation
    }
});

service.setLudeiServerValidationHandler(); //Validate using Ludei's Cloud server
```

Remember to notify onActivityResult and onDestroy events

```java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    boolean handled = service.onActivityResult(requestCode, resultCode, data);
    if (!handled) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

@Override
public void onDestroy()
{
    service.onDestroy();
    super.onDestroy();
}

```

##JavaScript API:

###API Reference

See [API Documentation](http://ludei.github.io/atomic-plugins-docs/dist/doc/js/Cocoon.InApp.html)

For a complete project that tests all the features provided in the API run the following command:

    gulp create-cordova

A cordova project is created in test/cordova/InAppTest

###Introduction 

Cocoon.InApp class provides a multiplatform, easy to use and secure in-app purchase API. Built-in support for local and server-side receipt validation, consumable and non-consumable purchase tracking and local product cache. Single JavaScript API for multiple IAP providers.

###Setup your project

Releases are deployed to Cordova Plugin Registry. You only have to install the desired plugins using Cordova CLI, CocoonJS CLI or Ludei's Cocoon Cloud Server.

    cordova plugin add cocoon-plugin-inapps-ios-appstore;
    cordova plugin add cocoon-plugin-inapps-android-googleplay;
    cordova plugin add cocoon-plugin-inapps-android-amazon;

The following JavaScript file is included automatically:

[`cocoon_inapps.js`](src/cordova/js/cocoon_inapps.js)

###Example

```javascript
// Basic usage, register callbacks first
var service = Cocoon.InApp;
service.on("purchase", {
    start: function(productId) {
{'fraction_non_alphanumeric': 0.09593127311776638, 'fraction_numerical': 0.002624985085312015, 'mean_word_length': 4.734861443722203, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3882511', 'n_tokens_mistral': 4794, 'n_tokens_neox': 4574, 'n_words': 1622}