Skip to content

Commit

Permalink
Check Google Play service is available, if not fallback (#1128)
Browse files Browse the repository at this point in the history
* check if play service is not found fallback to custom checkout.

* Change proxy and other small changes.
  • Loading branch information
jigar-f authored Jul 25, 2024
1 parent 94627cb commit c4aa50d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 30 deletions.
3 changes: 3 additions & 0 deletions android/app/src/main/kotlin/io/lantern/model/SessionModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ class SessionModel(
LanternApp.getSession().setLanguage(call.argument("lang"))
fetchPaymentMethods(result)
}
"isPlayServiceAvailable" -> {
result.success(LanternApp.getInAppBilling().isPlayStoreAvailable())
}

else -> super.doOnMethodCall(call, result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class InAppBilling(
@Volatile
private var billingClient: BillingClient? = null

private var billingResult: BillingResult? = null

private val skus: ConcurrentHashMap<String, ProductDetails> = ConcurrentHashMap()
private val handler = Handler(Looper.getMainLooper())

Expand All @@ -54,6 +56,15 @@ class InAppBilling(
@Volatile
private var purchasesUpdated: PurchasesUpdatedListener? = null


fun isPlayStoreAvailable(): Boolean {
if (billingResult != null) {
return billingResult!!.responseCodeOK()
}
return false

}

override fun initConnection() {
if (googleApiAvailability.isGooglePlayServicesAvailable(context)
!= ConnectionResult.SUCCESS
Expand All @@ -70,7 +81,8 @@ class InAppBilling(
it.startConnection(
object : BillingClientStateListener {
override fun onBillingSetupFinished(billingResult: BillingResult) {
// The BillingClient is ready. You can query purchases here.

this@InAppBilling.billingResult = billingResult
val responseCode = billingResult.responseCode
Logger.d(TAG, "onBillingSetupFinished with response code: $responseCode")
if (billingResult.responseCodeOK()) {
Expand Down
2 changes: 1 addition & 1 deletion desktop/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func start() {
settings := loadSettings(cdir)
webclientOpts := &webclient.Opts{
HttpClient: &http.Client{
Transport: proxied.ParallelPreferChained(),
Transport: proxied.ChainedThenFronted(),
Timeout: 30 * time.Second,
},
UserConfig: func() common.UserConfig {
Expand Down
49 changes: 25 additions & 24 deletions lib/account/account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ class _AccountMenuState extends State<AccountMenu> {
).show(context);
}

void onAccountManagementTap(
BuildContext context, bool isProUser, bool hasUserLoggedIn) {
if(Platform.isAndroid){
void onAccountManagementTap(BuildContext context, bool isProUser,
bool hasUserLoggedIn) {
if (Platform.isAndroid) {
context.pushRoute(AccountManagement(isPro: isProUser));
return;
}
if (hasUserLoggedIn) {
// User has gone through onboarding
Expand Down Expand Up @@ -97,26 +98,26 @@ class _AccountMenuState extends State<AccountMenu> {
),
if (Platform.isAndroid)
messagingModel.getOnBoardingStatus(
(context, hasBeenOnboarded, child) => hasBeenOnboarded == true
(context, hasBeenOnboarded, child) =>
hasBeenOnboarded == true
? messagingModel.getCopiedRecoveryStatus(
(
BuildContext context,
bool hasCopiedRecoveryKey,
Widget? child,
) =>
ListItemFactory.settingsItem(
icon: ImagePaths.account,
content: 'account_management'.i18n,
onTap: () async => await context
.pushRoute(AccountManagement(isPro: false)),
trailingArray: [
if (!hasCopiedRecoveryKey)
const CAssetImage(
path: ImagePaths.badge,
),
],
),
)
(BuildContext context,
bool hasCopiedRecoveryKey,
Widget? child,) =>
ListItemFactory.settingsItem(
icon: ImagePaths.account,
content: 'account_management'.i18n,
onTap: () async =>
await context
.pushRoute(AccountManagement(isPro: false)),
trailingArray: [
if (!hasCopiedRecoveryKey)
const CAssetImage(
path: ImagePaths.badge,
),
],
),
)
: const SizedBox(),
),
ListItemFactory.settingsItem(
Expand Down Expand Up @@ -146,9 +147,9 @@ class _AccountMenuState extends State<AccountMenu> {
List<Widget> proItems(BuildContext context, bool hasUserLoggedIn) {
return [
messagingModel.getOnBoardingStatus(
(context, hasBeenOnboarded, child) =>
(context, hasBeenOnboarded, child) =>
messagingModel.getCopiedRecoveryStatus((BuildContext context,
bool hasCopiedRecoveryKey, Widget? child) =>
bool hasCopiedRecoveryKey, Widget? child) =>
ListItemFactory.settingsItem(
key: AppKeys.account_management,
icon: ImagePaths.account,
Expand Down
2 changes: 1 addition & 1 deletion lib/common/app_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension ErrorX on Object {
if (description.contains("error while sign up")) {
return "signup_error".i18n;
} else {
return description.i18n;
return 'we_are_experiencing_technical_difficulties'.i18n;
}
} else {
return toString().i18n;
Expand Down
5 changes: 5 additions & 0 deletions lib/common/session_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,11 @@ class SessionModel extends Model {
}).then((value) => value as String);
}

Future<bool> isGooglePlayServiceAvailable() async {
final result = await methodChannel.invokeMethod('isPlayServiceAvailable');
return result as bool;
}

Future<void> submitPlayPayment(
String planID,
String email,
Expand Down
9 changes: 6 additions & 3 deletions lib/plans/plan_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class _PlanCardState extends State<PlanCard> {
CText(
planName == '1y'
? 'one_year_plan'.i18n
: (planName == '1m' ? 'one_month_plan'.i18n : 'two_year_plan'.i18n),
: (planName == '1m'
? 'one_month_plan'.i18n
: 'two_year_plan'.i18n),
style: tsSubtitle2.copiedWith(
color: pink3,
fontWeight: FontWeight.w500,
Expand Down Expand Up @@ -160,8 +162,9 @@ class _PlanCardState extends State<PlanCard> {
Future<void> _processCheckOut(BuildContext context) async {
final isPlayVersion = sessionModel.isPlayVersion.value ?? false;
final inRussia = sessionModel.country.value == 'RU';
// * Play version (Android only)
if (isPlayVersion && !inRussia) {
// check if google play payment is available
final isGooglePlayAvailable = await sessionModel.isGooglePlayServiceAvailable();
if (isPlayVersion && !inRussia && isGooglePlayAvailable) {
await context.pushRoute(
PlayCheckout(
plan: widget.plan,
Expand Down

0 comments on commit c4aa50d

Please sign in to comment.