diff --git a/README.md b/README.md index 9ee7c39..4f5b555 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,60 @@ HyperSdkReact.isInitialised().then((init: boolean) => { }); ``` +### 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.hypersdkreact.HyperSdkReactModule +import `in`.juspay.hypersdk.core.JuspayWebViewConfigurationCallback + + +HyperSdkReactModule.setWebViewConfigurationCallback( + JuspayWebViewConfigurationCallback { webView -> + + } +) +``` + +**Java:** + +```java +import in.juspay.hypersdkreact.HyperSdkReactModule; + + +HyperSdkReactModule.setWebViewConfigurationCallback(webView -> { + +}); +``` + +#### iOS + +**Swift:** + +```swift +import hyper_sdk_react + + +HyperSdkReact.setJuspayWebViewConfigurationCallback { webView in + +} +``` + +**Objective-C:** + +```objective-c +#import "HyperSdkReact.h" + +[HyperSdkReact setJuspayWebViewConfigurationCallback:^(WKWebView * _Nonnull webView) { + +}]; +``` + ### Optional: Update Base ViewController - Only for iOS This is an optional method to update the base view controller in case if any new view controller is presented over top view controller after the SDK initiation. This method should be called before making `HyperSdkReact.process()` call. diff --git a/android/src/main/java/in/juspay/hypersdkreact/HyperSdkReactModule.java b/android/src/main/java/in/juspay/hypersdkreact/HyperSdkReactModule.java index 39a0073..4311d99 100644 --- a/android/src/main/java/in/juspay/hypersdkreact/HyperSdkReactModule.java +++ b/android/src/main/java/in/juspay/hypersdkreact/HyperSdkReactModule.java @@ -47,6 +47,7 @@ import java.util.Set; import in.juspay.hypercheckoutlite.HyperCheckoutLite; +import in.juspay.hypersdk.core.JuspayWebViewConfigurationCallback; import in.juspay.hypersdk.core.MerchantViewType; import in.juspay.hypersdk.core.SdkTracker; import in.juspay.hypersdk.data.JuspayResponseHandler; @@ -89,6 +90,18 @@ public class HyperSdkReactModule extends ReactContextBaseJavaModule implements A private static WeakReference hyperServicesReference = new WeakReference<>(null); + @Nullable + private static JuspayWebViewConfigurationCallback webViewConfigurationCallback = null; + + /** + * Sets the WebView configuration callback used by HyperSDK. Merchants can use this to + * customise the {@link android.webkit.WebView} created by the SDK (for example, to enable + * Minkasu SDK access). Must be called before {@code process} to take effect. + */ + public static void setWebViewConfigurationCallback(@Nullable JuspayWebViewConfigurationCallback callback) { + webViewConfigurationCallback = callback; + } + private final ReactApplicationContext context; private boolean wasProcessWithActivity = false; @@ -592,6 +605,9 @@ private void process(HyperServices hyperService, String data) { } hyperService.setActivityLaunchDelegate(new ReactLaunchDelegate(context)); hyperService.setRequestPermissionDelegate(new ReactRequestDelegate(activity)); + if (webViewConfigurationCallback != null) { + hyperService.setWebViewConfigurationCallback(webViewConfigurationCallback); + } hyperService.process(activity, payload); } catch (JSONException e) { @@ -650,6 +666,9 @@ public void onCreated(@NonNull FragmentActivity fragmentActivity) { wasProcessWithActivity = true; processActivityRef = new WeakReference<>(fragmentActivity); + if (webViewConfigurationCallback != null) { + hyperService.setWebViewConfigurationCallback(webViewConfigurationCallback); + } hyperService.process(fragmentActivity, payload); } diff --git a/ios/HyperSdkReact.h b/ios/HyperSdkReact.h index 774a442..85ed695 100644 --- a/ios/HyperSdkReact.h +++ b/ios/HyperSdkReact.h @@ -12,6 +12,9 @@ #import #import #import +#import + +typedef void (^JuspayWebViewConfigurationCallback)(WKWebView *webView); @interface HyperSdkReact : RCTEventEmitter @@ -21,6 +24,9 @@ @property (nonatomic, strong) NSMutableDictionary *hyperDelegatesDict; @property (nonatomic, strong) NSMutableSet *knownEventKeys; ++ (void)setJuspayWebViewConfigurationCallback:(JuspayWebViewConfigurationCallback)callback; ++ (nullable JuspayWebViewConfigurationCallback)juspayWebViewConfigurationCallback; + @end @protocol HyperSdkReactDelegate diff --git a/ios/HyperSdkReact.mm b/ios/HyperSdkReact.mm index a3e1e52..8ec4aa9 100644 --- a/ios/HyperSdkReact.mm +++ b/ios/HyperSdkReact.mm @@ -204,12 +204,26 @@ - (UIView * _Nullable)merchantViewForViewType:(NSString * _Nonnull)viewType { } - (void) onWebViewReady:(WKWebView *)webView { - //Ignored + JuspayWebViewConfigurationCallback callback = [HyperSdkReact juspayWebViewConfigurationCallback]; + if (callback) { + callback(webView); + } } @end @implementation HyperSdkReact + +static JuspayWebViewConfigurationCallback _juspayWebViewConfigurationCallback = nil; + ++ (void)setJuspayWebViewConfigurationCallback:(JuspayWebViewConfigurationCallback)callback { + _juspayWebViewConfigurationCallback = [callback copy]; +} + ++ (nullable JuspayWebViewConfigurationCallback)juspayWebViewConfigurationCallback { + return _juspayWebViewConfigurationCallback; +} + RCT_EXPORT_MODULE() NSString *HYPER_EVENT = @"HyperEvent";