From 2de580640337a4b0369787e799448448e18869a0 Mon Sep 17 00:00:00 2001 From: AbhinavArora95 Date: Wed, 21 Feb 2018 18:40:42 +0530 Subject: [PATCH 1/3] Flat respons external wallet ios and removed unnecessary step in readme --- example/index.js | 2 +- example/ios/example.xcodeproj/project.pbxproj | 12 ++++++------ example/reload.sh | 5 ----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/example/index.js b/example/index.js index 3643edeb4..c34119963 100644 --- a/example/index.js +++ b/example/index.js @@ -48,7 +48,7 @@ class example extends Component { alert(`Error: ${error.code} | ${error.description}`); }); RazorpayCheckout.onExternalWalletSelection(data => { - alert(`External Wallet Selected: ${data.name} | ${data.details}`); + alert(`External Wallet Selected: ${data.external_wallet} `); }); }}> PAY diff --git a/example/ios/example.xcodeproj/project.pbxproj b/example/ios/example.xcodeproj/project.pbxproj index dc1cb4862..9fdc4daef 100644 --- a/example/ios/example.xcodeproj/project.pbxproj +++ b/example/ios/example.xcodeproj/project.pbxproj @@ -27,7 +27,7 @@ 924876631D8BEAFC002ADD01 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 924876621D8BEAFC002ADD01 /* SystemConfiguration.framework */; }; AD303AA11F9E1C5E009CE9B5 /* Razorpay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 920D7AD01D8BE9E700CA6795 /* Razorpay.framework */; }; AD303AA21F9E1C5E009CE9B5 /* Razorpay.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 920D7AD01D8BE9E700CA6795 /* Razorpay.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - C965BD7112A3425686EC2BCC /* libRazorpayCheckout.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BFD36E0BFFA4163855158DC /* libRazorpayCheckout.a */; }; + E844CC64996F4F1A8718D55C /* libRazorpayCheckout.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 90E62A34DB624C2489848F4D /* libRazorpayCheckout.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -281,8 +281,8 @@ 920D7AD01D8BE9E700CA6795 /* Razorpay.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Razorpay.framework; sourceTree = ""; }; 924876551D8BEAF4002ADD01 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 924876621D8BEAFC002ADD01 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; - 2E6D90F2286843C281E73D59 /* RazorpayCheckout.xcodeproj */ = {isa = PBXFileReference; name = "RazorpayCheckout.xcodeproj"; path = "../node_modules/react-native-razorpay/ios/RazorpayCheckout.xcodeproj"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; }; - 7BFD36E0BFFA4163855158DC /* libRazorpayCheckout.a */ = {isa = PBXFileReference; name = "libRazorpayCheckout.a"; path = "libRazorpayCheckout.a"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; }; + 794F1E83F20C4F04A7988077 /* RazorpayCheckout.xcodeproj */ = {isa = PBXFileReference; name = "RazorpayCheckout.xcodeproj"; path = "../node_modules/react-native-razorpay/ios/RazorpayCheckout.xcodeproj"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; }; + 90E62A34DB624C2489848F4D /* libRazorpayCheckout.a */ = {isa = PBXFileReference; name = "libRazorpayCheckout.a"; path = "libRazorpayCheckout.a"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -312,7 +312,7 @@ 00C302EA1ABCBA2D00DB3ED1 /* libRCTVibration.a in Frameworks */, 139FDEF61B0652A700C62182 /* libRCTWebSocket.a in Frameworks */, 920D7AD11D8BE9E700CA6795 /* Razorpay.framework in Frameworks */, - C965BD7112A3425686EC2BCC /* libRazorpayCheckout.a in Frameworks */, + E844CC64996F4F1A8718D55C /* libRazorpayCheckout.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -453,7 +453,7 @@ 832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */, 00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */, 139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */, - 2E6D90F2286843C281E73D59 /* RazorpayCheckout.xcodeproj */, + 794F1E83F20C4F04A7988077 /* RazorpayCheckout.xcodeproj */, ); name = Libraries; sourceTree = ""; @@ -494,7 +494,7 @@ ADCB1EF61FC3096200A14E91 /* Recovered References */ = { isa = PBXGroup; children = ( - 143EC6054168498F96B6AF47 /* libRazorpayCheckout.a */, + 7BFD36E0BFFA4163855158DC /* libRazorpayCheckout.a */, ); name = "Recovered References"; sourceTree = ""; diff --git a/example/reload.sh b/example/reload.sh index 20cd63087..8206b1cc4 100755 --- a/example/reload.sh +++ b/example/reload.sh @@ -1,11 +1,6 @@ #!/bin/sh ## Run this script after making changes to the module - react-native unlink react-native-razorpay npm uninstall react-native-razorpay npm install react-native link react-native-razorpay -#rm -r ./node_modules/react-native-razorpay/ios/Razorpay.framework -#cp -r ../ios/Razorpay.framework ./node_modules/react-native-razorpay/ios/ -#rm -r ./ios/Razorpay.framework -#cp -r ../ios/Razorpay.framework ./ios/ From 4c37ef7c35fa317867ac78892a5fab972eefa063 Mon Sep 17 00:00:00 2001 From: AbhinavArora95 Date: Thu, 22 Feb 2018 14:19:13 +0530 Subject: [PATCH 2/3] Removed unnecessary step from ios linking steps --- README.md | 27 ------------ ios/RazorpayEventEmitter.m | 88 ++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 797721efb..8215502ea 100644 --- a/README.md +++ b/README.md @@ -32,33 +32,6 @@ $ react-native link react-native-razorpay If the above command doesn't work for you (installation), try [these steps from wiki][wiki]. -### Additional Steps for Linking iOS SDK - -React Native creates static library for each plugin / library / framework / native module being used. - -Due to some limitation on the way Xcode links static and dynamic -libraries / frameworks to projects, we require some additional -steps to be followed to link our iOS SDK to the React Native project. - -You can skip steps 1, 2 and 3 if you used `npm`. - -1. Download [Razorpay's iOS SDK from here][ios-docs] and unzip it. -2. Delete the `.framework` file from -`path/to/your/project/node_modules/react-native-razorpay/ios`. -3. Copy the `.framework` file obtained in step 1 to -`path/to/your/project/node_modules/react-native-razorpay/ios`. -4. Open `path/to/your/project/ios/.xcworkspace` or -`path/to/your/project/ios/.xcodeproj` -5. Also link the `.framework` file **_directly_ to your project** in Xcode. You - can do this by simply dragging-and-dropping the `.framework` file into Xcode -under directory named `your_project`. Check the `Copy items if needed` box and - select your project target from the list below. -6. Add the following line of code in your `AppDelegate.m` under the imports section: -`#import ` -7. Add the following line of code in your `AppDelegate.m` inside the -`application:didFinishLaunchingWithOptions:` method: -`dlopen("Razorpay.framework/Razorpay", RTLD_LAZY | RTLD_GLOBAL);` - ## Usage Sample code to integrate with Razorpay can be found in diff --git a/ios/RazorpayEventEmitter.m b/ios/RazorpayEventEmitter.m index 211f292ee..843968cab 100644 --- a/ios/RazorpayEventEmitter.m +++ b/ios/RazorpayEventEmitter.m @@ -20,76 +20,80 @@ @implementation RazorpayEventEmitter RCT_EXPORT_MODULE(); - (NSArray *)supportedEvents { - return @[ - @"Razorpay::PAYMENT_SUCCESS", - @"Razorpay::PAYMENT_ERROR", - @"Razorpay::EXTERNAL_WALLET_SELECTED" - ]; + return @[ + @"Razorpay::PAYMENT_SUCCESS", + @"Razorpay::PAYMENT_ERROR", + @"Razorpay::EXTERNAL_WALLET_SELECTED" + ]; } - (void)startObserving { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(paymentSuccess:) - name:kPaymentSuccess - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(paymentError:) - name:kPaymentError - object:nil]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(externalWalletSelected:) - name:kExternalWalletSelected - object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(paymentSuccess:) + name:kPaymentSuccess + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(paymentError:) + name:kPaymentError + object:nil]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(externalWalletSelected:) + name:kExternalWalletSelected + object:nil]; } - (void)stopObserving { - [[NSNotificationCenter defaultCenter] removeObserver:self]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)paymentSuccess:(NSNotification *)notification { - [self sendEventWithName:@"Razorpay::PAYMENT_SUCCESS" - body:notification.userInfo]; + [self sendEventWithName:@"Razorpay::PAYMENT_SUCCESS" + body:notification.userInfo]; } - (void)paymentError:(NSNotification *)notification { - [self sendEventWithName:@"Razorpay::PAYMENT_ERROR" - body:notification.userInfo]; + [self sendEventWithName:@"Razorpay::PAYMENT_ERROR" + body:notification.userInfo]; } - (void)externalWalletSelected:(NSNotification *)notification { - [self sendEventWithName:@"Razorpay::EXTERNAL_WALLET_SELECTED" - body:notification.userInfo]; + [self sendEventWithName:@"Razorpay::EXTERNAL_WALLET_SELECTED" + body:notification.userInfo]; } + (void)onPaymentSuccess:(NSString *)payment_id andData:(NSDictionary *)response { - NSDictionary *payload = [NSDictionary dictionaryWithDictionary:response]; - [[NSNotificationCenter defaultCenter] postNotificationName:kPaymentSuccess - object:nil - userInfo:payload]; + NSDictionary *payload = [NSDictionary dictionaryWithDictionary:response]; + [[NSNotificationCenter defaultCenter] postNotificationName:kPaymentSuccess + object:nil + userInfo:payload]; } + (void)onPaymentError:(int)code description:(NSString *)str andData:(NSDictionary *)response { - NSDictionary *payload = @{ - @"code" : @(code), - @"description" : str, - @"details" : response - }; - [[NSNotificationCenter defaultCenter] postNotificationName:kPaymentError - object:nil - userInfo:payload]; + NSDictionary *payload = @{ + @"code" : @(code), + @"description" : str, + @"details" : response + }; + [[NSNotificationCenter defaultCenter] postNotificationName:kPaymentError + object:nil + userInfo:payload]; } + (void)onExternalWalletSelected:(NSString *)walletName andData:(NSDictionary *)paymentData { - NSDictionary *payload = @{ @"name" : walletName, @"details" : paymentData }; - [[NSNotificationCenter defaultCenter] - postNotificationName:kExternalWalletSelected - object:nil - userInfo:payload]; + + NSMutableDictionary *payload = [[NSMutableDictionary alloc] init]; + [payload addEntriesFromDictionary: paymentData]; + [payload setValue:walletName forKey:@"external_wallet"]; + + [[NSNotificationCenter defaultCenter] + postNotificationName:kExternalWalletSelected + object:nil + userInfo:payload]; } @end From 83659e45a5929de1467ae41d3ea139f8ac302146 Mon Sep 17 00:00:00 2001 From: AbhinavArora95 Date: Thu, 22 Feb 2018 14:21:04 +0530 Subject: [PATCH 3/3] Formatting change --- ios/RazorpayEventEmitter.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/RazorpayEventEmitter.m b/ios/RazorpayEventEmitter.m index 843968cab..a8776e69e 100644 --- a/ios/RazorpayEventEmitter.m +++ b/ios/RazorpayEventEmitter.m @@ -74,10 +74,10 @@ + (void)onPaymentError:(int)code description:(NSString *)str andData:(NSDictionary *)response { NSDictionary *payload = @{ - @"code" : @(code), - @"description" : str, - @"details" : response - }; + @"code" : @(code), + @"description" : str, + @"details" : response + }; [[NSNotificationCenter defaultCenter] postNotificationName:kPaymentError object:nil userInfo:payload];