@@ -18,80 +18,83 @@ import UIKit
18
18
19
19
@objc static var isOn = false
20
20
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
+ }
58
78
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
- }
65
79
80
+
66
81
67
- //phVC.initRequest = req
68
- //phVC.delegate = self
69
- //phVC.isSandBoxEnabled = true
70
- //phVC.modalPresentationStyle = .overCurrentContext
71
82
72
- self . present ( phVC, animated: true , completion: nil )
83
+
84
+
73
85
}
74
- @objc
75
- static func requiresMainQueueSetup( ) -> Bool { return true }
76
86
}
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 " )
89
90
}
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
+ }
93
99
}
94
-
95
- return controller
96
- }
97
100
}
0 commit comments