Skip to content

Commit bb1f1a4

Browse files
author
Harsha Harischandra
committed
Build
Change swift compiler
1 parent b8f75ed commit bb1f1a4

File tree

8 files changed

+101
-73
lines changed

8 files changed

+101
-73
lines changed

App.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
NativeModules,
1616
View,
1717
Button,
18+
Alert,
1819
} from 'react-native';
1920

2021
export default class App extends Component {
@@ -34,7 +35,7 @@ export default class App extends Component {
3435
/>
3536
<Button
3637
onPress={() => {
37-
NativeModules.Payhere.payOnece(50);
38+
NativeModules.Payhere.callbackMethod((err, r) => console.log(r));
3839
}}
3940
title="Call Payhere"
4041
color="#841584"

ios/Payhere.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
#import "React/RCTBridgeModule.h"
1111

1212
@interface RCT_EXTERN_MODULE(Payhere, NSObject)
13-
RCT_EXTERN_METHOD(payOnece:(NSInteger *)amount)
13+
RCT_EXTERN_METHOD(payOnece)
14+
RCT_EXTERN_METHOD(callbackMethod:(RCTResponseSenderBlock)callback)
1415
@end

ios/Payhere.swift

+71-68
Original file line numberDiff line numberDiff line change
@@ -18,80 +18,83 @@ import UIKit
1818

1919
@objc static var isOn = false
2020

21-
@objc
22-
func payOnece(_ amount:NSInteger) {
23-
24-
25-
let req : InitRequest = InitRequest()
26-
req.merchantId = "1210251" // Your Merchant ID
27-
req.merchantSecret = "bhasha2" // Your Merchant secret
28-
req.amount = 100.0 // Amount which the customer should pay
29-
req.currency = "LKR" // Currency
30-
req.orderId = "ABCDWXYZ" // Unique ID for your payment transaction
31-
req.itemsDescription = "1 Greeting Card" // Item title or Order/Invoice number
32-
req.custom1 = "This is the custom 1 message"
33-
req.custom2 = "This is the custom 2 message"
34-
35-
let customer = Customer()
36-
37-
customer.firstName = "Saman"
38-
customer.lastName = "Perera"
39-
customer.email = "[email protected]"
40-
customer.phone = "+94771234567"
41-
42-
let address = Address()
43-
address.address = "No 43, Galle Road"
44-
address.city = "Colombo"
45-
address.country = "Sri Lanka"
46-
47-
let deliverAddress = Address()
48-
deliverAddress.address = "No 1, Galle Road"
49-
deliverAddress.city = "Colombo"
50-
deliverAddress.country = "Sri Lanka"
51-
52-
customer.address = address
53-
customer.deliveryAddress = deliverAddress
54-
55-
req.customer = customer
56-
57-
req.items = [Item(id: "1", name: "Card", quantity: 1)]
21+
@objc static func requiresMainQueueSetup() -> Bool {
22+
return false
23+
}
24+
@objc(callbackMethod:)
25+
func callbackMethod(callback: @escaping RCTResponseSenderBlock) -> Void {
26+
let resultsDict = [
27+
"success" : true
28+
];
29+
30+
31+
let req : InitRequest = InitRequest()
32+
req.merchantId = "1210251" // Your Merchant ID
33+
req.merchantSecret = "bhasha2" // Your Merchant secret
34+
req.amount = 100.0 // Amount which the customer should pay
35+
req.currency = "LKR" // Currency
36+
req.orderId = "ABCDWXYZ" // Unique ID for your payment transaction
37+
req.itemsDescription = "1 Greeting Card" // Item title or Order/Invoice number
38+
req.custom1 = "This is the custom 1 message"
39+
req.custom2 = "This is the custom 2 message"
40+
41+
let customer = Customer()
42+
43+
customer.firstName = "Saman"
44+
customer.lastName = "Perera"
45+
customer.email = "[email protected]"
46+
customer.phone = "+94771234567"
47+
48+
let address = Address()
49+
address.address = "No 43, Galle Road"
50+
address.city = "Colombo"
51+
address.country = "Sri Lanka"
52+
53+
let deliverAddress = Address()
54+
deliverAddress.address = "No 1, Galle Road"
55+
deliverAddress.city = "Colombo"
56+
deliverAddress.country = "Sri Lanka"
57+
58+
customer.address = address
59+
customer.deliveryAddress = deliverAddress
60+
61+
req.customer = customer
62+
63+
// req.items = [Item(id: "1", name: "Card", quantity: 1)]
64+
65+
let phVC = PHViewController()
66+
phVC.initRequest = req
67+
phVC.delegate = self
68+
phVC.isSandBoxEnabled = true
69+
phVC.modalPresentationStyle = .overCurrentContext
70+
71+
// self.present(phVC, animated: true, completion: nil)
72+
73+
74+
DispatchQueue.main.async {
75+
callback([NSNull() ,resultsDict])
76+
self.present(phVC, animated: true, completion: nil)
77+
}
5878

59-
let phVC = PHViewController()
60-
DispatchQueue.main.async {
61-
let alert = UIAlertController(title: "Alert", message: "Message", preferredStyle: UIAlertController.Style.alert)
62-
alert.addAction(UIAlertAction(title: "Click", style: UIAlertAction.Style.default, handler: nil))
63-
self.present(alert, animated: true, completion: nil)
64-
}
6579

80+
6681

67-
//phVC.initRequest = req
68-
//phVC.delegate = self
69-
//phVC.isSandBoxEnabled = true
70-
//phVC.modalPresentationStyle = .overCurrentContext
7182

72-
self.present(phVC, animated: true, completion: nil)
83+
84+
7385
}
74-
@objc
75-
static func requiresMainQueueSetup() -> Bool { return true}
7686
}
77-
extension UIApplication {
78-
79-
class func topMostViewController(controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
80-
81-
if let navigationController = controller as? UINavigationController {
82-
return topMostViewController(controller: navigationController.visibleViewController)
83-
}
84-
85-
if let tabController = controller as? UITabBarController {
86-
if let selected = tabController.selectedViewController {
87-
return topMostViewController(controller: selected)
88-
}
87+
extension Payhere : PHViewControllerDelegate{
88+
func onErrorReceived(error: Error) {
89+
print("fff")
8990
}
90-
91-
if let presented = controller?.presentedViewController {
92-
return topMostViewController(controller: presented)
91+
92+
func onResponseReceived(response: PHResponse<Any>?) {
93+
if(response?.isSuccess())!{
94+
95+
//Payment Success
96+
}else{
97+
response?.getMessage()
98+
}
9399
}
94-
95-
return controller
96-
}
97100
}

ios/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,4 +356,4 @@ SPEC CHECKSUMS:
356356

357357
PODFILE CHECKSUM: 2857b711dc5079ab164d4c66a39d8985ff3a2da6
358358

359-
COCOAPODS: 1.8.4
359+
COCOAPODS: 1.9.2

ios/xcapp.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@
665665
PRODUCT_NAME = xcapp;
666666
SWIFT_OBJC_BRIDGING_HEADER = "xcapp-Bridging-Header.h";
667667
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
668-
SWIFT_VERSION = 5.0;
668+
SWIFT_VERSION = 4.2;
669669
VERSIONING_SYSTEM = "apple-generic";
670670
};
671671
name = Debug;
@@ -688,7 +688,7 @@
688688
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
689689
PRODUCT_NAME = xcapp;
690690
SWIFT_OBJC_BRIDGING_HEADER = "xcapp-Bridging-Header.h";
691-
SWIFT_VERSION = 5.0;
691+
SWIFT_VERSION = 4.2;
692692
VERSIONING_SYSTEM = "apple-generic";
693693
};
694694
name = Release;

ios/xcapp.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

0 commit comments

Comments
 (0)