-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8147 from woocommerce/fix/remove-dependency-from-…
…debug-sourceset Fix/remove dependency from debug sourceset
- Loading branch information
Showing
2 changed files
with
53 additions
and
2 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
51 changes: 51 additions & 0 deletions
51
...main/kotlin/com/woocommerce/android/ui/login/storecreation/iap/IapMobilePayApiProvider.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,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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |