Skip to content

Commit

Permalink
feat: added webview configuration callback for minkasu support
Browse files Browse the repository at this point in the history
  • Loading branch information
harshgarg18 committed Nov 13, 2024
1 parent b55fdb9 commit b1a3165
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 8 deletions.
48 changes: 43 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Get dependency from [pub.dev](https://pub.dev/packages/hypersdkflutter/install)
## Android Setup

Add the clientId ext property in root(top) `build.gradle`:

- Override HyperSDK Version by adding hyperSDKVersion - `Optional`
- Exclude microSDKs provided with HyperSDK for given clientId by adding excludedMicroSDKs - `Optional`

Expand All @@ -29,8 +30,6 @@ buildscript {

Optionally, you can also provide an override for base SDK version present in plugin (the newer version among both would be considered).



### Note

**Your application's `MainActivity` should extend `FlutterFragmentActivity` instead of `FlutterActivity`.**
Expand All @@ -46,8 +45,6 @@ class MainActivity: FlutterFragmentActivity() {
}
```



## iOS Setup

Add the following post_install script in the Podfile (`ios/Podfile`)
Expand Down Expand Up @@ -128,12 +125,12 @@ await hyperSDK.process(processPayload, hyperSDKCallbackHandler)
This API should be used when Payment Page needs to be rendered within a particular container within the merchant app instead of whole screen.
This is custom view component that returns a StatefulWidget, AndroidView and UiKitView, for android and iOS respectively.
```dart
hyperSDK.hyperSdkView(processPayload, hyperSDKCallbackHandler)
```
You can attach this within a container of your screen like below:
```dart
Container(
color: Colors.white,
Expand Down Expand Up @@ -284,6 +281,47 @@ void hyperSDKCallbackHandler(MethodCall methodCall) {
}
```
### WebView Configuration Callback (Optional)
The Minkasu SDK requires access to the bank WebView SDK. This can be enabled after whitelisting on Juspay end. Below is a reference to changes required post getting SDK whitelisted. This should be called before calling process.
#### Android
Java:
```java
import in.juspay.hyper_sdk_flutter.HyperSdkFlutterPlugin;
HyperSdkFlutterPlugin.setWebViewConfigurationCallback(webView -> {
});
```
Kotlin:
```kotlin
import `in`.juspay.hyper_sdk_flutter.HyperSdkFlutterPlugin
import `in`.juspay.hypersdk.core.JuspayWebViewConfigurationCallback
HyperSdkFlutterPlugin.webViewConfigurationCallback =
JuspayWebViewConfigurationCallback { webview ->
}
```
#### iOS
```swift
import hypersdkflutter
SwiftHyperSdkFlutterPlugin.setJuspayWebViewConfigurationCallback { webView in
}
```
## Payload Structure
Payload type is `Map<String,Dynamic>`
Expand Down
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ linter:
- throw_in_finally
- unawaited_futures
- unnecessary_brace_in_string_interps
- public_member_api_docs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.util.Log
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import `in`.juspay.hypercheckoutlite.HyperCheckoutLite
import `in`.juspay.hypersdk.core.JuspayWebViewConfigurationCallback
import `in`.juspay.hypersdk.data.JuspayResponseHandler
import `in`.juspay.hypersdk.ui.HyperPaymentsCallbackAdapter
import `in`.juspay.services.HyperServices
Expand Down Expand Up @@ -193,6 +194,7 @@ class HyperSdkFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
result.success(false)
return
}
webViewConfigurationCallback?.let { hyperServices.setWebViewConfigurationCallback(it) }
hyperServices.process(JSONObject(params))
result.success(true)
}
Expand All @@ -207,6 +209,7 @@ class HyperSdkFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
?: return result.success(false)
val view = id?.let { (activity as Activity).findViewById<ViewGroup>(it) }
?: return result.success(false)
webViewConfigurationCallback?.let { hyperServices.setWebViewConfigurationCallback(it) }
hyperServices.process(activity, view, JSONObject(params))
result.success(true)
}
Expand Down Expand Up @@ -264,4 +267,9 @@ class HyperSdkFlutterPlugin : FlutterPlugin, MethodCallHandler, ActivityAware,
result.success(false)
}
}

companion object {
@JvmStatic
var webViewConfigurationCallback: JuspayWebViewConfigurationCallback? = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* This source code is licensed under the AGPL 3.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.example.demo_app

import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity : FlutterFragmentActivity() {

}
22 changes: 21 additions & 1 deletion ios/Classes/SwiftHyperSdkFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import Flutter
import UIKit
import HyperSDK

public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin {

public typealias JuspayWebViewConfigurationCallback = (WKWebView) -> ()

public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin, HyperDelegate {

private static var CHANNEL_NAME = "hyperSDK"
private let juspay: FlutterMethodChannel
private lazy var hyperServices: HyperServices = {
return HyperServices()
}()
private var processedViewId: Int = -1
private let hyperViewController = UIViewController()
private static var hyperDelegate: HyperDelegate? = nil
private static var webViewCallback: JuspayWebViewConfigurationCallback? = nil

init(_ channel: FlutterMethodChannel, _ registrar: FlutterPluginRegistrar) {
juspay = channel
Expand All @@ -30,6 +36,14 @@ public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin {
registrar.register(factory, withId: "HyperSdkViewGroup")
}

public func onWebViewReady(_ webView: WKWebView) {
SwiftHyperSdkFlutterPlugin.webViewCallback?(webView)
}

public static func setJuspayWebViewConfigurationCallback(_ callback: @escaping JuspayWebViewConfigurationCallback) {
self.webViewCallback = callback
}

public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
switch call.method {
case "preFetch":
Expand Down Expand Up @@ -89,6 +103,9 @@ public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin {
if let topViewController = (UIApplication.shared.delegate?.window??.rootViewController) {
self.hyperServices.baseViewController = topViewController
self.hyperServices.shouldUseViewController = true
if let delegate = SwiftHyperSdkFlutterPlugin.hyperDelegate {
self.hyperServices.hyperDelegate = delegate
}
self.hyperServices.process(params)
} else {
result(false)
Expand All @@ -113,6 +130,9 @@ public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin {
self.hyperServices.shouldUseViewController = false
self.hyperServices.baseView = uiView
self.processedViewId = viewId
if let delegate = SwiftHyperSdkFlutterPlugin.hyperDelegate {
self.hyperServices.hyperDelegate = delegate
}
self.hyperServices.process(params)
} else {
result(false)
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^4.0.0
lints: ^4.0.0

flutter:
plugin:
Expand Down

0 comments on commit b1a3165

Please sign in to comment.