-
Notifications
You must be signed in to change notification settings - Fork 949
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BillingClientWrapper (#4253)
<!-- Note: This checklist is a reminder of our shared engineering expectations. The items in Bold are required If your PR involves UI changes: 1. Upload screenshots or screencasts that illustrate the changes before / after 2. Add them under the UI changes section (feel free to add more columns if needed) If your PR does not involve UI changes, you can remove the **UI changes** section At a minimum, make sure your changes are tested in API 23 and one of the more recent API levels available. --> Task/Issue URL: https://app.asana.com/0/1205648422731273/1206760049330313/f ### Description See task. ### No UI changes
- Loading branch information
Showing
10 changed files
with
694 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...ions-impl/src/main/java/com/duckduckgo/subscriptions/impl/billing/BillingClientAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2024 DuckDuckGo | ||
* | ||
* 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.duckduckgo.subscriptions.impl.billing | ||
|
||
import android.app.Activity | ||
import com.android.billingclient.api.ProductDetails | ||
import com.android.billingclient.api.PurchaseHistoryRecord | ||
|
||
interface BillingClientAdapter { | ||
val ready: Boolean | ||
|
||
suspend fun connect( | ||
purchasesListener: (PurchasesUpdateResult) -> Unit, | ||
disconnectionListener: () -> Unit, | ||
): BillingInitResult | ||
|
||
suspend fun getSubscriptions(productIds: List<String>): SubscriptionsResult | ||
|
||
suspend fun getSubscriptionsPurchaseHistory(): SubscriptionsPurchaseHistoryResult | ||
|
||
suspend fun launchBillingFlow( | ||
activity: Activity, | ||
productDetails: ProductDetails, | ||
offerToken: String, | ||
externalId: String, | ||
): LaunchBillingFlowResult | ||
} | ||
|
||
sealed class BillingInitResult { | ||
data object Success : BillingInitResult() | ||
data object Failure : BillingInitResult() | ||
} | ||
|
||
sealed class SubscriptionsResult { | ||
data class Success(val products: List<ProductDetails>) : SubscriptionsResult() | ||
|
||
data class Failure( | ||
val billingResponseCode: Int? = null, | ||
val debugMessage: String? = null, | ||
) : SubscriptionsResult() | ||
} | ||
|
||
sealed class SubscriptionsPurchaseHistoryResult { | ||
data class Success(val history: List<PurchaseHistoryRecord>) : SubscriptionsPurchaseHistoryResult() | ||
data object Failure : SubscriptionsPurchaseHistoryResult() | ||
} | ||
|
||
sealed class LaunchBillingFlowResult { | ||
data object Success : LaunchBillingFlowResult() | ||
data object Failure : LaunchBillingFlowResult() | ||
} | ||
|
||
sealed class PurchasesUpdateResult { | ||
data class PurchasePresent( | ||
val purchaseToken: String, | ||
val packageName: String, | ||
) : PurchasesUpdateResult() | ||
|
||
data object PurchaseAbsent : PurchasesUpdateResult() | ||
data object UserCancelled : PurchasesUpdateResult() | ||
data object Failure : PurchasesUpdateResult() | ||
} |
Oops, something went wrong.