Skip to content

Commit

Permalink
Merge pull request #12 from betterme-dev/develop
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
dmytro-ostapovets authored Jul 14, 2019
2 parents 75b01a1 + f886de0 commit 3b2c6b2
Show file tree
Hide file tree
Showing 20 changed files with 382 additions and 398 deletions.
154 changes: 77 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,33 @@ The result of this operation will be delivered to your updates observer
The result of this operation will be delivered to onActivityResult() of your Activity or Fragment,
updates observer will not be triggered

private fun startFlowWithClient() {
disposable.add(rxBilling.launchFlow(this, BillingFlowParams.newBuilder()
.setSku("you_id")
.setType(BillingClient.SkuType.SUBS)
.build())
.subscribe({
//flow started
}, {
//handle error
}))
}
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(resultCode, data)
.subscribe({
//handle purchase
}, {
//handle error
}))
disposable.add(
rxBillingFlow.handleActivityResult(data)
.subscribe({
Timber.d("onActivityResult $it")
tvServiceFlow.text = it.toString()
}, {
Timber.e(it)
tvServiceFlow.text = it.toString()
}))
}

## Load owned products
Expand All @@ -125,78 +130,73 @@ updates observer will not be triggered
}))
}

## Load owned subscriptions
## Load owned purchases

private fun loadSubscriptions() {
disposable.add(rxBilling.getSubscriptions()
.subscribe({
//handle purchases
}, {
//handle error
}))
}

## Load products history

private fun loadPurchasesHistory() {
disposable.add(rxBilling.getPurchaseHistory()
.subscribe({
//handle purchases
}, {
//handle error
}))
}

## Load subscriptions history

private fun loadPurchasesHistory() {
disposable.add(rxBilling.getSubscriptionHistory()
.subscribe({
//handle purchases
}, {
//handle error
}))
private fun loadPurchases() {
disposable.add(
rxBilling.getPurchases(BillingClient.SkuType.SUBS)
.subscribe({
Timber.d("getPurchases $it")
tvPurchases.text = it.toString()
}, {
Timber.e(it)
}))
}

## Load product sku details
## Load history

private fun loadPurchasesHistory() {
disposable.add(rxBilling.getPurchaseSkuDetails(listOf("your_id1", "your_id2"))
.subscribe({
//handle details
}, {
//handle details
}))
private fun loadHistory() {
disposable.add(
rxBilling.getPurchaseHistory(BillingClient.SkuType.SUBS)
.subscribe({
Timber.d("getPurchaseHistory $it")
tvHistory.text = it.toString()
}, {
Timber.e(it)
}))
}

## Load subscription sku details
## Load sku details

private fun loadDetails() {
disposable.add(rxBilling.getSubscriptionSkuDetails(listOf("your_id1", "your_id2"))
.subscribe({
//handle details
}, {
//handle details
}))
disposable.add(
rxBilling.getSkuDetails(
SkuDetailsParams.newBuilder()
.setSkusList(listOf("your_id1", "your_id2"))
.setType(BillingClient.SkuType.SUBS)
.build())
.subscribe({
Timber.d("loadDetails $it")
tvDetails.text = it.toString()
}, {
Timber.e(it)
}))
}

## Consume product

private fun consume() {
disposable.add(rxBilling.consumeProduct("purchase_token")
.subscribe({
//completed
}, {
//handle error
}))
disposable.add(
rxBilling.consumeProduct(
ConsumeParams.newBuilder()
.setPurchaseToken("token")
.build())
.subscribe()
)
}

## AndroidX

If you are going to migrate on AndroidX, please use

com.gen.rxbilling.lifecycle.androidx.BillingConnectionManager

and

com.gen.rxbilling.flow.delegate.androidx.FragmentFlowDelegate
## Acknowledge item

private fun acknowledge() {
disposable.add(
rxBilling.acknowledge(
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken("token")
.setDeveloperPayload("payload")
.build())
.subscribe({
Timber.d("acknowledge success")
}, {
Timber.e(it)
}))
}
4 changes: 1 addition & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ dependencies {
implementation developmentDependencies.timber
implementation dataDependencies.rxJava
implementation dataDependencies.rxAndroid
implementation supportDependencies.appCompat
implementation presentationDependencies.appCompat

testImplementation testDependencies.jUnit
testImplementation testDependencies.mockito
testImplementation testDependencies.mockitoKotlin

androidTestImplementation androidTestDependencies.testRunner
androidTestImplementation androidTestDependencies.espressoCore
}
142 changes: 85 additions & 57 deletions app/src/main/java/com/gen/rxbilling/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package com.gen.rxbilling.sample

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingFlowParams
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.arch.BillingConnectionManager
import com.gen.rxbilling.lifecycle.BillingConnectionManager
import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.activity_main.*
import timber.log.Timber
Expand Down Expand Up @@ -45,18 +44,22 @@ class MainActivity : AppCompatActivity() {
btnLoadDetails.setOnClickListener {
loadDetails()
}
btnAcknowledge.setOnClickListener {
acknowledge()
}
}

override fun onStart() {
super.onStart()
disposable.add(rxBilling.observeUpdates()
.subscribe({
Timber.d("observeUpdates $it")
tvClientFlow.text = it.toString()
}, {
Timber.e(it)
tvClientFlow.text = it.toString()
}))
disposable.add(
rxBilling.observeUpdates()
.subscribe({
Timber.d("observeUpdates $it")
tvClientFlow.text = it.toString()
}, {
Timber.e(it)
tvClientFlow.text = it.toString()
}))
}

override fun onStop() {
Expand All @@ -66,65 +69,90 @@ class MainActivity : AppCompatActivity() {

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
disposable.add(rxBillingFlow.handleActivityResult(resultCode, data)
.subscribe({
Timber.d("onActivityResult $it")
tvServiceFlow.text = it.toString()
}, {
Timber.e(it)
tvServiceFlow.text = it.toString()
}))
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)
}))
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()
.setSku("you_id")
.setType(BillingClient.SkuType.SUBS)
.build())
.subscribe({
Timber.d("startFlowWithClient")
}, {
Timber.e(it)
}))
disposable.add(
rxBilling.launchFlow(this, BillingFlowParams.newBuilder()
.setSkuDetails(SkuDetails("{}"))
.build())
.subscribe({
Timber.d("startFlowWithClient")
}, {
Timber.e(it)
}))
}

private fun loadPurchases() {
disposable.add(rxBilling.getPurchases()
.subscribe({
Timber.d("getPurchases $it")
tvPurchases.text = it.toString()
}, {
Timber.e(it)
}))
disposable.add(
rxBilling.getPurchases(BillingClient.SkuType.SUBS)
.subscribe({
Timber.d("getPurchases $it")
tvPurchases.text = it.toString()
}, {
Timber.e(it)
}))
}

private fun loadHistory() {
disposable.add(rxBilling.getPurchaseHistory()
.subscribe({
Timber.d("getPurchaseHistory $it")
tvHistory.text = it.toString()
}, {
Timber.e(it)
}))
disposable.add(
rxBilling.getPurchaseHistory(BillingClient.SkuType.SUBS)
.subscribe({
Timber.d("getPurchaseHistory $it")
tvHistory.text = it.toString()
}, {
Timber.e(it)
}))
}

private fun loadDetails() {
disposable.add(rxBilling.getPurchaseSkuDetails(listOf("your_id1", "your_id2"))
.subscribe({
Timber.d("loadDetails $it")
tvDetails.text = it.toString()
}, {
Timber.e(it)
}))
disposable.add(
rxBilling.getSkuDetails(
SkuDetailsParams.newBuilder()
.setSkusList(listOf("your_id1", "your_id2"))
.setType(BillingClient.SkuType.SUBS)
.build())
.subscribe({
Timber.d("loadDetails $it")
tvDetails.text = it.toString()
}, {
Timber.e(it)
}))
}

private fun acknowledge() {
disposable.add(
rxBilling.acknowledge(
AcknowledgePurchaseParams.newBuilder()
.setPurchaseToken("token")
.setDeveloperPayload("payload")
.build())
.subscribe({
Timber.d("acknowledge success")
}, {
Timber.e(it)
}))
}
}
Loading

0 comments on commit 3b2c6b2

Please sign in to comment.