Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added webview configuration callback for minkasu support #54

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 59 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,63 @@ 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

**Kotlin:**

```kotlin
import `in`.juspay.hyper_sdk_flutter.HyperSdkFlutterPlugin
import `in`.juspay.hypersdk.core.JuspayWebViewConfigurationCallback


HyperSdkFlutterPlugin.webViewConfigurationCallback =
JuspayWebViewConfigurationCallback { webview ->

}
```

**Java:**

```java
import in.juspay.hyper_sdk_flutter.HyperSdkFlutterPlugin;


HyperSdkFlutterPlugin.setWebViewConfigurationCallback(webView -> {

});
```

#### iOS

**Swift:**

```swift
import hypersdkflutter


SwiftHyperSdkFlutterPlugin.setJuspayWebViewConfigurationCallback { webView in

}
```

**Objective-C:**

```objective-c
#if __has_include(<hypersdkflutter/hypersdkflutter-Swift.h>)
#import <hypersdkflutter/hypersdkflutter-Swift.h>
#else
@import hypersdkflutter;
#endif

[SwiftHyperSdkFlutterPlugin setJuspayWebViewConfigurationCallback:^(WKWebView * _Nonnull webview) {

}];
```

## 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() {

}
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PODS:
- HyperSDK (2.2.1.7):
- JuspaySafeBrowser (= 0.1.84)
- Salvator (= 1.0.6)
- hypersdkflutter (4.0.22):
- hypersdkflutter (4.0.24):
- Flutter
- HyperSDK (= 2.2.1.7)
- JuspaySafeBrowser (0.1.84)
Expand Down Expand Up @@ -41,7 +41,7 @@ SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_inappwebview_ios: 97215cf7d4677db55df76782dbd2930c5e1c1ea0
HyperSDK: 761a9a75197097db5fcd96af8f40892109bb0135
hypersdkflutter: 7d7526602b8b8eff585eb59300a3477717da2633
hypersdkflutter: 505d1bec6ee4ff1fc590b24d036a549a76144c70
JuspaySafeBrowser: caa2c1a54405f30210ba9d324cf79224e719134d
OrderedSet: aaeb196f7fef5a9edf55d89760da9176ad40b93c
Salvator: 1de69620ac17123ba3491e27a9a8b35bc5b97eaa
Expand Down
1 change: 1 addition & 0 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<string>ppe</string>
<string>cugext</string>
<string>amazonpay</string>
<string>kiwi</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
Expand Down
17 changes: 16 additions & 1 deletion ios/Classes/SwiftHyperSdkFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ import Flutter
import UIKit
import HyperSDK

public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin {

public typealias JuspayWebViewConfigurationCallback = (WKWebView) -> ()

@objc 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 webViewCallback: JuspayWebViewConfigurationCallback? = nil

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

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

@objc 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 +102,7 @@ public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin {
if let topViewController = (UIApplication.shared.delegate?.window??.rootViewController) {
self.hyperServices.baseViewController = topViewController
self.hyperServices.shouldUseViewController = true
self.hyperServices.hyperDelegate = self
self.hyperServices.process(params)
} else {
result(false)
Expand All @@ -113,6 +127,7 @@ public class SwiftHyperSdkFlutterPlugin: NSObject, FlutterPlugin {
self.hyperServices.shouldUseViewController = false
self.hyperServices.baseView = uiView
self.processedViewId = viewId
self.hyperServices.hyperDelegate = self
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
Loading