Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
mvojtkovszky committed Sep 12, 2022
2 parents 39235a1 + 83da78b commit 9b8146d
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 189 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## 2.0.0 (2022-09-12)
* update Google billing client to 5.0.0 and adjust to all changes required to support it
* renamed all references from "sku" to "product" to reflect Google's billing client naming conventions.
* add `PriceUtil` object to simplify price formatting.
* bump Kotlin to 1.7.10, Gradle plugin to 7.2.2, core-ktx to 1.9.0

## 1.10.0 (2022-04-29)
* update Google billing client to 4.1.0
* bump Kotlin to 1.6.21, Serialization to 1.3.2, Gradle plugin to 7.1.3
Expand Down
50 changes: 26 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# BillingHelper
Wrapper around Google Play Billing Library, simplifying its use.
Handles client connection, querying sku details, owned purchase, different purchase types, acknowledging purchases etc.
Handles client connection, querying product details, owned purchase, different purchase types, acknowledging purchases etc.

## How does it work?
Make sure your Activity/Fragment implements BillingListener and initializes BillingHelper
Your app requires Billing permission in the manifest
``` xml
<uses-permission android:name="com.android.vending.BILLING" />
```

<br/>Make sure your Activity/Fragment implements BillingListener and initializes BillingHelper
``` kotlin
class MainActivity: AppCompatActivity(), BillingListener {

Expand All @@ -12,15 +17,15 @@ class MainActivity: AppCompatActivity(), BillingListener {
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
super.onCreate(savedInstanceState, persistentState)

// Construct helper - by default, connection will be initialized immediately with sku details and
// owned purchases queried. All events are reported via billingListener.
// At least one of skuInAppPurchases, skuSubscriptions is required.
// Construct helper - by default, connection will be initialized immediately with product details
// and owned purchases queried. All events are reported via billingListener.
// At least one of productInAppPurchases or productSubscriptions is required.
// For more configuration options, check BillingHelper constructor parameters.
billing = BillingHelper(
context = this,
skuInAppPurchases = listOf("inAppPurchaseSkuName1", "inAppPurchaseSkuName2"),
skuSubscriptions = listOf("subscriptionSkuName"),
billingListener = this
context = this,
productInAppPurchases = listOf("inAppPurchaseSkuName1", "inAppPurchaseSkuName2"),
productSubscriptions = listOf("subscriptionSkuName"),
billingListener = this
)
}

Expand All @@ -40,26 +45,26 @@ class MainActivity: AppCompatActivity(), BillingListener {
``` kotlin
fun consumePurchase(purchase: Purchase)
fun endClientConnection()
fun getPurchaseForSkuName(skuName: String): Purchase?
fun getSkuDetails(skuName: String): SkuDetails?
fun isPurchased(skuName: String): Boolean
fun launchPurchaseFlow(activity: Activity, skuName: String)
fun launchPriceChangeConfirmationFlow(activity: Activity, skuDetails: SkuDetails)
fun initClientConnection(queryForSkuDetailsOnConnected: Boolean,queryForOwnedPurchasesOnConected: Boolean)
fun getPurchaseForProductName(productName: String): Purchase?
fun getProductDetails(productName: String): ProductDetails?
fun isPurchased(productName: String): Boolean
fun launchPurchaseFlow(activity: Activity, productName: String)
fun launchPriceChangeConfirmationFlow(activity: Activity, productDetails: ProductDetails)
fun initClientConnection(queryForProductDetailsOnConnected: Boolean, queryForOwnedPurchasesOnConected: Boolean)
fun initQueryOwnedPurchases()
fun initQuerySkuDetails()
fun initQueryProductDetails()
fun acknowledgePurchases(purchases: List<Purchase>)
fun isFeatureSupported(feature: String)
fun addBillingListener(listener: BillingListener)
fun removeBillingListener(listener: BillingListener)

var querySkuDetailsOnConnected: Boolean
var queryProductDetailsOnConnected: Boolean
var queryOwnedPurchasesOnConnected: Boolean
var autoAcknowledgePurchases: Boolean
val billingReady: Boolean
val connectionState: Int
val purchasesQueried: Boolean
val skuDetailsQueried: Boolean
val productDetailsQueried: Boolean
val isConnectionFailure: Boolead
val purchasesQueriedOrConnectionFailure: Boolean
```
Expand All @@ -70,8 +75,8 @@ enum class BillingEvent {
BILLING_CONNECTED,
BILLING_CONNECTION_FAILED,
BILLING_DISCONNECTED,
QUERY_SKU_DETAILS_COMPLETE,
QUERY_SKU_DETAILS_FAILED,
QUERY_PRODUCT_DETAILS_COMPLETE,
QUERY_PRODUCT_DETAILS_FAILED,
QUERY_OWNED_PURCHASES_COMPLETE,
QUERY_OWNED_PURCHASES_FAILED,
PURCHASE_COMPLETE,
Expand All @@ -80,10 +85,7 @@ enum class BillingEvent {
PURCHASE_ACKNOWLEDGE_SUCCESS,
PURCHASE_ACKNOWLEDGE_FAILED,
CONSUME_PURCHASE_SUCCESS,
CONSUME_PURCHASE_FAILED,
PRICE_CHANGE_CONFIRMATION_SUCCESS,
PRICE_CHANGE_CONFIRMATION_CANCELLED,
PRICE_CHANGE_CONFIRMATION_FAILED
CONSUME_PURCHASE_FAILED
}
```

Expand Down
4 changes: 2 additions & 2 deletions billinghelper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ android {

dependencies {
/* https://developer.android.com/jetpack/androidx/releases/core */
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.core:core-ktx:1.9.0'
/*
https://developer.android.com/google/play/billing/billing_library_overview
https://developer.android.com/google/play/billing/release-notes
*/
api 'com.android.billingclient:billing-ktx:4.1.0'
api 'com.android.billingclient:billing-ktx:5.0.0'

/* https://developer.android.com/jetpack/androidx/releases/test */
testImplementation 'junit:junit:4.13.2'
Expand Down
2 changes: 1 addition & 1 deletion billinghelper/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ buildTypes=debug,release
groupId=com.github.mvojtkovszky
artifactId=BillingHelper
moduleId=billinghelper
versionName=1.10.0
versionName=2.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ enum class BillingEvent {
BILLING_DISCONNECTED,

/**
* Success from [BillingClient.querySkuDetailsAsync]
* Success from [BillingClient.queryProductDetailsAsync]
*/
QUERY_SKU_DETAILS_COMPLETE,
QUERY_PRODUCT_DETAILS_COMPLETE,

/**
* Failure from [BillingClient.querySkuDetailsAsync]
* Failure from [BillingClient.queryProductDetailsAsync]
*/
QUERY_SKU_DETAILS_FAILED,
QUERY_PRODUCT_DETAILS_FAILED,

/**
* Success from [BillingClient.queryPurchasesAsync]
Expand Down Expand Up @@ -78,22 +78,7 @@ enum class BillingEvent {
/**
* Failure from [BillingClient.consumeAsync]
*/
CONSUME_PURCHASE_FAILED,

/**
* Success from [BillingClient.launchPriceChangeConfirmationFlow]
*/
PRICE_CHANGE_CONFIRMATION_SUCCESS,

/**
* User cancelled [BillingClient.launchPriceChangeConfirmationFlow]
*/
PRICE_CHANGE_CONFIRMATION_CANCELLED,

/**
* Failure from [BillingClient.launchPriceChangeConfirmationFlow]
*/
PRICE_CHANGE_CONFIRMATION_FAILED;
CONSUME_PURCHASE_FAILED;
// endregion event types

// region helpers
Expand All @@ -102,36 +87,35 @@ enum class BillingEvent {
*/
val isFailure: Boolean
get() = listOf(
BILLING_CONNECTION_FAILED, QUERY_SKU_DETAILS_FAILED, QUERY_OWNED_PURCHASES_FAILED,
PURCHASE_FAILED, CONSUME_PURCHASE_FAILED, PRICE_CHANGE_CONFIRMATION_FAILED
BILLING_CONNECTION_FAILED, QUERY_PRODUCT_DETAILS_FAILED, QUERY_OWNED_PURCHASES_FAILED,
PURCHASE_FAILED, CONSUME_PURCHASE_FAILED
).contains(this)

/**
* Is event a success by nature.
*/
val isSuccess: Boolean
get() = listOf(
BILLING_CONNECTED, QUERY_SKU_DETAILS_COMPLETE, QUERY_OWNED_PURCHASES_COMPLETE,
PURCHASE_COMPLETE, PURCHASE_ACKNOWLEDGE_SUCCESS, CONSUME_PURCHASE_SUCCESS,
PRICE_CHANGE_CONFIRMATION_SUCCESS
BILLING_CONNECTED, QUERY_PRODUCT_DETAILS_COMPLETE, QUERY_OWNED_PURCHASES_COMPLETE,
PURCHASE_COMPLETE, PURCHASE_ACKNOWLEDGE_SUCCESS, CONSUME_PURCHASE_SUCCESS
).contains(this)

/**
* Is event a failure in an actively initialized flow, usually accompanied by a dialog. One of:
* [PURCHASE_FAILED], [PRICE_CHANGE_CONFIRMATION_FAILED]
* [PURCHASE_FAILED]
*/
val isActiveActionFailure: Boolean
get() = listOf(
PURCHASE_FAILED, PRICE_CHANGE_CONFIRMATION_FAILED
PURCHASE_FAILED
).contains(this)

/**
* Is event a success in an actively initialized flow, usually accompanied by a dialog. One of:
* [PURCHASE_COMPLETE], [PRICE_CHANGE_CONFIRMATION_SUCCESS]
* [PURCHASE_COMPLETE]
*/
val isActiveActionSuccess: Boolean
get() = listOf(
PURCHASE_COMPLETE, PRICE_CHANGE_CONFIRMATION_SUCCESS
PURCHASE_COMPLETE
).contains(this)

/**
Expand All @@ -154,11 +138,11 @@ enum class BillingEvent {
).contains(this)

/**
* Determine if event belongs to query sku details flow.
* Determine if event belongs to query product details flow.
*/
val isQuerySkuDetailsFlow: Boolean
val isQueryProductDetailsFlow: Boolean
get() = listOf(
QUERY_SKU_DETAILS_COMPLETE, QUERY_SKU_DETAILS_FAILED
QUERY_PRODUCT_DETAILS_COMPLETE, QUERY_PRODUCT_DETAILS_FAILED
).contains(this)

/**
Expand Down Expand Up @@ -192,14 +176,5 @@ enum class BillingEvent {
get() = listOf(
PURCHASE_ACKNOWLEDGE_SUCCESS, PURCHASE_ACKNOWLEDGE_FAILED
).contains(this)

/**
* Determine if event belongs to price change confirmation flow.
*/
val isPriceChangeConfirmationFlow: Boolean
get() = listOf(
PRICE_CHANGE_CONFIRMATION_FAILED, PRICE_CHANGE_CONFIRMATION_CANCELLED,
PRICE_CHANGE_CONFIRMATION_SUCCESS
).contains(this)
// endregion flow helpers
}
Loading

0 comments on commit 9b8146d

Please sign in to comment.