Skip to content

Commit

Permalink
Google Play Billing implementation (#32)
Browse files Browse the repository at this point in the history
Google Play Billing implementation
  • Loading branch information
tomasz-keepsafe authored Aug 29, 2019
1 parent 48bdcb1 commit 0a24384
Show file tree
Hide file tree
Showing 69 changed files with 3,946 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android:
components:
- platform-tools
- tools
- build-tools-27.0.3
- android-27
- build-tools-28.0.3
- android-28

- extra-google-m2repository
- extra-android-m2repository
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## 0.3.5
- Fixed inventory query uncaught exception

## 0.3.0
- Google Play Billing lib implementation - GooglePlayBillingVendor
- Google Play Billing implementation unit tests
- Fake purchase flow for GooglePlayBillingVendor
- New sample app using GooglePlayBillingVendor
- Added changelog
76 changes: 65 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">
<img src=".github/ic_launcher.png" alt="Cashier"><br/>
Cashier
Cashier
</h1>

[![Build Status](https://travis-ci.org/KeepSafe/Cashier.svg?branch=master)](https://travis-ci.org/KeepSafe/Cashier)
Expand All @@ -19,28 +19,34 @@ Cashier also aims to bridge the gap between development testing and production t

### Features

- Google Play's In-App-Billing (IAB)
- Google Play's In-App-Billing (IAB) - Deprecated
- Purchasing for products and subscriptions, consuming for consumable products
- Fake checkout, facilitating faster development
- Local receipt verification
- Inventory querying

- Google Play Billing
- Purchasing for products and subscriptions, consuming for consumable products
- Fake checkout, facilitating faster development
- Local receipt verification
- Inventory querying
- For now, developer payload is not supported (will be added in GPB v2)

## Installation

Cashier is distributed using [jcenter](https://bintray.com/keepsafesoftware/Android/Cashier/view).

```groovy
repositories {
repositories {
jcenter()
}
dependencies {
compile 'com.getkeepsafe.cashier:cashier:0.x.x' // Core library, required
// Google Play
compile 'com.getkeepsafe.cashier:cashier-iab:0.x.x'
debugCompile 'com.getkeepsafe.cashier:cashier-iab-debug:0.x.x' // For fake checkout and testing
releaseCompile 'com.getkeepsafe.cashier:cashier-iab-debug-no-op:0.x.x'
// Google Play Billing
compile 'com.getkeepsafe.cashier:cashier-google-play-billing:0.x.x'
debugCompile 'com.getkeepsafe.cashier:cashier-google-play-billing-debug:0.x.x' // For fake checkout and testing
}
```

Expand All @@ -50,7 +56,7 @@ General usage is as follows:

```java
// First choose a vendor
final Vendor vendor = new InAppBillingV3Vendor();
final Vendor vendor = new GooglePlayBillingVendor();

// Get a product to buy
final Product product = Product.create(
Expand Down Expand Up @@ -82,9 +88,57 @@ final Cashier cashier = Cashier.forVendor(activity, vendor);
cashier.purchase(activity, product, "my custom dev payload", listener);
```

To test app in debug mode with fake purchase flow:
```java
// Create vendor with fake API implementation
vendor = new GooglePlayBillingVendor(
new FakeGooglePlayBillingApi(MainActivity.this,
FakeGooglePlayBillingApi.TEST_PUBLIC_KEY));

// Add products definitions
final Product product = Product.create(
vendor.id(), // The vendor that produces this product
"my.sku", // The SKU of the product
"$0.99", // The display price of the product
"USD", // The currency of the display price
"My Awesome Product", // The product's title
"Provides awesomeness!", // The product's description
false, // Whether the product is a subscription or not (consumable)
990_000L); // The product price in micros

FakeGooglePlayBillingApi.addTestProduct(product)
```

```FakeGooglePlayBillingApi``` uses predefined private key to sign purchase receipt.
If you want to verify purchase signature in your code, use corresponding public key defined in
```FakeGooglePlayBillingApi.TEST_PUBLIC_KEY```.

## Migrating from In App Billing to Google Play Billing

All you need to do is change vendor implementation from depracated `InAppBillingV3Vendor` to `GooglePlayBillingVendor`.
Since both implementations are just different ways to connect to Google Play Store, all your products and purchase
flows remain the same.

1. In your dependencies replace
```compile 'com.getkeepsafe.cashier:cashier-iab:0.x.x'
debugCompile 'com.getkeepsafe.cashier:cashier-iab-debug:0.x.x' // For fake checkout and testing
releaseCompile 'com.getkeepsafe.cashier:cashier-iab-debug-no-op:0.x.x'```
with
```
compile 'com.getkeepsafe.cashier:cashier-google-play-billing:0.x.x'
debugCompile 'com.getkeepsafe.cashier:cashier-google-play-billing-debug:0.x.x' // For fake checkout and testing
```
2. Replace `InAppBillingV3Vendor` with `GooglePlayBillingVendor`. To test the app in debug mode use `FakeGooglePlayBillingApi` in place of `FakeAppBillingV3Api`.
Definition of products remains the same, but now you need to add them by calling
```FakeGooglePlayBillingApi.addTestProduct(product)```
3. That's it! Now your app will use new Google Play Billing API!!
## Sample App
For a buildable / workable sample app, please see the `cashier-sample` project under `cashier-sample/`.
For a buildable / workable sample app, please see the `cashier-sample-google-play-billing` project.
## Acknowledgements
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
}
}
Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions cashier-google-play-billing-debug/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

android {
compileSdkVersion versions.compileSdk
buildToolsVersion versions.buildTools

defaultConfig {
minSdkVersion versions.minSdk
}

buildTypes {
release {
minifyEnabled false
}
}
testOptions {
unitTests.all {
testLogging {
exceptionFormat 'full'
showStackTraces true
showCauses true
events "passed", "skipped", "failed", "standardError"
}
}
}
}

dependencies {
api project(':cashier-google-play-billing')

compileOnly deps.autoValue
compileOnly deps.supportAnnotations
annotationProcessor deps.autoValue
annotationProcessor deps.autoParcel

testImplementation deps.robolectric
testImplementation deps.junit
testImplementation deps.mockito
testImplementation deps.truth
}
13 changes: 13 additions & 0 deletions cashier-google-play-billing-debug/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.getkeepsafe.cashier.billing.debug">

<application>

<activity
android:name=".FakeGooglePlayCheckoutActivity"
android:theme="@style/Cashier.FakeCheckoutTheme"/>

</application>

</manifest>
Loading

0 comments on commit 0a24384

Please sign in to comment.