Skip to content

Commit

Permalink
Merge pull request #58 from razorpay/f/ios_flat_response
Browse files Browse the repository at this point in the history
Flat response external wallet ios and removed unnecessary step in readme
  • Loading branch information
AbhinavArora95 authored Feb 22, 2018
2 parents bf167a6 + 83659e4 commit 2ab602e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 81 deletions.
27 changes: 0 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<your_project>.xcworkspace` or
`path/to/your/project/ios/<your_project>.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 <dlfcn.h>`
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
Expand Down
2 changes: 1 addition & 1 deletion example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} `);
});
}}>
<Text style = {styles.text}>PAY</Text>
Expand Down
12 changes: 6 additions & 6 deletions example/ios/example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -281,8 +281,8 @@
920D7AD01D8BE9E700CA6795 /* Razorpay.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Razorpay.framework; sourceTree = "<group>"; };
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 = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
7BFD36E0BFFA4163855158DC /* libRazorpayCheckout.a */ = {isa = PBXFileReference; name = "libRazorpayCheckout.a"; path = "libRazorpayCheckout.a"; sourceTree = "<group>"; 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 = "<group>"; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; };
90E62A34DB624C2489848F4D /* libRazorpayCheckout.a */ = {isa = PBXFileReference; name = "libRazorpayCheckout.a"; path = "libRazorpayCheckout.a"; sourceTree = "<group>"; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -453,7 +453,7 @@
832341B01AAA6A8300B99B32 /* RCTText.xcodeproj */,
00C302DF1ABCB9EE00DB3ED1 /* RCTVibration.xcodeproj */,
139FDEE61B06529A00C62182 /* RCTWebSocket.xcodeproj */,
2E6D90F2286843C281E73D59 /* RazorpayCheckout.xcodeproj */,
794F1E83F20C4F04A7988077 /* RazorpayCheckout.xcodeproj */,
);
name = Libraries;
sourceTree = "<group>";
Expand Down Expand Up @@ -494,7 +494,7 @@
ADCB1EF61FC3096200A14E91 /* Recovered References */ = {
isa = PBXGroup;
children = (
143EC6054168498F96B6AF47 /* libRazorpayCheckout.a */,
7BFD36E0BFFA4163855158DC /* libRazorpayCheckout.a */,
);
name = "Recovered References";
sourceTree = "<group>";
Expand Down
5 changes: 0 additions & 5 deletions example/reload.sh
Original file line number Diff line number Diff line change
@@ -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/
88 changes: 46 additions & 42 deletions ios/RazorpayEventEmitter.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,76 +20,80 @@ @implementation RazorpayEventEmitter
RCT_EXPORT_MODULE();

- (NSArray<NSString *> *)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

0 comments on commit 2ab602e

Please sign in to comment.