Skip to content

Commit

Permalink
Send users directly to web when we do not support Native GPay (#4898)
Browse files Browse the repository at this point in the history
* Share the code

* Move the logic to DonateViewModel

* Add margin to prevent overlapping to the handel

* Tighten up a bit.

* And a bit more.

---------

Co-authored-by: Dmitry Brant <[email protected]>
Co-authored-by: Dmitry Brant <[email protected]>
  • Loading branch information
3 people authored Aug 29, 2024
1 parent 31943c8 commit 37de8f3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
22 changes: 17 additions & 5 deletions app/src/extra/java/org/wikipedia/donate/GooglePayComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ import com.google.android.gms.wallet.IsReadyToPayRequest
import com.google.android.gms.wallet.PaymentsClient
import com.google.android.gms.wallet.Wallet
import com.google.android.gms.wallet.WalletConstants
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.tasks.await
import kotlinx.coroutines.withContext
import org.json.JSONArray
import org.json.JSONObject
import org.wikipedia.dataclient.donate.DonationConfigHelper
import org.wikipedia.settings.Prefs
import org.wikipedia.util.GeoUtil
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.Locale
Expand Down Expand Up @@ -59,11 +63,19 @@ internal object GooglePayComponent {
}

suspend fun isGooglePayAvailable(activity: Activity): Boolean {
val readyToPayRequest = IsReadyToPayRequest.fromJson(googlePayBaseConfiguration.toString())
val paymentsClient = createPaymentsClient(activity)
val readyToPayTask = paymentsClient.isReadyToPay(readyToPayRequest)
readyToPayTask.await()
return readyToPayTask.result
var available: Boolean
withContext(Dispatchers.IO) {
val readyToPayRequest = IsReadyToPayRequest.fromJson(googlePayBaseConfiguration.toString())
val paymentsClient = createPaymentsClient(activity)
val readyToPayTask = paymentsClient.isReadyToPay(readyToPayRequest)
available = readyToPayTask.await()
if (available) {
DonationConfigHelper.getConfig()?.let { config ->
available = config.countryCodeGooglePayEnabled.contains(GeoUtil.geoIPCountry.orEmpty())
}
}
}
return available
}

fun getDonateActivityIntent(activity: Activity, campaignId: String? = null, donateUrl: String? = null): Intent {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/dialog_donate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
android:layout_gravity="center"
android:layout_marginVertical="12dp"/>

<View
android:layout_width="32dp"
Expand Down

0 comments on commit 37de8f3

Please sign in to comment.