Skip to content

Commit

Permalink
Merge pull request #26 from betterme-dev/develop
Browse files Browse the repository at this point in the history
RC 3.0.0
  • Loading branch information
KChernenko authored Oct 28, 2020
2 parents 60b6a6b + 9e14017 commit 781726f
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 689 deletions.
55 changes: 5 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# RxBilling
Rx wrapper for Billing Library with connection management
RxBilling is a simple wrapper above [Google Billing library](https://developer.android.com/google/play/billing/billing_library.html) with connection management

# Download

[ ![Download](https://api.bintray.com/packages/betterme/rxbilling/com.betterme%3Arxbilling/images/download.svg) ](https://bintray.com/betterme/rxbilling/com.betterme%3Arxbilling/_latestVersion)
[![](https://jitpack.io/v/betterme-dev/RxBilling.svg)](https://jitpack.io/#betterme-dev/RxBilling)

implementation 'com.betterme:rxbilling:$latestVersion'
implementation 'com.android.billingclient:billing:$billingClientVer'

# How to use

## RxBilling and RxBillingFlow
RxBilling is a simple wrapper above [Google Billing library](https://developer.android.com/google/play/billing/billing_library.html).
Using RxBilling is preferable to RxBillingFlow in most cases (if you don't care about fine-grained events, and you don't know about this issue https://github.com/googlesamples/android-play-billing/issues/83).

RxBillingFlow is a wrapper above InAppBillingService that allows to launch billing flow and handle result of onActivityResult() callback


## Connection management

### BillingConnectionManager
Expand All @@ -28,15 +21,12 @@ Add next lines to your Activity, Fragment or any other lifecycle owner
class MainActivity : AppCompatActivity() {

private lateinit var rxBilling: RxBilling
private lateinit var rxBillingFlow: RxBillingFlow

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
rxBilling = RxBillingImpl(BillingClientFactory(applicationContext))
rxBillingFlow = RxBillingFlow(applicationContext, BillingServiceFactory(this))
lifecycle.addObserver(BillingConnectionManager(rxBilling))
lifecycle.addObserver(BillingConnectionManager(rxBillingFlow))
}
}

Expand Down Expand Up @@ -69,7 +59,7 @@ You can provide your own transformer to BillingClientFactory and BillingServiceF
super.onStop()
}

## Launch Billing flow with RxBilling
## Launch Billing flow

The result of this operation will be delivered to your updates observer

Expand All @@ -85,44 +75,10 @@ The result of this operation will be delivered to your updates observer
}))
}

## Launch Billing flow with RxBillingFlow

The result of this operation will be delivered to onActivityResult() of your Activity or Fragment,
updates observer will not be triggered

private fun startFlowWithService() {
disposable.add(
rxBillingFlow.buyItem(
BuyItemRequest(BillingClient.SkuType.SUBS, "your_id", 101),
ActivityFlowDelegate(this)
)
.subscribe({
Timber.d("flow started")
}, {
Timber.e(it)
}))
}


## Handle Billing result with RxBillingFlow

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
disposable.add(
rxBillingFlow.handleActivityResult(data)
.subscribe({
Timber.d("onActivityResult $it")
tvServiceFlow.text = it.toString()
}, {
Timber.e(it)
tvServiceFlow.text = it.toString()
}))
}

## Load owned products

private fun loadPurchases() {
disposable.add(rxBilling.getPurchases()
disposable.add(rxBilling.getPurchases(BillingClient.SkuType.INAPP)
.subscribe({
//handle purchases
}, {
Expand Down Expand Up @@ -192,7 +148,6 @@ updates observer will not be triggered
rxBilling.acknowledge(
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken("token")
.setDeveloperPayload("payload")
.build())
.subscribe({
Timber.d("acknowledge success")
Expand Down
39 changes: 1 addition & 38 deletions app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.gen.rxbilling.sample

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.android.billingclient.api.*
import com.gen.rxbilling.client.RxBilling
import com.gen.rxbilling.client.RxBillingImpl
import com.gen.rxbilling.connection.BillingClientFactory
import com.gen.rxbilling.connection.BillingServiceFactory
import com.gen.rxbilling.flow.delegate.ActivityFlowDelegate
import com.gen.rxbilling.flow.BuyItemRequest
import com.gen.rxbilling.flow.RxBillingFlow
import com.gen.rxbilling.lifecycle.BillingConnectionManager
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.activity_main.*
Expand All @@ -19,19 +14,14 @@ import timber.log.Timber
class MainActivity : AppCompatActivity() {

private lateinit var rxBilling: RxBilling
private lateinit var rxBillingFlow: RxBillingFlow
private val disposable = CompositeDisposable()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
rxBilling = RxBillingImpl(BillingClientFactory(applicationContext))
rxBillingFlow = RxBillingFlow(applicationContext, BillingServiceFactory(this))
lifecycle.addObserver(BillingConnectionManager(rxBilling))
lifecycle.addObserver(BillingConnectionManager(rxBillingFlow))
btnLaunchServiceFlow.setOnClickListener {
startFlowWithService()
}

btnLaunchClientFlow.setOnClickListener {
startFlowWithClient()
}
Expand Down Expand Up @@ -67,32 +57,6 @@ class MainActivity : AppCompatActivity() {
super.onStop()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
disposable.add(
rxBillingFlow.handleActivityResult(data)
.subscribe({
Timber.d("onActivityResult $it")
tvServiceFlow.text = it.toString()
}, {
Timber.e(it)
tvServiceFlow.text = it.toString()
}))
}

private fun startFlowWithService() {
disposable.add(
rxBillingFlow.buyItem(
BuyItemRequest(BillingClient.SkuType.SUBS, "your_id", 101),
ActivityFlowDelegate(this)
)
.subscribe({
Timber.d("flow started")
}, {
Timber.e(it)
}))
}

private fun startFlowWithClient() {
disposable.add(
rxBilling.launchFlow(this, BillingFlowParams.newBuilder()
Expand Down Expand Up @@ -147,7 +111,6 @@ class MainActivity : AppCompatActivity() {
rxBilling.acknowledge(
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken("token")
.setDeveloperPayload("payload")
.build())
.subscribe({
Timber.d("acknowledge success")
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
android:orientation="vertical"
tools:context=".MainActivity">


<Button
android:id="@+id/btnLaunchServiceFlow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/launch_flow_service" />

<TextView
android:id="@+id/tvServiceFlow"
android:layout_width="wrap_content"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<resources>
<string name="app_name">RxBilling</string>
<string name="launch_flow_service">Launch flow with service</string>
<string name="launch_flow_client">Launch flow with client</string>
<string name="load_purchases">Load purchases</string>
<string name="load_history">Load history</string>
Expand Down
8 changes: 2 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ apply from: 'dependencies.gradle'
apply plugin: "com.hellofresh.gradle.deblibs"

buildscript {
ext.kotlin_version = '1.3.72'
ext.maven_version = '2.1'
ext.bintray_version = '1.8.5'
ext.kotlin_version = '1.4.10'
ext.dokka_version = '0.9.16'
repositories {
maven { url 'https://plugins.gradle.org/m2/' }
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
classpath 'com.android.tools.build:gradle:4.0.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.dcendents:android-maven-gradle-plugin:$maven_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_version"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$dokka_version"
classpath "com.hellofresh.gradle:deblibs:2.2.0"

Expand Down
18 changes: 9 additions & 9 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@ ext {
targetSdkVer = 28

versionCode = 1
versionName = '2.2.0'
versionName = '3.0.0'

// Kotlin
kotlinVer = '1.3.72'
kotlinVer = '1.4.10'
androidKtxVer = '1.0.2'

// Support library
constraintLayout = '1.1.3'

// AndroidX
xAppCompatVer = '1.1.0'
xAppCompatVer = '1.2.0'
xLifecycleVer = '2.2.0'
xFragmentVer = '1.1.0-rc04'
xRulesVer = '1.1.0-rc04'
xRunnerVer = '1.1.0-rc04'
xTestVer = '1.2.0'
xExtVer = '1.1.1'
xTestVer = '1.3.0'
xExtVer = '1.1.2'

// Reactive Extensions
rxJava2Ver = '2.2.19'
rxJava2Ver = '2.2.20'
rxAndroid2Ver = '2.1.1'

// Billing Client
billingClientVer = '2.2.0'
billingClientVer = '3.0.1'

// Developer-related
timberVer = '4.7.1'

// Unit-tests
jUnitVer = '4.13'
mockitoVer = '3.3.3'
jUnitVer = '4.13.1'
mockitoVer = '3.5.15'
mockitoKotlinVer = '2.1.0'
jacocoVer = '0.1.2'
assertJVer = '3.9.1'
Expand Down
71 changes: 1 addition & 70 deletions rxbilling/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'org.jetbrains.dokka-android'

def libraryVersionName = rootProject.extensions.getByName("ext")["versionName"]

android {

defaultConfig {
versionName "3.0.0"
minSdkVersion minSdkVer
targetSdkVersion targetSdkVer
compileSdkVersion compileSdkVer
Expand Down Expand Up @@ -59,49 +56,6 @@ dependencies {

}

def siteUrl = 'https://github.com/betterme-dev/RxBilling' // Homepage URL of the library
def gitUrl = 'https://github.com/betterme-dev/RxBilling.git' // Git repository URL
def issueUrl = 'https://github.com/betterme-dev/RxBilling/issues' // Issues URL
group = GROUP // Maven Group ID for the artifact
version = libraryVersionName

install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging POM_PACKAGING

// Add your description here
name POM_NAME
description = POM_DESCRIPTION
url SITE_URL

// Set your license
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id 'dmytro-ostapovets'
name 'Dmytro Ostapovets'
email "[email protected]"
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}

task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier.set('sources')
Expand All @@ -128,26 +82,3 @@ artifacts {

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")

configurations = ['archives']
pkg {
repo = "rxbilling"
name = "com.betterme:rxbilling"
websiteUrl = SITE_URL
vcsUrl = VCS_URL
issueTrackerUrl = VCS_ISSUES_URL
userOrg = 'betterme'
licenses = ["Apache-2.0"]
publish = true
version {
name = libraryVersionName
desc = 'Billing library release $libraryVersionName'
released = new Date()
vcsTag = libraryVersionName
}
}
}
Loading

0 comments on commit 781726f

Please sign in to comment.