Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-3469 Remove deprecated purchase methods #1711

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
691a910
Bumps the purchases-android version to 8.0.0-SNAPSHOT.
JayShortway May 28, 2024
d7007b4
Bumps the billing client to 7.0.0. (Fails to compile.)
JayShortway May 28, 2024
8ab5bfc
Removes GoogleProrationMode, as ProrationMode is removed from BC7.
JayShortway May 28, 2024
57b48a9
Bumps the minSdkVersion from 19 to 21.
JayShortway May 28, 2024
db4dde0
Fixes some tests.
JayShortway May 28, 2024
840446f
Renames local prorationMode field to replacementMode in UpgradeInfoAPI.
JayShortway May 28, 2024
5918c60
Also renames reference to prorationMode to replacementMode in Upgrade…
JayShortway May 28, 2024
9119bca
Removes UpgradeInfo and related purchase() methods.
JayShortway May 29, 2024
bb44815
Removes all other deprecated purchase() methods.
JayShortway May 29, 2024
46e6fb0
Fixes api-tester.
JayShortway May 29, 2024
8f83ccc
Fixes purchase-tester.
JayShortway May 29, 2024
e7cb2a6
Fixes unitTests.
JayShortway May 29, 2024
8b92f73
Merge branch 'sdk-3465-support-bc7' into sdk-3469-remove-deprecated-p…
JayShortway May 30, 2024
0eddd0f
Removes an unused import from Purchases.
JayShortway May 30, 2024
3003da6
Support pending prepaid purchases (#1717)
tonidero Jun 5, 2024
603cd78
Revert "Support pending prepaid purchases (#1717)"
tonidero Jun 6, 2024
a2aaf5f
Revert "Removes all other deprecated purchase() methods."
JayShortway Jun 6, 2024
b5c02d5
Revert "Fixes api-tester."
JayShortway Jun 6, 2024
9b52608
Fixes api-tester again.
JayShortway Jun 6, 2024
85547d7
Revert "Fixes purchase-tester."
JayShortway Jun 6, 2024
0657bc1
Fixes purchase-tester again.
JayShortway Jun 6, 2024
b26ff1e
Partially reverts PurchasesTest.
JayShortway Jun 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.revenuecat.purchases.Package;
import com.revenuecat.purchases.Purchases;
import com.revenuecat.purchases.PurchasesError;
import com.revenuecat.purchases.UpgradeInfo;
import com.revenuecat.purchases.interfaces.ProductChangeCallback;
import com.revenuecat.purchases.interfaces.PurchaseCallback;
import com.revenuecat.purchases.models.StoreProduct;
Expand All @@ -24,8 +23,7 @@ static void check(final Purchases purchases,
final SkuDetails skuDetails,
final StoreProduct storeProduct,
final Package packageToPurchase,
final SubscriptionOption subscriptionOption,
final UpgradeInfo upgradeInfo) {
final SubscriptionOption subscriptionOption) {
final ProductChangeCallback purchaseChangeListener = new ProductChangeCallback() {
@Override
public void onCompleted(@Nullable StoreTransaction storeTransaction, @NonNull CustomerInfo customerInfo) {
Expand All @@ -47,9 +45,7 @@ public void onError(@NonNull PurchasesError error, boolean userCancelled) {

purchases.setAllowSharingPlayStoreAccount(true);
Purchases.setDebugLogsEnabled(false);
purchases.purchaseProduct(activity, storeProduct, upgradeInfo, purchaseChangeListener);
purchases.purchaseProduct(activity, storeProduct, makePurchaseListener);
purchases.purchasePackage(activity, packageToPurchase, upgradeInfo, purchaseChangeListener);
purchases.purchasePackage(activity, packageToPurchase, makePurchaseListener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import com.revenuecat.purchases.CustomerInfo
import com.revenuecat.purchases.Package
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.UpgradeInfo
import com.revenuecat.purchases.getNonSubscriptionSkusWith
import com.revenuecat.purchases.getSubscriptionSkusWith
import com.revenuecat.purchases.interfaces.ProductChangeCallback
import com.revenuecat.purchases.interfaces.PurchaseCallback
import com.revenuecat.purchases.models.StoreProduct
import com.revenuecat.purchases.models.StoreTransaction
Expand All @@ -23,22 +21,15 @@ private class DeprecatedPurchasesAPI {
purchases: Purchases,
activity: Activity,
storeProduct: StoreProduct,
upgradeInfo: UpgradeInfo,
subscriptionOption: SubscriptionOption,
packageToPurchase: Package,
) {
val purchaseChangeCallback = object : ProductChangeCallback {
override fun onCompleted(storeTransaction: StoreTransaction?, customerInfo: CustomerInfo) {}
override fun onError(error: PurchasesError, userCancelled: Boolean) {}
}
val purchaseCallback = object : PurchaseCallback {
override fun onCompleted(storeTransaction: StoreTransaction, customerInfo: CustomerInfo) {}
override fun onError(error: PurchasesError, userCancelled: Boolean) {}
}

purchases.purchaseProduct(activity, storeProduct, upgradeInfo, purchaseChangeCallback)
purchases.purchaseProduct(activity, storeProduct, purchaseCallback)
purchases.purchasePackage(activity, packageToPurchase, upgradeInfo, purchaseChangeCallback)
purchases.purchasePackage(activity, packageToPurchase, purchaseCallback)

purchases.purchaseProductWith(
Expand All @@ -51,31 +42,6 @@ private class DeprecatedPurchasesAPI {
activity,
storeProduct,
) { _: StoreTransaction, _: CustomerInfo -> }
purchases.purchaseProductWith(
activity,
storeProduct,
upgradeInfo,
onError = { _: PurchasesError, _: Boolean -> },
onSuccess = { _: StoreTransaction?, _: CustomerInfo -> },
)
purchases.purchaseProductWith(
activity,
storeProduct,
upgradeInfo,
) { _: StoreTransaction?, _: CustomerInfo -> }

purchases.purchasePackageWith(
activity,
packageToPurchase,
upgradeInfo,
onError = { _: PurchasesError, _: Boolean -> },
onSuccess = { _: StoreTransaction?, _: CustomerInfo -> },
)
purchases.purchasePackageWith(
activity,
packageToPurchase,
upgradeInfo,
) { _: StoreTransaction?, _: CustomerInfo -> }

purchases.purchasePackageWith(
activity,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,14 @@ import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.transition.MaterialContainerTransform
import com.revenuecat.purchases.CustomerInfo
import com.revenuecat.purchases.Offerings
import com.revenuecat.purchases.Package
import com.revenuecat.purchases.Purchases
import com.revenuecat.purchases.PurchasesError
import com.revenuecat.purchases.UpgradeInfo
import com.revenuecat.purchases.getCustomerInfoWith
import com.revenuecat.purchases.getOfferingsWith
import com.revenuecat.purchases.models.GoogleReplacementMode
import com.revenuecat.purchases.models.StoreProduct
import com.revenuecat.purchases.models.StoreTransaction
import com.revenuecat.purchases.purchasePackageWith
Expand Down Expand Up @@ -51,12 +48,6 @@ class DeprecatedOfferingFragment : Fragment(), DeprecatedPackageCardAdapter.Pack
handleSuccessfulPurchase(storeTransaction.orderId)
}

private val successfulUpgradeCallback: (purchase: StoreTransaction?, customerInfo: CustomerInfo) -> Unit =
{ storeTransaction, _ ->
toggleLoadingIndicator(false)
handleSuccessfulPurchase(storeTransaction?.orderId)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
sharedElementEnterTransition = MaterialContainerTransform().apply {
Expand Down Expand Up @@ -96,74 +87,30 @@ class DeprecatedOfferingFragment : Fragment(), DeprecatedPackageCardAdapter.Pack
override fun onPurchasePackageClicked(
cardView: View,
currentPackage: Package,
isUpgrade: Boolean,
) {
toggleLoadingIndicator(true)

if (isUpgrade) {
promptForUpgradeInfo { upgradeInfo ->
upgradeInfo?.let {
startPurchasePackage(currentPackage, upgradeInfo)
}
}
} else {
startPurchasePackage(currentPackage, null)
}
startPurchasePackage(currentPackage)
}

override fun onPurchaseProductClicked(
cardView: View,
currentProduct: StoreProduct,
isUpgrade: Boolean,
) {
toggleLoadingIndicator(true)

if (isUpgrade) {
promptForUpgradeInfo { upgradeInfo ->
upgradeInfo?.let {
startPurchaseProduct(currentProduct, upgradeInfo)
}
}
} else {
startPurchaseProduct(currentProduct, null)
}
}

private fun promptForUpgradeInfo(callback: (UpgradeInfo?) -> Unit) {
showOldSubIdPicker { subId ->
subId?.let {
showReplacementModePicker { replacementMode, error ->
if (error == null) {
replacementMode?.let {
callback(UpgradeInfo(subId, replacementMode.playBillingClientMode))
} ?: callback(UpgradeInfo(subId))
} else {
callback(null)
}
}
} ?: callback(null)
}
startPurchaseProduct(currentProduct)
}

private fun startPurchaseProduct(
currentProduct: StoreProduct,
upgradeInfo: UpgradeInfo?,
) {
when {
upgradeInfo == null -> Purchases.sharedInstance.purchaseProductWith(
requireActivity(),
currentProduct,
purchaseErrorCallback,
successfulPurchaseCallback,
)
upgradeInfo != null -> Purchases.sharedInstance.purchaseProductWith(
requireActivity(),
currentProduct,
upgradeInfo,
purchaseErrorCallback,
successfulUpgradeCallback,
)
}
Purchases.sharedInstance.purchaseProductWith(
requireActivity(),
currentProduct,
purchaseErrorCallback,
successfulPurchaseCallback,
)
}

private fun handleSuccessfulPurchase(orderId: String?) {
Expand All @@ -179,88 +126,16 @@ class DeprecatedOfferingFragment : Fragment(), DeprecatedPackageCardAdapter.Pack

private fun startPurchasePackage(
currentPackage: Package,
upgradeInfo: UpgradeInfo?,
) {
when {
upgradeInfo == null -> Purchases.sharedInstance.purchasePackageWith(
requireActivity(),
currentPackage,
purchaseErrorCallback,
successfulPurchaseCallback,
)
upgradeInfo != null -> Purchases.sharedInstance.purchasePackageWith(
requireActivity(),
currentPackage,
upgradeInfo,
purchaseErrorCallback,
successfulUpgradeCallback,
)
}
Purchases.sharedInstance.purchasePackageWith(
requireActivity(),
currentPackage,
purchaseErrorCallback,
successfulPurchaseCallback,
)
}

private fun toggleLoadingIndicator(isLoading: Boolean) {
binding.purchaseProgress.visibility = if (isLoading) View.VISIBLE else View.GONE
}

private fun showOldSubIdPicker(callback: (String?) -> Unit) {
// Removes base plan id to get the sub id
val activeSubIds = activeSubscriptions.map { it.split(":").first() }
if (activeSubIds.isEmpty()) {
Toast.makeText(
requireContext(),
"Cannot upgrade without an existing active subscription.",
Toast.LENGTH_LONG,
).show()
toggleLoadingIndicator(false)
callback(null)
return
}

var selectedUpgradeSubId: String = activeSubIds[0]
MaterialAlertDialogBuilder(requireContext())
.setTitle("Choose which active sub to switch from")
.setSingleChoiceItems(activeSubIds.toTypedArray(), 0) { _, which ->
selectedUpgradeSubId = activeSubIds[which]
}
.setPositiveButton("Continue") { dialog, _ ->
dialog.dismiss()
callback(selectedUpgradeSubId)
}
.setNegativeButton("Cancel purchase") { dialog, _ ->
dialog.dismiss()
toggleLoadingIndicator(false)
callback(null)
}
.setOnDismissListener {
toggleLoadingIndicator(false)
callback(null)
}
.show()
}

private fun showReplacementModePicker(callback: (GoogleReplacementMode?, Error?) -> Unit) {
val replacementModeOptions = GoogleReplacementMode.values()
var selectedReplacementMode: GoogleReplacementMode? = null

val replacementModeNames = replacementModeOptions.map { it.name }.toTypedArray()
MaterialAlertDialogBuilder(requireContext())
.setTitle("Choose ReplacementMode")
.setSingleChoiceItems(replacementModeNames, -1) { _, selectedIndex ->
selectedReplacementMode = replacementModeOptions.elementAt(selectedIndex)
}
.setPositiveButton("Start purchase") { dialog, _ ->
dialog.dismiss()
callback(selectedReplacementMode, null)
}
.setNegativeButton("Cancel purchase") { dialog, _ ->
dialog.dismiss()
toggleLoadingIndicator(false)
callback(null, Error("Purchase cancelled"))
}
.setOnDismissListener {
toggleLoadingIndicator(false)
callback(null, Error("Selection dismissed"))
}
.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.revenuecat.purchasetester
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.revenuecat.purchases.Package
import com.revenuecat.purchases.PackageType
Expand Down Expand Up @@ -38,12 +39,13 @@ class DeprecatedPackageCardAdapter(
binding.currentPackage = currentPackage
binding.isSubscription = product.type == ProductType.SUBS
binding.isActive = activeSubscriptions.contains(product.id)
// Upgrades are no longer possible with deprecated methods.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I think it might make sense to just remove these deprecated classes now... I believe it was mostly used to test during the migration to the new ReplacementMode, but I think it wouldn't be very useful now... But this can also happen separately.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright! My vote would be to do it separately indeed, to avoid this PR from creeping up in scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also quicker v8 beta 🚀 😄

binding.isUpgradeCheckbox.isVisible = false

binding.packageBuyButton.setOnClickListener {
listener.onPurchasePackageClicked(
binding.root,
currentPackage,
binding.isUpgradeCheckbox.isChecked,
)
}

Expand All @@ -53,7 +55,6 @@ class DeprecatedPackageCardAdapter(
listener.onPurchaseProductClicked(
binding.root,
product,
binding.isUpgradeCheckbox.isChecked,
)
}
binding.productBuyButton.text = "Buy product (deprecated)"
Expand Down Expand Up @@ -82,12 +83,10 @@ class DeprecatedPackageCardAdapter(
fun onPurchasePackageClicked(
cardView: View,
currentPackage: Package,
isUpgrade: Boolean,
)
fun onPurchaseProductClicked(
cardView: View,
currentProduct: StoreProduct,
isUpgrade: Boolean,
)
}
}
Loading