This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e20d133
commit ee7da17
Showing
19 changed files
with
164 additions
and
22 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
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
48 changes: 48 additions & 0 deletions
48
...rc/main/java/caios/android/fanbox/core/billing/usecase/PurchasePlusSubscriptionUseCase.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,48 @@ | ||
package caios.android.fanbox.core.billing.usecase | ||
|
||
import android.app.Activity | ||
import caios.android.fanbox.core.billing.AcknowledgeResult | ||
import caios.android.fanbox.core.billing.BillingClient | ||
import caios.android.fanbox.core.billing.models.ProductDetails | ||
import caios.android.fanbox.core.billing.models.ProductItem | ||
import caios.android.fanbox.core.billing.models.ProductType | ||
import caios.android.fanbox.core.billing.purchaseSingle | ||
import com.android.billingclient.api.Purchase | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class PurchasePlusSubscriptionUseCase( | ||
private val billingClient: BillingClient, | ||
private val mainDispatcher: CoroutineDispatcher, | ||
) { | ||
@Inject | ||
constructor(billingClient: BillingClient) : this( | ||
billingClient = billingClient, | ||
mainDispatcher = Dispatchers.Main, | ||
) | ||
|
||
suspend fun execute(activity: Activity): PurchaseConsumableResult { | ||
val productDetails = billingClient.queryProductDetails(ProductItem.plusSubscription, ProductType.SUBS) | ||
val purchaseResult = purchase(activity, productDetails) | ||
|
||
acknowledge(purchaseResult.purchase) | ||
|
||
return purchaseResult | ||
} | ||
|
||
private suspend fun purchase( | ||
activity: Activity, | ||
productDetails: ProductDetails, | ||
): PurchaseConsumableResult = withContext(mainDispatcher) { | ||
val command = purchaseSingle(productDetails, null) | ||
val result = billingClient.launchBillingFlow(activity, command) | ||
|
||
PurchaseConsumableResult(command, productDetails, result.billingPurchase) | ||
} | ||
|
||
private suspend fun acknowledge(purchase: Purchase): AcknowledgeResult { | ||
return billingClient.acknowledgePurchase(purchase) | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.