Skip to content

Commit

Permalink
Merge pull request #8147 from woocommerce/fix/remove-dependency-from-…
Browse files Browse the repository at this point in the history
…debug-sourceset

Fix/remove dependency from debug sourceset
  • Loading branch information
ParaskP7 authored Jan 9, 2023
2 parents 9144ea4 + 6bb0a7c commit 2191757
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
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
}
}
}
}
}
}

0 comments on commit 2191757

Please sign in to comment.