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

Fix/remove dependency from debug sourceset #8147

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -4,7 +4,7 @@ import android.app.Application
import com.woocommerce.android.iap.pub.IAPSitePurchasePlanFactory
import com.woocommerce.android.iap.pub.PurchaseWPComPlanActions
import com.woocommerce.android.iap.pub.PurchaseWpComPlanSupportChecker
import com.woocommerce.android.iapshowcase.purchase.IAPShowcaseMobilePayAPIProvider
import com.woocommerce.android.ui.login.storecreation.iap.IapMobilePayApiProvider
import com.woocommerce.android.ui.login.storecreation.iap.WooIapLogWrapper
import dagger.Module
import dagger.Provides
Expand All @@ -19,7 +19,7 @@ class InAppPurchasesModule {
@Provides
fun providePurchaseWPComPlanActions(
context: Application,
mobilePayAPIProvider: IAPShowcaseMobilePayAPIProvider
mobilePayAPIProvider: IapMobilePayApiProvider
): PurchaseWPComPlanActions =
IAPSitePurchasePlanFactory.createIAPSitePurchasePlan(
context,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.woocommerce.android.ui.login.storecreation.iap

import com.woocommerce.android.iap.pub.network.IAPMobilePayAPI
import com.woocommerce.android.iap.pub.network.model.CreateAndConfirmOrderResponse
import org.wordpress.android.fluxc.network.rest.wpcom.mobilepay.MobilePayRestClient
import org.wordpress.android.fluxc.store.MobilePayStore
import javax.inject.Inject

/**
* This class provides a default implementation of IAPMobilePayAPI for store creation flow. It duplicates
* code from IAPShowcaseMobilePayAPIProvider. We should double check if we need this duplication to remove
* one of the files and move the other to the correct package.
* Github issue: https://github.com/woocommerce/woocommerce-android/issues/8148
*/
class IapMobilePayApiProvider @Inject constructor(private val mobilePayStore: MobilePayStore) {
fun buildMobilePayAPI(customUrl: String?) = object : IAPMobilePayAPI {
override suspend fun createAndConfirmOrder(
remoteSiteId: Long,
productIdentifier: String,
priceInCents: Int,
currency: String,
purchaseToken: String,
appId: String
): CreateAndConfirmOrderResponse {
val response = mobilePayStore.createOrder(
productIdentifier,
priceInCents,
currency,
purchaseToken,
appId,
remoteSiteId,
customUrl = customUrl
)
return when (response) {
is MobilePayRestClient.CreateOrderResponse.Success -> {
CreateAndConfirmOrderResponse.Success(response.orderId)
}
is MobilePayRestClient.CreateOrderResponse.Error -> {
when (response.type) {
MobilePayRestClient.CreateOrderErrorType.API_ERROR,
MobilePayRestClient.CreateOrderErrorType.AUTH_ERROR,
MobilePayRestClient.CreateOrderErrorType.GENERIC_ERROR,
MobilePayRestClient.CreateOrderErrorType.INVALID_RESPONSE ->
CreateAndConfirmOrderResponse.Server(response.message ?: "Reason is not provided")
MobilePayRestClient.CreateOrderErrorType.TIMEOUT -> CreateAndConfirmOrderResponse.Network
}
}
}
}
}
}