You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.8 KiB
Dart
81 lines
2.8 KiB
Dart
import 'dart:convert';
|
|
import 'dart:developer';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
|
import 'package:mc_common_app/classes/consts.dart';
|
|
import 'package:mc_common_app/services/my_in_app_browser.dart';
|
|
import 'package:mc_common_app/utils/utils.dart';
|
|
|
|
abstract class PaymentService {
|
|
Future<void> placeAdPayment({
|
|
required int id,
|
|
required int paymentType,
|
|
required Function() onSuccess,
|
|
required Function() onFailure,
|
|
});
|
|
|
|
Future<void> onBrowserLoadStart({
|
|
required String url,
|
|
required Function() onSuccess,
|
|
required Function() onFailure,
|
|
});
|
|
}
|
|
|
|
class PaymentServiceImp implements PaymentService {
|
|
MyInAppBrowser? myInAppBrowser;
|
|
var inAppBrowserOptions = InAppBrowserClassOptions(
|
|
inAppWebViewGroupOptions:
|
|
InAppWebViewGroupOptions(crossPlatform: InAppWebViewOptions(useShouldOverrideUrlLoading: true, transparentBackground: false), ios: IOSInAppWebViewOptions(applePayAPIEnabled: true)),
|
|
crossPlatform: InAppBrowserOptions(hideUrlBar: true, toolbarTopBackgroundColor: Colors.black),
|
|
android: AndroidInAppBrowserOptions(),
|
|
ios:
|
|
IOSInAppBrowserOptions(hideToolbarBottom: true, toolbarBottomBackgroundColor: Colors.white, closeButtonColor: Colors.white, presentationStyle: IOSUIModalPresentationStyle.OVER_FULL_SCREEN));
|
|
|
|
String generateBrowserUrl(int id) {
|
|
String form = Utils.getAdsPaymentBrowserForm(paymentId: 3, adId: id);
|
|
// form.replaceFirst("SERVICE_URL_VALUE", ApiConsts.paymentWebViewUrl);
|
|
// form.replaceFirst("PaymentType_Value", 4.toString());
|
|
// form.replaceFirst("AdID_Value", id.toString());
|
|
|
|
var bytes = utf8.encode(form);
|
|
var base64Str = base64.encode(bytes);
|
|
return 'data:text/html;base64,$base64Str';
|
|
}
|
|
|
|
@override
|
|
Future<void> placeAdPayment({
|
|
required int id,
|
|
required int paymentType,
|
|
required Function() onSuccess,
|
|
required Function() onFailure,
|
|
}) async {
|
|
myInAppBrowser = MyInAppBrowser(onExitCallback: () {
|
|
log("Browser Exited");
|
|
}, onLoadStartCallback: (String url) {
|
|
log("Browser LoadStart");
|
|
onBrowserLoadStart(onFailure: onFailure, onSuccess: onSuccess, url: url);
|
|
});
|
|
await myInAppBrowser!.openUrlRequest(
|
|
urlRequest: URLRequest(url: Uri.parse("${ApiConsts.paymentWebViewUrl}?PaymentType=$paymentType&AdsID=$id")),
|
|
options: inAppBrowserOptions,
|
|
);
|
|
}
|
|
|
|
@override
|
|
Future<void> onBrowserLoadStart({
|
|
required String url,
|
|
required Function() onSuccess,
|
|
required Function() onFailure,
|
|
}) async {
|
|
for (var element in ApiConsts.closingUrls) {
|
|
if (url.contains(element)) {
|
|
if (myInAppBrowser!.isOpened()) myInAppBrowser!.close();
|
|
onSuccess();
|
|
return;
|
|
}
|
|
// onFailure();
|
|
}
|
|
}
|
|
}
|