Skip to content

Commit

Permalink
Merge pull request #78 from simoneb/master
Browse files Browse the repository at this point in the history
Allow to specify license key via plugin parameter
  • Loading branch information
poiuytrez committed Oct 20, 2014
2 parents ac5b882 + 17006e2 commit 84a421f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
9 changes: 8 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<!-- android -->
<platform name="android">
<preference name="BILLING_KEY" />

<js-module src="v3/www/inappbilling.js" name="InAppBillingPlugin">
<clobbers target="inappbilling" />
</js-module>
Expand All @@ -33,7 +35,12 @@
<param name="android-package" value="com.smartmobilesoftware.inappbilling.InAppBillingPlugin"/>
</feature>
</config-file>


<source-file src="v3/res/values/billing_key_param.xml" target-dir="res/values/" />
<config-file target="res/values/billing_key_param.xml" parent="/*">
<string name="billing_key_param">$BILLING_KEY</string>
</config-file>

<!-- In-app Billing Library -->
<source-file src="v3/src/android/com/android/vending/billing/IInAppBillingService.aidl" target-dir="src/com/android/vending/billing" />

Expand Down
15 changes: 7 additions & 8 deletions v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ We recommend this way to install the plugin into your project.
1. Clone this project into your repository
2. Run at the root of your project:
```
cordova plugin add /path/to/your/cloned/plugin/AndroidInAppBilling/v3
cordova plugin add /path/to/your/cloned/plugin/AndroidInAppBilling/v3 --variable BILLING_KEY="MIIBIjANBgk...AQAB"
```
or
```
phonegap local plugin add /path/to/your/cloned/plugin/AndroidInAppBilling/v3
phonegap local plugin add /path/to/your/cloned/plugin/AndroidInAppBilling/v3 --variable BILLING_KEY="MIIBIjANBgk...AQAB"
```

### Manually
Expand Down Expand Up @@ -81,13 +81,12 @@ It contains:
* Enter the app description, logo, etc. then click on save
* Add in-app purchases items from the Developer Console (activate them but do not publish the app)
* Click on Services and APIs to get your public license key
* Create `res/values/billing_key.xml`, and add your public key as follows:
* For PhoneGap build, configure the plugin with a parameter in your `config.xml` file

```
<?xml version='1.0' encoding='utf-8'?>
<resources>
<string name="billing_key">MIIBIjANBgk...AQAB</string>
</resources>
```xml
<gap:plugin name="com.smartmobilesoftware.inappbilling">
<param name="BILLING_KEY" value="MIIBIjANBgk...AQAB" />
</gap:plugin>
```

* Wait 6-8 hours
Expand Down
9 changes: 8 additions & 1 deletion v3/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

<!-- android -->
<platform name="android">
<preference name="BILLING_KEY" />

<js-module src="www/inappbilling.js" name="InAppBillingPlugin">
<clobbers target="inappbilling" />
</js-module>
Expand All @@ -33,7 +35,12 @@
<param name="android-package" value="com.smartmobilesoftware.inappbilling.InAppBillingPlugin"/>
</feature>
</config-file>


<source-file src="res/values/billing_key_param.xml" target-dir="res/values/" />
<config-file target="res/values/billing_key_param.xml" parent="/*">
<string name="billing_key_param">$BILLING_KEY</string>
</config-file>

<!-- In-app Billing Library -->
<source-file src="src/android/com/android/vending/billing/IInAppBillingService.aidl" target-dir="src/com/android/vending/billing" />

Expand Down
3 changes: 3 additions & 0 deletions v3/res/values/billing_key_param.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version='1.0' encoding='utf-8'?>
<resources>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,25 @@ public boolean execute(String action, JSONArray data, final CallbackContext call
return isValidAction;
}

private String getPublicKey() {
int billingKeyFromParam = cordova.getActivity().getResources().getIdentifier("billing_key_param", "string", cordova.getActivity().getPackageName());

if(billingKeyFromParam > 0) {
return cordova.getActivity().getString(billingKeyFromParam);
}

int billingKey = cordova.getActivity().getResources().getIdentifier("billing_key", "string", cordova.getActivity().getPackageName());
return cordova.getActivity().getString(billingKey);
}

// Initialize the plugin
private void init(final List<String> skus){
Log.d(TAG, "init start");
// Some sanity checks to see if the developer (that's you!) really followed the
// instructions to run this plugin
int billingKey = cordova.getActivity().getResources().getIdentifier("billing_key", "string", cordova.getActivity().getPackageName());
String base64EncodedPublicKey = cordova.getActivity().getString(billingKey);

if (base64EncodedPublicKey.contains("CONSTRUCT_YOUR"))
throw new RuntimeException("Please put your app's public key in InAppBillingPlugin.java. See ReadMe.");
String base64EncodedPublicKey = getPublicKey();

if (base64EncodedPublicKey.isEmpty())
throw new RuntimeException("Please install the plugin supplying your Android license key. See README.");

// Create the helper, passing it our context and the public key to verify signatures with
Log.d(TAG, "Creating IAB helper.");
Expand Down

0 comments on commit 84a421f

Please sign in to comment.