Skip to content

Commit

Permalink
v 1.0.3
Browse files Browse the repository at this point in the history
- Billing lib 6.0.0 updated
- Implemented consumable one-time products
- Billing Client Ready/Error Callbacks Added
- Set Logging for Release or Debug (By default only logs on debug mode)
- Now initialize billing lib in App class (if you want)
- Billing client ready check issue solved
  • Loading branch information
hannanshahid committed Jun 14, 2023
1 parent a9d44f9 commit 5bd56ac
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 39 deletions.
86 changes: 76 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

[![](https://jitpack.io/v/Funsol-Projects/Funsol-Billing-Helper.svg)](https://jitpack.io/#Funsol-Projects/Funsol-Billing-Helper)

Funsol Billing Helper is a simple, straight-forward implementation of the Android v5.1 In-app billing API
Funsol Billing Helper is a simple, straight-forward implementation of the Android v6.0 In-app billing API

> Support both IN-App and Subscriptions.
### **Billing v5 subscription model:**
### **Billing v6 subscription model:**

![Subcription](https://user-images.githubusercontent.com/106656179/227849820-8b9e8566-fa6e-40d4-862e-77aaeaa65e6c.png)

Expand Down Expand Up @@ -36,10 +36,10 @@ Add Funsol Billing Helper dependencies in App level build.gradle.

```kotlin

dependencies {
implementation 'com.github.Funsol-Projects:Funsol-Billing-Helper:v1.0.2'
}
dependencies {
implementation 'com.github.Funsol-Projects:Funsol-Billing-Helper:v1.0.3'
}

```

## Step 3 (Setup)
Expand All @@ -61,11 +61,43 @@ if both subscription and In-App
.setInAppKeys(mutableListOf("In-App Key"))

```
if consumable in-App
```kotlin

Call this in first stable activity
FunSolBillingHelper(this)
.setInAppKeys(mutableListOf("In-App Key, In-App consumable Key"))
.setConsumableKeys(mutableListOf("In-App consumable Key"))

```
**Note: you have add consumable key in both func ```setInAppKeys()``` and ```setConsumableKeys()```**

Call this in first stable activity or in App class

### Billing Client Listeners

```kotlin

FunSolBillingHelper(this)
.setSubKeys(mutableListOf("Subs Key", "Subs Key 2"))
.setInAppKeys(mutableListOf("In-App Key"))
.enableLogging()
.setBillingClientListener(object : BillingClientListener {
override fun onClientReady() {
Log.i("billing", "onClientReady: ")
}

override fun onClientInitError() {
Log.i("billing", "onClientInitError: ")
}

})


```

### Enable Logs

##### Only for debug

```kotlin

Expand All @@ -76,11 +108,25 @@ Call this in first stable activity


```

##### For both Debug/Release

```kotlin

FunSolBillingHelper(this)
.setSubKeys(mutableListOf("Subs Key", "Subs Key 2"))
.setInAppKeys(mutableListOf("In-App Key"))
.enableLogging(isEnableWhileRelease = true)


```


### Buy In-App Product

Subscribe to a Subscription
```kotlin
FunSolBillingHelper(this).buyInApp("In-App Key",false)
FunSolBillingHelper(this).buyInApp(activity,"In-App Key",false)
```
```fasle``` value used for **isPersonalizedOffer** attribute:

Expand All @@ -91,11 +137,11 @@ If your app can be distributed to users in the European Union, use the **isPerso

Subscribe to a Subscription
```kotlin
FunSolBillingHelper(this).subscribe(this, "Base Plan ID")
FunSolBillingHelper(this).subscribe(activity, "Base Plan ID")
```
Subscribe to a offer
```kotlin
FunSolBillingHelper(this).subscribe(this, "Base Plan ID","Offer ID")
FunSolBillingHelper(this).subscribe(activity, "Base Plan ID","Offer ID")
```

**Note: it auto acknowledge the subscription and give callback when product acknowledged successfully.**
Expand Down Expand Up @@ -147,9 +193,15 @@ Interface implementation to handle purchase results and errors.

FunSolBillingHelper(this).setBillingEventListener(object : BillingEventListener {
override fun onProductsPurchased(purchases: List<Purchase?>) {
//call back when purchase occured
}

override fun onPurchaseAcknowledged(purchase: Purchase) {
//call back when purchase occur and acknowledged
}

override fun onPurchaseConsumed(purchase: Purchase) {
//call back when purchase occur and consumed
}

override fun onBillingError(error: ErrorType) {
Expand Down Expand Up @@ -205,6 +257,10 @@ Interface implementation to handle purchase results and errors.

ErrorType.OLD_PURCHASE_TOKEN_NOT_FOUND -> {

}

ErrorType.CONSUME_ERROR -> {

}
else -> {

Expand Down Expand Up @@ -344,6 +400,16 @@ FunSolBillingHelper(this).release()
```
This Method used for Releasing the client object and save from memory leaks

## CHANGELOG

- 14-06-2023
- Billing lib 6.0.0 updated
- Implemented consumable one-time products
- Billing Client Ready/Error Callbacks Added
- Set Logging for Release or Debug (By default only logs on debug mode)
- Now initialize billing lib in App class (if you want)
- Billing client ready check issue solved


## License

Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ dependencies {
implementation project(path: ':funsol-billing-utils')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
implementation 'com.android.billingclient:billing:6.0.0'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.billing.funsolbillinghelper

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.funsol.iap.billing.BillingClientListener
import com.funsol.iap.billing.FunSolBillingHelper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -11,7 +13,16 @@ class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
FunSolBillingHelper(this).setSubKeys(mutableListOf("basic"))
FunSolBillingHelper(this).setSubKeys(mutableListOf("basic")).enableLogging(isEnableWhileRelease = true).setBillingClientListener(object : BillingClientListener {
override fun onClientReady() {
Log.i("billing", "onClientReady: ")
}

override fun onClientInitError() {
Log.i("billing", "onClientInitError: ")
}

})

}
}
6 changes: 3 additions & 3 deletions funsol-billing-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {

dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.android.billingclient:billing:5.1.0'
implementation 'com.android.billingclient:billing:6.0.0'
}

afterEvaluate {
Expand All @@ -49,13 +49,13 @@ afterEvaluate {
from components.release
groupId = 'com.github.Funsol-Projects'
artifactId = 'Funsol-Billing-Helper'
version = 'v1.0.2'
version = 'v1.0.3'
}
debug(MavenPublication) {
from components.debug
groupId = 'com.github.Funsol-Projects'
artifactId = 'Funsol-Billing-Helper'
version = 'v1.0.2'
version = 'v1.0.3'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.funsol.iap.billing

import com.android.billingclient.api.Purchase
import com.funsol.iap.billing.model.ErrorType

interface BillingClientListener {
fun onClientReady()
fun onClientInitError()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import com.funsol.iap.billing.model.ErrorType
interface BillingEventListener {
fun onProductsPurchased(purchases: List<Purchase?>)
fun onPurchaseAcknowledged(purchase: Purchase)
fun onPurchaseConsumed(purchase: Purchase)
fun onBillingError(error: ErrorType)
}
Loading

0 comments on commit 5bd56ac

Please sign in to comment.