@netappsng/react-native-pay 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -0
- package/Netappspay.podspec +22 -0
- package/README.md +190 -0
- package/android/build.gradle +68 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/netappspay/NetappspayModule.kt +170 -0
- package/android/src/main/java/com/netappspay/NetappspayPackage.kt +31 -0
- package/ios/Netappspay-Bridging-Header.h +3 -0
- package/ios/Netappspay.h +6 -0
- package/ios/Netappspay.mm +67 -0
- package/ios/NetappspayBridge.swift +199 -0
- package/lib/module/NativeNetappspay.js +5 -0
- package/lib/module/NativeNetappspay.js.map +1 -0
- package/lib/module/index.js +95 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeNetappspay.d.ts +9 -0
- package/lib/typescript/src/NativeNetappspay.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +88 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +143 -0
- package/src/NativeNetappspay.ts +9 -0
- package/src/index.tsx +202 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 lawrence
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "Netappspay"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => "15.1" }
|
|
14
|
+
s.source = { :git => "https://gitlab.com/talktothelaw/react-native-netapps-pay.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
s.dependency "NetAppsPaySDK"
|
|
20
|
+
|
|
21
|
+
install_modules_dependencies(s)
|
|
22
|
+
end
|
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# @netappsng/react-native-pay
|
|
2
|
+
|
|
3
|
+
NetAppsPay React Native SDK — accept card, bank transfer, USSD, and PayAttitude payments in your React Native app. Supports **iOS** and **Android**.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @netappsng/react-native-pay
|
|
9
|
+
# or
|
|
10
|
+
yarn add @netappsng/react-native-pay
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### iOS
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
cd ios && pod install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The SDK uses the native [NetAppsPaySDK](https://gitlab.com/netapps-sdk/netappspay-sdk-ios) Swift package, which is linked automatically via CocoaPods.
|
|
20
|
+
|
|
21
|
+
### Android
|
|
22
|
+
|
|
23
|
+
The Android SDK is pulled from Maven Central automatically — no extra setup needed.
|
|
24
|
+
|
|
25
|
+
Make sure your project's `android/build.gradle` includes `mavenCentral()` in repositories (this is the default for new React Native projects).
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
import { presentPayment } from '@netappsng/react-native-pay';
|
|
31
|
+
import type { PaymentConfig } from '@netappsng/react-native-pay';
|
|
32
|
+
|
|
33
|
+
function handlePayment() {
|
|
34
|
+
const amountNaira = 100;
|
|
35
|
+
const amountKobo = Math.round(amountNaira * 100);
|
|
36
|
+
|
|
37
|
+
const config: PaymentConfig = {
|
|
38
|
+
publicKey: 'pk_live_xxxxxxxxxxxxxxxxxxxx',
|
|
39
|
+
amount: amountKobo, // ₦100.00 = 10000 kobo
|
|
40
|
+
currency: 'NGN',
|
|
41
|
+
email: 'john@example.com',
|
|
42
|
+
fullName: 'John Doe',
|
|
43
|
+
phoneNumber: '08106720418',
|
|
44
|
+
narration: 'Dev Test Payment',
|
|
45
|
+
paymentChannels: ['card', 'transfer', 'ussd', 'payattitude', 'moniflow'],
|
|
46
|
+
defaultChannel: 'card',
|
|
47
|
+
address1: 'Customer Address',
|
|
48
|
+
metadata: { inputAmount: amountNaira, env: 'development' },
|
|
49
|
+
businessName: 'Demo Store',
|
|
50
|
+
showTransactionSummary: true,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const cleanup = presentPayment(config, {
|
|
54
|
+
onSuccess: (payload) => {
|
|
55
|
+
console.log('Payment successful!', payload.transactionRef);
|
|
56
|
+
// payload: { status, merchantRef, transactionRef, amount, currency, channel, message, timestamp }
|
|
57
|
+
},
|
|
58
|
+
onFailed: (payload) => {
|
|
59
|
+
console.log('Payment failed:', payload.message);
|
|
60
|
+
// payload: { status, amount, currency, message, timestamp, errorCode? }
|
|
61
|
+
},
|
|
62
|
+
onCancel: () => {
|
|
63
|
+
console.log('Payment cancelled');
|
|
64
|
+
},
|
|
65
|
+
onReady: () => {
|
|
66
|
+
console.log('Payment UI ready');
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Call cleanup() to remove event listeners when unmounting
|
|
71
|
+
// e.g. in useEffect: return cleanup;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### With React Hook
|
|
76
|
+
|
|
77
|
+
```tsx
|
|
78
|
+
import React, { useCallback, useRef } from 'react';
|
|
79
|
+
import { Button } from 'react-native';
|
|
80
|
+
import { presentPayment } from '@netappsng/react-native-pay';
|
|
81
|
+
import type { PaymentConfig } from '@netappsng/react-native-pay';
|
|
82
|
+
|
|
83
|
+
export default function CheckoutScreen() {
|
|
84
|
+
const cleanupRef = useRef<(() => void) | null>(null);
|
|
85
|
+
|
|
86
|
+
const pay = useCallback(() => {
|
|
87
|
+
cleanupRef.current?.();
|
|
88
|
+
|
|
89
|
+
const config: PaymentConfig = {
|
|
90
|
+
publicKey: 'pk_live_xxxxxxxxxxxxxxxxxxxx',
|
|
91
|
+
amount: 10000, // ₦100.00
|
|
92
|
+
currency: 'NGN',
|
|
93
|
+
email: 'john@example.com',
|
|
94
|
+
fullName: 'John Doe',
|
|
95
|
+
phoneNumber: '08106720418',
|
|
96
|
+
narration: 'Dev Test Payment',
|
|
97
|
+
paymentChannels: ['card', 'transfer', 'ussd', 'payattitude', 'moniflow'],
|
|
98
|
+
defaultChannel: 'card',
|
|
99
|
+
address1: 'Customer Address',
|
|
100
|
+
metadata: { env: 'development' },
|
|
101
|
+
businessName: 'Demo Store',
|
|
102
|
+
showTransactionSummary: true,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
cleanupRef.current = presentPayment(config, {
|
|
106
|
+
onSuccess: (payload) => {
|
|
107
|
+
console.log('Ref:', payload.transactionRef);
|
|
108
|
+
cleanupRef.current?.();
|
|
109
|
+
},
|
|
110
|
+
onFailed: (payload) => {
|
|
111
|
+
alert(payload.message);
|
|
112
|
+
cleanupRef.current?.();
|
|
113
|
+
},
|
|
114
|
+
onCancel: () => {
|
|
115
|
+
console.log('Cancelled');
|
|
116
|
+
cleanupRef.current?.();
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
return <Button title="Pay ₦100" onPress={pay} />;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Configuration
|
|
126
|
+
|
|
127
|
+
### Required Fields
|
|
128
|
+
|
|
129
|
+
| Field | Type | Description |
|
|
130
|
+
|-------|------|-------------|
|
|
131
|
+
| `publicKey` | `string` | Your NetAppsPay public key |
|
|
132
|
+
| `amount` | `number` | Amount in minor units (kobo/cents). ₦15.00 = `1500` |
|
|
133
|
+
| `currency` | `'NGN' \| 'USD'` | Payment currency |
|
|
134
|
+
| `email` | `string` | Customer email |
|
|
135
|
+
| `fullName` | `string` | Customer full name |
|
|
136
|
+
| `narration` | `string` | Payment description |
|
|
137
|
+
| `paymentChannels` | `PaymentChannel[]` | Channels to display |
|
|
138
|
+
| `defaultChannel` | `PaymentChannel` | Initially selected channel |
|
|
139
|
+
|
|
140
|
+
### Optional Fields
|
|
141
|
+
|
|
142
|
+
| Field | Type | Default | Description |
|
|
143
|
+
|-------|------|---------|-------------|
|
|
144
|
+
| `phoneNumber` | `string` | — | Customer phone number |
|
|
145
|
+
| `transactionRef` | `string` | auto-generated | Custom transaction reference |
|
|
146
|
+
| `address1` | `string` | `'Customer Address'` | Customer address line 1 |
|
|
147
|
+
| `address2` | `string` | — | Customer address line 2 |
|
|
148
|
+
| `city` | `string` | `'Lagos'` | Customer city |
|
|
149
|
+
| `postalCode` | `string` | — | Customer postal code |
|
|
150
|
+
| `locality` | `string` | — | Country code (e.g. `'NG'`) |
|
|
151
|
+
| `administrativeArea` | `string` | — | State/province (e.g. `'Lagos'`) |
|
|
152
|
+
| `chargeAllocation` | `'CUSTOMER' \| 'MERCHANT'` | `'CUSTOMER'` | Who bears the transaction charge |
|
|
153
|
+
| `businessName` | `string` | — | Merchant display name |
|
|
154
|
+
| `logoURL` | `string` | — | Merchant logo URL |
|
|
155
|
+
| `productName` | `string` | — | Product name |
|
|
156
|
+
| `metadata` | `Record<string, any>` | — | Custom key-value metadata |
|
|
157
|
+
| `cardHolderName` | `string` | — | Pre-filled cardholder name |
|
|
158
|
+
| `customerId` | `string` | — | Your internal customer ID |
|
|
159
|
+
| `enableSaveCard` | `boolean` | `false` | Allow saving cards for future payments |
|
|
160
|
+
| `showTransactionSummary` | `boolean` | `true` | Show transaction summary |
|
|
161
|
+
|
|
162
|
+
### Payment Channels
|
|
163
|
+
|
|
164
|
+
| Channel | Description |
|
|
165
|
+
|---------|-------------|
|
|
166
|
+
| `'card'` | Card payment (Visa, Mastercard, Verve) |
|
|
167
|
+
| `'transfer'` | Bank transfer |
|
|
168
|
+
| `'ussd'` | USSD payment |
|
|
169
|
+
| `'payattitude'` | PayAttitude (USSD push) |
|
|
170
|
+
| `'moniflow'` | MoniFlow marketplace |
|
|
171
|
+
|
|
172
|
+
### Callbacks
|
|
173
|
+
|
|
174
|
+
| Callback | Payload | Description |
|
|
175
|
+
|----------|---------|-------------|
|
|
176
|
+
| `onSuccess` | `PaymentSuccessPayload` | Payment completed successfully |
|
|
177
|
+
| `onFailed` | `PaymentFailedPayload` | Payment failed |
|
|
178
|
+
| `onCancel` | — | User dismissed the payment sheet |
|
|
179
|
+
| `onReady` | — | Payment sheet is fully loaded |
|
|
180
|
+
|
|
181
|
+
## Native SDKs
|
|
182
|
+
|
|
183
|
+
This package bridges the native NetAppsPay SDKs:
|
|
184
|
+
|
|
185
|
+
- **iOS**: [NetAppsPaySDK](https://github.com/nicenapp/NetAppsPaySDK) (Swift Package)
|
|
186
|
+
- **Android**: `ng.netapps:netappspay:1.0.0` (Maven Central)
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.Netappspay = [
|
|
3
|
+
kotlinVersion: "2.0.21",
|
|
4
|
+
minSdkVersion: 24,
|
|
5
|
+
compileSdkVersion: 36,
|
|
6
|
+
targetSdkVersion: 36
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
ext.getExtOrDefault = { prop ->
|
|
10
|
+
if (rootProject.ext.has(prop)) {
|
|
11
|
+
return rootProject.ext.get(prop)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return Netappspay[prop]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
repositories {
|
|
18
|
+
google()
|
|
19
|
+
mavenCentral()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
dependencies {
|
|
23
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
24
|
+
// noinspection DifferentKotlinGradleVersion
|
|
25
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
apply plugin: "com.android.library"
|
|
31
|
+
apply plugin: "kotlin-android"
|
|
32
|
+
|
|
33
|
+
apply plugin: "com.facebook.react"
|
|
34
|
+
|
|
35
|
+
android {
|
|
36
|
+
namespace "com.netappspay"
|
|
37
|
+
|
|
38
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
39
|
+
|
|
40
|
+
defaultConfig {
|
|
41
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
42
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
buildFeatures {
|
|
46
|
+
buildConfig true
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
buildTypes {
|
|
50
|
+
release {
|
|
51
|
+
minifyEnabled false
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
lint {
|
|
56
|
+
disable "GradleCompatible"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
compileOptions {
|
|
60
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
61
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
dependencies {
|
|
66
|
+
implementation "com.facebook.react:react-android"
|
|
67
|
+
implementation "ng.netapps:netappspay:1.0.0"
|
|
68
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
package com.netappspay
|
|
2
|
+
|
|
3
|
+
import android.app.Activity
|
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
|
+
import com.facebook.react.bridge.ReadableMap
|
|
6
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
7
|
+
import com.netappspay.sdk.PaymentSDK
|
|
8
|
+
import com.netappspay.sdk.models.*
|
|
9
|
+
|
|
10
|
+
class NetappspayModule(reactContext: ReactApplicationContext) :
|
|
11
|
+
NativeNetappspaySpec(reactContext) {
|
|
12
|
+
|
|
13
|
+
private var listenerCount = 0
|
|
14
|
+
|
|
15
|
+
companion object {
|
|
16
|
+
const val NAME = NativeNetappspaySpec.NAME
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun present(config: ReadableMap) {
|
|
20
|
+
val activity = currentActivity ?: run {
|
|
21
|
+
sendEvent("onPaymentFailed", mapOf(
|
|
22
|
+
"status" to "failed",
|
|
23
|
+
"message" to "Unable to find current activity"
|
|
24
|
+
))
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
val map = config.toHashMap()
|
|
29
|
+
|
|
30
|
+
// Required fields
|
|
31
|
+
val publicKey = map["publicKey"] as? String ?: ""
|
|
32
|
+
val amountNum = map["amount"] as? Double ?: 0.0
|
|
33
|
+
val amount = amountNum.toInt()
|
|
34
|
+
val currencyStr = (map["currency"] as? String ?: "NGN").uppercase()
|
|
35
|
+
val email = map["email"] as? String ?: ""
|
|
36
|
+
val fullName = map["fullName"] as? String ?: ""
|
|
37
|
+
val narration = map["narration"] as? String ?: ""
|
|
38
|
+
|
|
39
|
+
if (publicKey.isEmpty() || email.isEmpty() || fullName.isEmpty() || narration.isEmpty() || amount <= 0) {
|
|
40
|
+
sendEvent("onPaymentFailed", mapOf(
|
|
41
|
+
"status" to "failed",
|
|
42
|
+
"message" to "Missing required config fields (publicKey, amount, email, fullName, narration)"
|
|
43
|
+
))
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
val currency = if (currencyStr == "USD") Currency.USD else Currency.NGN
|
|
48
|
+
|
|
49
|
+
// Payment channels
|
|
50
|
+
val channelStrings = (map["paymentChannels"] as? List<*>)?.mapNotNull { it as? String } ?: listOf("card")
|
|
51
|
+
val channels = channelStrings.mapNotNull { mapChannel(it) }.ifEmpty { listOf(PaymentChannel.CARD) }
|
|
52
|
+
|
|
53
|
+
// Default channel
|
|
54
|
+
val defaultChannelStr = map["defaultChannel"] as? String
|
|
55
|
+
val defaultChannel = if (defaultChannelStr != null) mapChannel(defaultChannelStr) ?: channels.first() else channels.first()
|
|
56
|
+
|
|
57
|
+
// Metadata
|
|
58
|
+
@Suppress("UNCHECKED_CAST")
|
|
59
|
+
val metadata = (map["metadata"] as? Map<String, Any>) ?: emptyMap()
|
|
60
|
+
|
|
61
|
+
// Build config
|
|
62
|
+
val address1Raw = (map["address1"] as? String)?.trim() ?: ""
|
|
63
|
+
val cityRaw = (map["city"] as? String)?.trim() ?: ""
|
|
64
|
+
|
|
65
|
+
val paymentConfig = PaymentConfig(
|
|
66
|
+
publicKey = publicKey,
|
|
67
|
+
amount = amount,
|
|
68
|
+
currency = currency,
|
|
69
|
+
email = email,
|
|
70
|
+
fullName = fullName,
|
|
71
|
+
phoneNumber = (map["phoneNumber"] as? String) ?: "",
|
|
72
|
+
narration = narration,
|
|
73
|
+
paymentChannels = channels,
|
|
74
|
+
defaultChannel = defaultChannel,
|
|
75
|
+
metadata = metadata,
|
|
76
|
+
address1 = address1Raw.ifEmpty { "Customer Address" },
|
|
77
|
+
address2 = (map["address2"] as? String) ?: "",
|
|
78
|
+
city = cityRaw.ifEmpty { "Lagos" }
|
|
79
|
+
).apply {
|
|
80
|
+
(map["transactionRef"] as? String)?.let { transactionRef = it }
|
|
81
|
+
(map["businessName"] as? String)?.let { businessName = it }
|
|
82
|
+
(map["logoURL"] as? String)?.let { logoURL = it }
|
|
83
|
+
(map["productName"] as? String)?.let { productName = it }
|
|
84
|
+
(map["cardHolderName"] as? String)?.let { cardHolderName = it }
|
|
85
|
+
(map["customerId"] as? String)?.let { customerId = it }
|
|
86
|
+
(map["postalCode"] as? String)?.let { postalCode = it }
|
|
87
|
+
(map["locality"] as? String)?.let { locality = it }
|
|
88
|
+
(map["administrativeArea"] as? String)?.let { administrativeArea = it }
|
|
89
|
+
(map["enableSaveCard"] as? Boolean)?.let { enableSaveCard = it }
|
|
90
|
+
(map["showTransactionSummary"] as? Boolean)?.let { showTransactionSummary = it }
|
|
91
|
+
(map["isTest"] as? Boolean)?.let { isTest = it }
|
|
92
|
+
(map["debugMode"] as? Boolean)?.let {
|
|
93
|
+
debugMode = it
|
|
94
|
+
PaymentSDK.debugMode = it
|
|
95
|
+
}
|
|
96
|
+
(map["chargeAllocation"] as? String)?.let {
|
|
97
|
+
chargeAllocation = if (it.uppercase() == "MERCHANT") ChargeAllocation.MERCHANT else ChargeAllocation.CUSTOMER
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
val listener = object : PaymentSDK.PaymentSDKListener {
|
|
102
|
+
override fun onSuccess(payload: PaymentSuccessPayload) {
|
|
103
|
+
sendEvent("onPaymentSuccess", mapOf(
|
|
104
|
+
"status" to payload.status,
|
|
105
|
+
"merchantRef" to payload.merchantRef,
|
|
106
|
+
"transactionRef" to payload.transactionRef,
|
|
107
|
+
"amount" to payload.amount,
|
|
108
|
+
"currency" to payload.currency.code,
|
|
109
|
+
"channel" to payload.channel.code,
|
|
110
|
+
"message" to payload.message,
|
|
111
|
+
"timestamp" to payload.timestamp
|
|
112
|
+
))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
override fun onFailed(payload: PaymentFailedPayload) {
|
|
116
|
+
val body = mutableMapOf<String, Any>(
|
|
117
|
+
"status" to payload.status,
|
|
118
|
+
"amount" to payload.amount,
|
|
119
|
+
"currency" to payload.currency.code,
|
|
120
|
+
"message" to payload.message,
|
|
121
|
+
"timestamp" to payload.timestamp
|
|
122
|
+
)
|
|
123
|
+
payload.merchantRef?.let { body["merchantRef"] = it }
|
|
124
|
+
payload.transactionRef?.let { body["transactionRef"] = it }
|
|
125
|
+
payload.channel?.let { body["channel"] = it.code }
|
|
126
|
+
payload.errorCode?.let { body["errorCode"] = it }
|
|
127
|
+
sendEvent("onPaymentFailed", body)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
override fun onCancel() {
|
|
131
|
+
sendEvent("onPaymentCancel", emptyMap())
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
override fun onReady() {
|
|
135
|
+
sendEvent("onPaymentReady", emptyMap())
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
activity.runOnUiThread {
|
|
140
|
+
PaymentSDK.present(activity, paymentConfig, listener)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
override fun addListener(eventType: String) {
|
|
145
|
+
listenerCount++
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
override fun removeListeners(count: Double) {
|
|
149
|
+
listenerCount -= count.toInt()
|
|
150
|
+
if (listenerCount < 0) listenerCount = 0
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private fun sendEvent(eventName: String, body: Map<String, Any>) {
|
|
154
|
+
reactApplicationContext
|
|
155
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
156
|
+
.emit(eventName, com.facebook.react.bridge.Arguments.makeNativeMap(body))
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private fun mapChannel(str: String): PaymentChannel? {
|
|
160
|
+
return when (str.lowercase()) {
|
|
161
|
+
"card" -> PaymentChannel.CARD
|
|
162
|
+
"transfer", "bank_transfer" -> PaymentChannel.TRANSFER
|
|
163
|
+
"ussd", "ussd_code" -> PaymentChannel.USSD
|
|
164
|
+
"payattitude", "ussd_push", "pay_attitude" -> PaymentChannel.PAYATTITUDE
|
|
165
|
+
"moniflow", "netapps_marketplace", "marketplace" -> PaymentChannel.MONIFLOW
|
|
166
|
+
"tap_to_pay", "nfc" -> PaymentChannel.TAP_TO_PAY
|
|
167
|
+
else -> null
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package com.netappspay
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import java.util.HashMap
|
|
9
|
+
|
|
10
|
+
class NetappspayPackage : BaseReactPackage() {
|
|
11
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
12
|
+
return if (name == NetappspayModule.NAME) {
|
|
13
|
+
NetappspayModule(reactContext)
|
|
14
|
+
} else {
|
|
15
|
+
null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
|
|
20
|
+
mapOf(
|
|
21
|
+
NetappspayModule.NAME to ReactModuleInfo(
|
|
22
|
+
name = NetappspayModule.NAME,
|
|
23
|
+
className = NetappspayModule.NAME,
|
|
24
|
+
canOverrideExistingModule = false,
|
|
25
|
+
needsEagerInit = false,
|
|
26
|
+
isCxxModule = false,
|
|
27
|
+
isTurboModule = true
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
}
|
package/ios/Netappspay.h
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#import "Netappspay.h"
|
|
2
|
+
#import <React/RCTBridge.h>
|
|
3
|
+
#import <React/RCTUtils.h>
|
|
4
|
+
|
|
5
|
+
// Swift bridging — the actual implementation lives in NetappspayBridge.swift
|
|
6
|
+
// This is auto-generated as <ProductName>-Swift.h by Xcode.
|
|
7
|
+
#if __has_include("Netappspay-Swift.h")
|
|
8
|
+
#import "Netappspay-Swift.h"
|
|
9
|
+
#else
|
|
10
|
+
#import <Netappspay/Netappspay-Swift.h>
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
@implementation Netappspay {
|
|
14
|
+
NetappspayBridge *_bridge;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
RCT_EXPORT_MODULE()
|
|
18
|
+
|
|
19
|
+
- (instancetype)init {
|
|
20
|
+
self = [super init];
|
|
21
|
+
if (self) {
|
|
22
|
+
_bridge = [[NetappspayBridge alloc] init];
|
|
23
|
+
}
|
|
24
|
+
return self;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
- (NSArray<NSString *> *)supportedEvents {
|
|
28
|
+
return @[@"onPaymentSuccess", @"onPaymentFailed", @"onPaymentCancel", @"onPaymentReady"];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
- (void)addListener:(NSString *)eventName {
|
|
32
|
+
[super addListener:eventName];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (void)removeListeners:(double)count {
|
|
36
|
+
[super removeListeners:count];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (void)present:(NSDictionary *)config {
|
|
40
|
+
__weak Netappspay *weakSelf = self;
|
|
41
|
+
[_bridge presentWithConfig:config
|
|
42
|
+
onSuccess:^(NSDictionary *payload) {
|
|
43
|
+
[weakSelf sendEventWithName:@"onPaymentSuccess" body:payload];
|
|
44
|
+
}
|
|
45
|
+
onFailed:^(NSDictionary *payload) {
|
|
46
|
+
[weakSelf sendEventWithName:@"onPaymentFailed" body:payload];
|
|
47
|
+
}
|
|
48
|
+
onCancel:^{
|
|
49
|
+
[weakSelf sendEventWithName:@"onPaymentCancel" body:@{}];
|
|
50
|
+
}
|
|
51
|
+
onReady:^{
|
|
52
|
+
[weakSelf sendEventWithName:@"onPaymentReady" body:@{}];
|
|
53
|
+
}
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
58
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
59
|
+
{
|
|
60
|
+
return std::make_shared<facebook::react::NativeNetappspaySpecJSI>(params);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
64
|
+
return YES;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@end
|