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

fix: added openPaymentPage in iOS plugin #83

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ buildscript {
ext {
....
clientId = "<clientId shared by Juspay team>"
hyperSDKVersion = "2.1.25"
hyperSDKVersion = "2.1.33"
....
}
....
Expand Down Expand Up @@ -55,7 +55,7 @@ pod install
"devDependencies": {
....
},
"hyperSdkIOSVersion": "2.1.39"
"hyperSdkIOSVersion": "2.2.2"
....
}
```
Expand All @@ -64,7 +64,7 @@ Note: This version is just for explanatory purposes and may change in future. Co

#### **Dynamic Assets iOS**

Change the `hyperSdkIOSVersion` to `2.1.39` (This version is just for explanatory purposes and may change in future. Contact Juspay support team for the latest SDK version).
Change the `hyperSdkIOSVersion` to `2.2.2` (This version is just for explanatory purposes and may change in future. Contact Juspay support team for the latest SDK version).

Add below post_install script in the Podfile

Expand Down
4 changes: 4 additions & 0 deletions example/ios/HyperSdkReactExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<string>ppe</string>
<string>amazonpay</string>
<string>cugext</string>
<string>kiwi</string>
<string>navipay</string>
<string>mobikwik</string>
<string>tatadigital</string>
</array>
<key>LSRequiresIPhoneOS</key>
<true/>
Expand Down
4 changes: 4 additions & 0 deletions example/ios/HyperSdkReactExampleTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<string>ppe</string>
<string>amazonpay</string>
<string>cugext</string>
<string>kiwi</string>
<string>navipay</string>
<string>mobikwik</string>
<string>tatadigital</string>
</array>
</dict>
</plist>
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ PODS:
- hermes-engine (0.72.15):
- hermes-engine/Pre-built (= 0.72.15)
- hermes-engine/Pre-built (0.72.15)
- hyper-sdk-react (3.0.39):
- HyperSDK (= 2.2.1.4)
- hyper-sdk-react (3.0.41):
- HyperSDK (= 2.2.2)
- React-Core
- HyperSDK (2.2.1.4):
- HyperSDK (2.2.2):
- JuspaySafeBrowser (= 0.1.84)
- Salvator (= 1.0.6)
- JuspaySafeBrowser (0.1.84)
Expand Down Expand Up @@ -715,8 +715,8 @@ SPEC CHECKSUMS:
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: 5b340c6a5affbf3aba22185be41563bbb2426654
hyper-sdk-react: 600f3fe60c3010e5218ec28405796a5abaa02a49
HyperSDK: 5ea42ab6795ea239d449d1803e72968521cce198
hyper-sdk-react: 50ca138c0003e944a47e4f12f1f8a42566f4f640
HyperSDK: 653f618de09696305b9b705555019ecbbacc10b0
JuspaySafeBrowser: caa2c1a54405f30210ba9d324cf79224e719134d
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Expand Down Expand Up @@ -764,4 +764,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 9d75834eee1caf39c2287e0b86b419d59ce7fbd1

COCOAPODS: 1.15.2
COCOAPODS: 1.16.2
2 changes: 1 addition & 1 deletion hyper-sdk-react.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "json"
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

hyper_sdk_version = "2.2.1.4"
hyper_sdk_version = "2.2.2"

begin
package_json_path = File.expand_path(File.join(__dir__, "../../package.json"))
Expand Down
55 changes: 42 additions & 13 deletions ios/HyperSdkReact.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ -(void)didMoveToSuperview {
if (self.trailing.isActive) {
self.trailing.active = @NO;
}

//Checking superview just to be sure that it is not nil
if(self.superview) {
// Create contraints to replicate wrapcontent
Expand Down Expand Up @@ -72,12 +72,12 @@ - (void) setHeight: (NSNumber*)height forTag: (NSString * _Nonnull)tag {
// Update the latest value of the height holder for the given tag
// This will be used to set the height of view if view is created at a later point
[self.heightHolder setObject: height forKey:tag];

// Fetch previous height constraint so that it can be set to inactive
NSLayoutConstraint *heightConstraint = [self.heightConstraintHolder objectForKey:tag];
// Fetch rootview to update set constraints if view is already created
UIView *rootView = [self.rootHolder objectForKey:tag];

// Check if view is already present
if (rootView && [rootView isKindOfClass: [UIView class]]) {
// If present set earlier constraint to inactive
Expand All @@ -98,7 +98,7 @@ - (void) setHeight: (NSNumber*)height forTag: (NSString * _Nonnull)tag {
Use bridge to share the same JS VM
*/
- (UIView * _Nullable)merchantViewForViewType:(NSString * _Nonnull)viewType {

// Create a SDKRootView so that we can attach width constraints once it is attached to it's parent
RCTRootView *rrv = [SDKRootView alloc];
NSString *moduleName = @"JP_003";
Expand All @@ -111,23 +111,23 @@ - (UIView * _Nullable)merchantViewForViewType:(NSString * _Nonnull)viewType {
} else if ([viewType isEqual:@"FOOTER_ATTACHED"] && [registeredComponents containsObject:@"JuspayFooterAttached"]) {
moduleName = @"JuspayFooterAttached";
}

// Save a reference of the react root view
// This will be used to update height constraint if a newer value is sent by the merchant
[self.rootHolder setObject:rrv forKey:moduleName];


rrv = [rrv initWithBridge: self.bridge
moduleName:moduleName
initialProperties:nil
];

// Remove background colour. Default colour white is getting applied to the merchant view
rrv.backgroundColor = UIColor.clearColor ;

// Remove height 0, width 0 constraints added by default.
rrv.translatesAutoresizingMaskIntoConstraints = false;

// If height is available set the height
NSNumber *height = [self.heightHolder objectForKey:moduleName];
if (height && [height isKindOfClass:[NSNumber class]]) {
Expand Down Expand Up @@ -193,7 +193,7 @@ -(void)stopObserving {
if (jsonData && [jsonData isKindOfClass:[NSDictionary class]] && jsonData.allKeys.count>0) {
[HyperServices preFetch:jsonData];
} else {

}
} @catch (NSException *exception) {
//Parsing failure.
Expand All @@ -213,7 +213,7 @@ -(void)stopObserving {
@try {
NSDictionary *jsonData = [HyperSdkReact stringToDictionary:data];
if (jsonData && [jsonData isKindOfClass:[NSDictionary class]] && jsonData.allKeys.count>0) {

UIViewController *baseViewController = RCTPresentedViewController();
__weak HyperSdkReact *weakSelf = self;
self.delegate = [[SdkDelegate alloc] initWithBridge:self.bridge];
Expand Down Expand Up @@ -267,6 +267,35 @@ -(void)stopObserving {
}
}

RCT_EXPORT_METHOD(openPaymentPage:(NSString *)data) {
if (data && data.length>0) {
@try {
NSDictionary *sdkPayload = [HyperSdkReact stringToDictionary:data];
// Update baseViewController if it's nil or not in the view hierarchy.
if (sdkPayload && [sdkPayload isKindOfClass:[NSDictionary class]] && sdkPayload.allKeys.count>0) {

id baseViewController = RCTPresentedViewController();

__weak HyperSdkReact *weakSelf = self;
self.delegate = [[SdkDelegate alloc] initWithBridge:self.bridge];
[_hyperInstance setHyperDelegate: _delegate];
[HyperCheckoutLite openPaymentPage:baseViewController payload:sdkPayload callback:^(NSDictionary<NSString *,id> * _Nullable data) {
[weakSelf sendEventWithName:@"HyperEvent" body:[[self class] dictionaryToString:data]];
}];
} else {
// Define proper error code and return proper error
// [self sendEventWithName:@"HyperEvent" body:[[self class] dictionaryToString:data]];
}
} @catch (NSException *exception) {
// Define proper error code and return proper error
// [self sendEventWithName:@"HyperEvent" body:[[self class] dictionaryToString:data]];
}
} else {
// Define proper error code and return proper error
// [self sendEventWithName:@"HyperEvent" body:[[self class] dictionaryToString:data]];
}
}

RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isNull) {
return self.hyperInstance == NULL? @true : @false;
}
Expand Down Expand Up @@ -375,7 +404,7 @@ - (UIView *)view
- (void)manuallyLayoutChildren:(UIView *)view {
UIView *parent = view.superview;
if (!parent) return;

view.frame = parent.bounds;
}

Expand Down
Loading