Skip to content

Commit

Permalink
Release/3.0.11 (#19)
Browse files Browse the repository at this point in the history
* Update missing values for new version of billing library subscription pricing information.

* v3.0.11

* Bump Amazon IAP to 3.0.4 to resolve internal runtime crash - see RevenueCat/purchases-flutter#412

* Fix casting runtime error when an ArrayList is returned for the records

* Minor refactoring and code clean up

* Bump Google Play Billing to 5.1.0

* Update subscription offer support for v5 google play billing.

* Update README.md
  • Loading branch information
rjsuzuki authored Apr 14, 2023
1 parent c4d1999 commit da841dc
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 31 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ Through a combination of Adapter and Facade design patterns, this library allows
[![build_and_publish](https://github.com/rjsuzuki/billingz/actions/workflows/release-package.yml/badge.svg)](https://github.com/rjsuzuki/billingz/actions/workflows/release-package.yml) [![](https://jitpack.io/v/rjsuzuki/billingz.svg)](https://jitpack.io/#rjsuzuki/billingz) [![](https://jitci.com/gh/rjsuzuki/billingz/svg)](https://jitci.com/gh/rjsuzuki/billingz)

Currently supports up to:
- `google billing: 5.0.0`
- `amazon in-app: 2.0.76` (v2.0.6)
- `amazon appstore sdk: 3.0.2` (v2.1.0+)

- `google billing: 5.1.0`
- `amazon in-app: 2.0.76` (v2.0.6)
- `amazon appstore sdk: 3.0.4` (v2.1.0+)
## Version History

[Release History and Notes](https://github.com/rjsuzuki/billingz/releases)
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object Dependencies {
/**
* Billing libs
*/
const val google_billing = "5.0.0"
const val amazon_iap = "3.0.2"
const val google_billing = "5.1.0"
const val amazon_iap = "3.0.4"

/**
* UI libs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ class AmazonStore internal constructor() : Storez {

override fun resume() {
Logger.v(TAG, "resuming...")
if (client.isReady())
if (client.isReady()) {
sales.refreshQueries()
}
else if (!client.initialized()) {
client.init(context, connectionListener)
client.connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class AmazonSales(
PurchaseResponse.RequestStatus.ALREADY_PURCHASED -> Orderz.Result.PRODUCT_ALREADY_OWNED
PurchaseResponse.RequestStatus.INVALID_SKU -> Orderz.Result.INVALID_PRODUCT
PurchaseResponse.RequestStatus.NOT_SUPPORTED -> Orderz.Result.NOT_SUPPORTED
PurchaseResponse.RequestStatus.PENDING -> Orderz.Result.PENDING
}
}

Expand Down Expand Up @@ -491,7 +492,8 @@ class AmazonSales(
// again even if you receive a second receipt.
return false
}
else -> {}

else -> Logger.w(TAG, "Unhandled ProductType: ${receipt.productType}")
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import com.zuko.billingz.core.misc.CleanUpz
* Blueprint of the core logic of the library.
*/
interface Clientz : CleanUpz {

// fun getBillingClient(): BillingClient?
/**
*
*/
var connectionState: MutableLiveData<ConnectionStatus>

/**
Expand Down Expand Up @@ -87,7 +88,7 @@ interface Clientz : CleanUpz {
* Interface for reconnection logic to the billing service
* INTERNAL USE ONLY
*/
interface ReconnectListener {
interface ReconnectListener { //todo

/**
*
Expand Down
33 changes: 33 additions & 0 deletions lib/core/src/main/java/com/zuko/billingz/core/store/model/Offer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
*
* * Copyright 2021 rjsuzuki
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
*
*/

package com.zuko.billingz.core.store.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class Offer(
override val billingPeriod: String,
override val formattedPrice: String,
override val priceCurrencyCode: String,
override val priceAmountMicros: Long,
override val recurrenceMode: Int,
override val billingCycleCount: Int
) : Productz.Offer, Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
*
* * Copyright 2021 rjsuzuki
* *
* * Licensed under the Apache License, Version 2.0 (the "License");
* * you may not use this file except in compliance with the License.
* * You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing, software
* * distributed under the License is distributed on an "AS IS" BASIS,
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * See the License for the specific language governing permissions and
* * limitations under the License.
* *
*
*/

package com.zuko.billingz.core.store.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class OfferDetails(
override val offerTags: List<String>,
override val offerToken: String,
override val offers: List<Offer>
) : Productz.OfferDetails, Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ interface Orderz : ModuleIdentifier {
ERROR(6), // FAILED
PRODUCT_ALREADY_OWNED(7),
PRODUCT_NOT_OWNED(8),
NO_RESULT(9)
NO_RESULT(9),
PENDING(10)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ data class PricingInfo(
override val introPrice: String?,
override val introPricePeriod: String?,
override val billingPeriod: String?,
override val trialPeriod: String?
override val trialPeriod: String?,
override val subscriptionOffers: List<OfferDetails>?
) : Productz.Pricing, Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,31 @@ interface Productz : ModuleIdentifier {
val introPricePeriod: String?
val billingPeriod: String?
val trialPeriod: String?

/**
* Only available for Google products. Amazon products will return null.
*/
val subscriptionOffers: List<OfferDetails>?
}

/**
* For Google Play SubscriptionOfferDetails support
*/
interface OfferDetails {
val offerTags: List<String>
val offerToken: String
val offers: List<Offer>
}

/**
* For Google Play SubscriptionOfferDetails support
*/
interface Offer {
val billingPeriod: String
val formattedPrice: String
val priceCurrencyCode: String
val priceAmountMicros: Long
val recurrenceMode: Int
val billingCycleCount: Int
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package com.zuko.billingz.google.store.model

import com.android.billingclient.api.ProductDetails
import com.android.billingclient.api.SkuDetails
import com.zuko.billingz.core.store.model.Offer
import com.zuko.billingz.core.store.model.OfferDetails
import com.zuko.billingz.core.store.model.PricingInfo
import com.zuko.billingz.core.store.model.Productz
import java.util.Currency
Expand Down Expand Up @@ -89,7 +91,8 @@ data class GoogleProduct(
introPrice = skuDetails.introductoryPrice,
introPricePeriod = skuDetails.introductoryPricePeriod,
billingPeriod = skuDetails.subscriptionPeriod,
trialPeriod = skuDetails.freeTrialPeriod
trialPeriod = skuDetails.freeTrialPeriod,
subscriptionOffers = null
)
}

Expand Down Expand Up @@ -117,31 +120,57 @@ data class GoogleProduct(
currency =
Currency.getInstance(productDetails.subscriptionOfferDetails?.firstOrNull()?.pricingPhases?.pricingPhaseList?.firstOrNull()?.priceCurrencyCode)

productDetails.subscriptionOfferDetails?.forEach { offerDetails ->
offerDetails.offerToken
offerDetails.offerTags
offerDetails.pricingPhases.pricingPhaseList.forEach { pricingPhase ->
pricingPhase.billingPeriod
pricingPhase.formattedPrice
pricingPhase.priceCurrencyCode
pricingPhase.recurrenceMode
pricingPhase.billingCycleCount
pricingPhase.priceAmountMicros
}
}
pricingInfo = PricingInfo(
introPrice = null,
introPricePeriod = null,
billingPeriod = productDetails.subscriptionOfferDetails?.firstOrNull()?.pricingPhases?.pricingPhaseList?.firstOrNull()?.billingPeriod,
trialPeriod = null
billingPeriod = null,
trialPeriod = null,
subscriptionOffers = convertSubscriptionOfferDetailsTo(productDetails.subscriptionOfferDetails)
)

} else {
price = productDetails.oneTimePurchaseOfferDetails?.formattedPrice
currency =
Currency.getInstance(productDetails.oneTimePurchaseOfferDetails?.priceCurrencyCode)
}
}

private fun convertSubscriptionOfferDetailsTo(offers: List<ProductDetails.SubscriptionOfferDetails>?): List<OfferDetails>? {
if (offers.isNullOrEmpty()) {
return null
}
val offerDetailsList = mutableListOf<OfferDetails>()
offers.forEach {
val details = convertSubscriptionOfferTo(it)
offerDetailsList.add(details)
}
return offerDetailsList
}

private fun convertSubscriptionOfferTo(offer: ProductDetails.SubscriptionOfferDetails): OfferDetails {
val offers = mutableListOf<Offer>()
offer.pricingPhases.pricingPhaseList.forEach { pricingPhase ->
val o = convertPricingPhaseTo(pricingPhase)
offers.add(o)
}
return OfferDetails(
offerTags = offer.offerTags,
offerToken = offer.offerToken,
offers = offers
)
}

private fun convertPricingPhaseTo(p: ProductDetails.PricingPhase): Offer {
return Offer(
billingPeriod = p.billingPeriod,
formattedPrice = p.formattedPrice,
priceCurrencyCode = p.priceCurrencyCode,
priceAmountMicros = p.priceAmountMicros,
recurrenceMode = p.recurrenceMode,
billingCycleCount = p.billingCycleCount
)
}

override fun getProductId(): String? {
return productId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,11 @@ class GoogleSales(
private fun queryOrderHistory(type: Productz.Type?) {
Logger.v(TAG, "queryOrderHistory: $type")
val skuType =
if (type == Productz.Type.SUBSCRIPTION) BillingClient.ProductType.SUBS else BillingClient.ProductType.INAPP
if (type == Productz.Type.SUBSCRIPTION) {
BillingClient.ProductType.SUBS
} else {
BillingClient.ProductType.INAPP
}

mainScope.launch(dispatcher.io()) {
if (isNewVersion) {
Expand Down Expand Up @@ -862,9 +866,9 @@ class GoogleSales(
receipt.entitlement = record.purchaseToken
receipt.orderDate = Date(record.purchaseTime)
if (isNewVersion) {
receipt.skus = record.products
receipt.skus = record.products.toList()
} else {
receipt.skus = record.skus
receipt.skus = record.skus.toList()
}
receipt.originalJson = record.originalJson
receipt.quantity = record.quantity
Expand Down
2 changes: 1 addition & 1 deletion version.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

v.major=3
v.minor=0
v.patch=10
v.patch=11

0 comments on commit da841dc

Please sign in to comment.