@netappsng/react-native-pay 0.3.1 → 0.4.28
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/Netappspay.podspec +7 -1
- package/android/build.gradle +12 -1
- package/android/src/main/java/com/netappspay/NetappspayModule.kt +15 -7
- package/ios/NetappspayBridge.swift +16 -14
- package/lib/module/channelSelection.js +29 -0
- package/lib/module/channelSelection.js.map +1 -0
- package/lib/module/index.js +13 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/channelSelection.d.ts +22 -0
- package/lib/typescript/src/channelSelection.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +9 -21
- package/src/channelSelection.ts +31 -0
- package/src/index.tsx +18 -3
package/Netappspay.podspec
CHANGED
|
@@ -16,7 +16,13 @@ Pod::Spec.new do |s|
|
|
|
16
16
|
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
|
|
17
17
|
s.private_header_files = "ios/**/*.h"
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
ios_native_version = (package["nativeSdkVersions"] || {})["ios"]
|
|
20
|
+
raise "package.json is missing nativeSdkVersions.ios" if ios_native_version.to_s.empty?
|
|
21
|
+
unless ios_native_version =~ /\A\d+\.\d+\.\d+\z/
|
|
22
|
+
raise "nativeSdkVersions.ios is '#{ios_native_version}', which is not an exact version. " \
|
|
23
|
+
"Run `yarn sync-native` to pin the newest NetAppsPaySDK on CocoaPods Trunk."
|
|
24
|
+
end
|
|
25
|
+
s.dependency "NetAppsPaySDK", ios_native_version
|
|
20
26
|
|
|
21
27
|
install_modules_dependencies(s)
|
|
22
28
|
end
|
package/android/build.gradle
CHANGED
|
@@ -62,7 +62,18 @@ android {
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
def netappsPayNativeAndroidVersion = {
|
|
66
|
+
def pkg = new groovy.json.JsonSlurper().parse(file("$projectDir/../package.json"))
|
|
67
|
+
def pinned = pkg.nativeSdkVersions?.android
|
|
68
|
+
if (!pinned) {
|
|
69
|
+
throw new GradleException(
|
|
70
|
+
"package.json is missing nativeSdkVersions.android - the RN bridge must pin an exact ng.netapps:netappspay version"
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
return pinned
|
|
74
|
+
}()
|
|
75
|
+
|
|
65
76
|
dependencies {
|
|
66
77
|
implementation "com.facebook.react:react-android"
|
|
67
|
-
implementation "ng.netapps:netappspay
|
|
78
|
+
implementation "ng.netapps:netappspay:${netappsPayNativeAndroidVersion}"
|
|
68
79
|
}
|
|
@@ -46,13 +46,20 @@ class NetappspayModule(reactContext: ReactApplicationContext) :
|
|
|
46
46
|
|
|
47
47
|
val currency = if (currencyStr == "USD") Currency.USD else Currency.NGN
|
|
48
48
|
|
|
49
|
-
// Payment channels
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
val
|
|
55
|
-
|
|
49
|
+
// Payment channels — pass through exactly what the merchant offered. An empty
|
|
50
|
+
// list means "no restriction": the native SDK will offer every ACTIVE channel
|
|
51
|
+
// returned by the backend (do NOT force card here, which would restrict the
|
|
52
|
+
// sheet to a possibly-inactive card channel).
|
|
53
|
+
val channelStrings = (map["paymentChannels"] as? List<*>)?.mapNotNull { it as? String } ?: emptyList()
|
|
54
|
+
val channels = channelStrings.mapNotNull { mapChannel(it) }
|
|
55
|
+
|
|
56
|
+
// Default channel hint, forwarded only when the merchant explicitly asked for
|
|
57
|
+
// one AND it is consistent with `channels`. Otherwise null: the SDK then
|
|
58
|
+
// pre-selects the first channel the backend reports ACTIVE, in the merchant's
|
|
59
|
+
// own order. Never synthesise card — doing so is what made the sheet open on
|
|
60
|
+
// card even when card was not among the merchant's channels.
|
|
61
|
+
val requestedDefault = (map["defaultChannel"] as? String)?.let { mapChannel(it) }
|
|
62
|
+
val defaultChannel = requestedDefault?.takeIf { channels.isEmpty() || it in channels }
|
|
56
63
|
|
|
57
64
|
// Metadata
|
|
58
65
|
@Suppress("UNCHECKED_CAST")
|
|
@@ -82,6 +89,7 @@ class NetappspayModule(reactContext: ReactApplicationContext) :
|
|
|
82
89
|
(map["logoURL"] as? String)?.let { logoURL = it }
|
|
83
90
|
(map["productName"] as? String)?.let { productName = it }
|
|
84
91
|
(map["cardHolderName"] as? String)?.let { cardHolderName = it }
|
|
92
|
+
(map["mToken"] as? String)?.let { mToken = it }
|
|
85
93
|
(map["customerId"] as? String)?.let { customerId = it }
|
|
86
94
|
(map["postalCode"] as? String)?.let { postalCode = it }
|
|
87
95
|
(map["locality"] as? String)?.let { locality = it }
|
|
@@ -45,20 +45,21 @@ import NetAppsPaySDK
|
|
|
45
45
|
|
|
46
46
|
let currency: Currency = currencyStr.uppercased() == "USD" ? .USD : .NGN
|
|
47
47
|
|
|
48
|
-
// Payment channels
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// Default channel
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
48
|
+
// Payment channels — pass through exactly what the merchant offered. An
|
|
49
|
+
// empty list means "no restriction": the native SDK will offer every
|
|
50
|
+
// ACTIVE channel returned by the backend (do NOT force card here, which
|
|
51
|
+
// would restrict the sheet to a possibly-inactive card channel).
|
|
52
|
+
let channels: [PaymentChannel] = (dict["paymentChannels"] as? [String])?
|
|
53
|
+
.compactMap { mapChannel($0) } ?? []
|
|
54
|
+
|
|
55
|
+
// Default channel hint, forwarded only when the merchant explicitly asked
|
|
56
|
+
// for one AND it is consistent with `channels`. Otherwise nil: the SDK
|
|
57
|
+
// then pre-selects the first channel the backend reports ACTIVE, in the
|
|
58
|
+
// merchant's own order. Never synthesise card — doing so is what made the
|
|
59
|
+
// sheet open on card even when card was not among the merchant's channels.
|
|
60
|
+
let requestedDefault = (dict["defaultChannel"] as? String).flatMap { mapChannel($0) }
|
|
61
|
+
let defaultChannel: PaymentChannel? = requestedDefault.flatMap {
|
|
62
|
+
channels.isEmpty || channels.contains($0) ? $0 : nil
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
// Metadata
|
|
@@ -92,6 +93,7 @@ import NetAppsPaySDK
|
|
|
92
93
|
if let v = dict["logoURL"] as? String { config.logoURL = v }
|
|
93
94
|
if let v = dict["productName"] as? String { config.productName = v }
|
|
94
95
|
if let v = dict["cardHolderName"] as? String { config.cardHolderName = v }
|
|
96
|
+
if let v = dict["mToken"] as? String { config.mToken = v }
|
|
95
97
|
if let v = dict["customerId"] as? String { config.customerId = v }
|
|
96
98
|
if let v = dict["postalCode"] as? String { config.postalCode = v }
|
|
97
99
|
if let v = dict["locality"] as? String { config.locality = v }
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve which payment channel the bridge should hand to the native SDK as the
|
|
5
|
+
* default/pre-selected channel.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the web/iOS/Android SDKs so behaviour is consistent across platforms:
|
|
8
|
+
* • Returns `defaultChannel` when it is one of `paymentChannels`.
|
|
9
|
+
* • Otherwise returns the first channel in `paymentChannels`.
|
|
10
|
+
* • Returns null when `paymentChannels` is empty.
|
|
11
|
+
*
|
|
12
|
+
* Card is never hard-coded: it is used only when it is the configured default
|
|
13
|
+
* (and present in the list) or genuinely the first channel.
|
|
14
|
+
*
|
|
15
|
+
* Note: this React Native package is a thin bridge — it does not know which
|
|
16
|
+
* channels the backend marked active. "Available" here means the channels the
|
|
17
|
+
* merchant chose to offer (`paymentChannels`). The native SDK performs the
|
|
18
|
+
* further filtering by the backend's ACTIVE channels and makes the final
|
|
19
|
+
* selection, so this only guarantees the bridge never forwards a default that is
|
|
20
|
+
* inconsistent with the offered channels.
|
|
21
|
+
*/
|
|
22
|
+
export function resolveDefaultChannel(paymentChannels, defaultChannel) {
|
|
23
|
+
if (!paymentChannels || paymentChannels.length === 0) return null;
|
|
24
|
+
if (defaultChannel && paymentChannels.includes(defaultChannel)) {
|
|
25
|
+
return defaultChannel;
|
|
26
|
+
}
|
|
27
|
+
return paymentChannels[0] ?? null;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=channelSelection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["resolveDefaultChannel","paymentChannels","defaultChannel","length","includes"],"sourceRoot":"../../src","sources":["channelSelection.ts"],"mappings":";;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,qBAAqBA,CACnCC,eAAiC,EACjCC,cAAsC,EACf;EACvB,IAAI,CAACD,eAAe,IAAIA,eAAe,CAACE,MAAM,KAAK,CAAC,EAAE,OAAO,IAAI;EACjE,IAAID,cAAc,IAAID,eAAe,CAACG,QAAQ,CAACF,cAAc,CAAC,EAAE;IAC9D,OAAOA,cAAc;EACvB;EACA,OAAOD,eAAe,CAAC,CAAC,CAAC,IAAI,IAAI;AACnC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
import { NativeEventEmitter, Platform } from 'react-native';
|
|
4
4
|
import NativeNetappspay from "./NativeNetappspay.js";
|
|
5
|
+
import { resolveDefaultChannel } from "./channelSelection.js";
|
|
6
|
+
export { resolveDefaultChannel } from "./channelSelection.js";
|
|
5
7
|
|
|
6
8
|
// ── Types ──
|
|
7
9
|
|
|
@@ -49,7 +51,6 @@ function validateConfig(config) {
|
|
|
49
51
|
if (typeof config.amount !== 'number' || config.amount <= 0) return "'amount' must be a positive number in minor units (e.g. 150000 for ₦1,500.00).";
|
|
50
52
|
if (!config.currency) return "'currency' is required (e.g. 'NGN').";
|
|
51
53
|
if (!config.paymentChannels?.length) return "'paymentChannels' must contain at least one channel (e.g. ['card', 'transfer']).";
|
|
52
|
-
if (!config.defaultChannel) return "'defaultChannel' is required (e.g. 'card').";
|
|
53
54
|
return null;
|
|
54
55
|
}
|
|
55
56
|
export function presentPayment(config, callbacks) {
|
|
@@ -69,9 +70,20 @@ export function presentPayment(config, callbacks) {
|
|
|
69
70
|
return () => {};
|
|
70
71
|
}
|
|
71
72
|
|
|
73
|
+
// Reconcile the default channel against the offered channels so we never hand
|
|
74
|
+
// the native SDK a default that isn't in the list (e.g. defaultChannel:'card'
|
|
75
|
+
// when card isn't offered). The native SDK then further validates this against
|
|
76
|
+
// the backend's ACTIVE channels and selects the first active one if needed —
|
|
77
|
+
// this is what prevents a blank payment screen when card is disabled.
|
|
78
|
+
// De-duped first: a repeated channel renders the same tab N times natively.
|
|
79
|
+
const paymentChannels = [...new Set(config.paymentChannels)];
|
|
80
|
+
const resolvedDefaultChannel = resolveDefaultChannel(paymentChannels, config.defaultChannel) ?? paymentChannels[0];
|
|
81
|
+
|
|
72
82
|
// Apply defaults for fields the API requires to be non-empty
|
|
73
83
|
const sanitizedConfig = {
|
|
74
84
|
...config,
|
|
85
|
+
paymentChannels,
|
|
86
|
+
defaultChannel: resolvedDefaultChannel,
|
|
75
87
|
fullName: config.fullName?.trim() || '',
|
|
76
88
|
address1: config.address1?.trim() || 'Customer Address',
|
|
77
89
|
city: config.city?.trim() || 'Lagos',
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeEventEmitter","Platform","NativeNetappspay","emitter","validateConfig","config","publicKey","trim","email","fullName","narration","amount","currency","paymentChannels","length","
|
|
1
|
+
{"version":3,"names":["NativeEventEmitter","Platform","NativeNetappspay","resolveDefaultChannel","emitter","validateConfig","config","publicKey","trim","email","fullName","narration","amount","currency","paymentChannels","length","presentPayment","callbacks","OS","console","warn","error","onFailed","status","message","timestamp","Date","toISOString","Set","resolvedDefaultChannel","defaultChannel","sanitizedConfig","address1","city","phoneNumber","subscriptions","addListener","payload","onSuccess","onCancel","onReady","setTimeout","present","forEach","s","remove"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAC3D,OAAOC,gBAAgB,MAAM,uBAAoB;AACjD,SAASC,qBAAqB,QAAQ,uBAAoB;AAE1D,SAASA,qBAAqB,QAAQ,uBAAoB;;AAE1D;;AAsGA;;AAEA,MAAMC,OAAO,GAAG,IAAIJ,kBAAkB,CAACE,gBAAuB,CAAC;;AAE/D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,cAAcA,CAACC,MAAqB,EAAiB;EAC5D,IAAI,CAACA,MAAM,CAACC,SAAS,EAAEC,IAAI,CAAC,CAAC,EAAE,OAAO,iFAAiF;EACvH,IAAI,CAACF,MAAM,CAACG,KAAK,EAAED,IAAI,CAAC,CAAC,EAAE,OAAO,4DAA4D;EAC9F,IAAI,CAACF,MAAM,CAACI,QAAQ,EAAEF,IAAI,CAAC,CAAC,EAAE,OAAO,sFAAsF;EAC3H,IAAI,CAACF,MAAM,CAACK,SAAS,EAAEH,IAAI,CAAC,CAAC,EAAE,OAAO,wEAAwE;EAC9G,IAAI,OAAOF,MAAM,CAACM,MAAM,KAAK,QAAQ,IAAIN,MAAM,CAACM,MAAM,IAAI,CAAC,EAAE,OAAO,gFAAgF;EACpJ,IAAI,CAACN,MAAM,CAACO,QAAQ,EAAE,OAAO,sCAAsC;EACnE,IAAI,CAACP,MAAM,CAACQ,eAAe,EAAEC,MAAM,EAAE,OAAO,kFAAkF;EAC9H,OAAO,IAAI;AACb;AAEA,OAAO,SAASC,cAAcA,CAC5BV,MAAqB,EACrBW,SAA4B,EAChB;EACZ,IAAIhB,QAAQ,CAACiB,EAAE,KAAK,KAAK,IAAIjB,QAAQ,CAACiB,EAAE,K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,EAAGC,OAAO,IAAK;IACnDpB,SAAS,EAAEqB,SAAS,GAAGD,OAAgC,CAAC;EAC1D,CAAC,CAAC,EACFjC,OAAO,CAACgC,WAAW,CAAC,iBAAiB,EAAGC,OAAO,IAAK;IAClDpB,SAAS,EAAEK,QAAQ,GAAGe,OAA+B,CAAC;EACxD,CAAC,CAAC,EACFjC,OAAO,CAACgC,WAAW,CAAC,iBAAiB,EAAE,MAAM;IAC3CnB,SAAS,EAAEsB,QAAQ,GAAG,CAAC;EACzB,CAAC,CAAC,EACFnC,OAAO,CAACgC,WAAW,CAAC,gBAAgB,EAAE,MAAM;IAC1CnB,SAAS,EAAEuB,OAAO,GAAG,CAAC;EACxB,CAAC,CAAC,CACH;;EAED;EACAC,UAAU,CAAC,MAAMvC,gBAAgB,CAACwC,OAAO,CAACX,eAAsB,CAAC,EAAE,CAAC,CAAC;EAErE,OAAO,MAAM;IACXI,aAAa,CAACQ,OAAO,CAAEC,CAAC,IAAKA,CAAC,CAACC,MAAM,CAAC,CAAC,CAAC;EAC1C,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PaymentChannel } from './index';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve which payment channel the bridge should hand to the native SDK as the
|
|
4
|
+
* default/pre-selected channel.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors the web/iOS/Android SDKs so behaviour is consistent across platforms:
|
|
7
|
+
* • Returns `defaultChannel` when it is one of `paymentChannels`.
|
|
8
|
+
* • Otherwise returns the first channel in `paymentChannels`.
|
|
9
|
+
* • Returns null when `paymentChannels` is empty.
|
|
10
|
+
*
|
|
11
|
+
* Card is never hard-coded: it is used only when it is the configured default
|
|
12
|
+
* (and present in the list) or genuinely the first channel.
|
|
13
|
+
*
|
|
14
|
+
* Note: this React Native package is a thin bridge — it does not know which
|
|
15
|
+
* channels the backend marked active. "Available" here means the channels the
|
|
16
|
+
* merchant chose to offer (`paymentChannels`). The native SDK performs the
|
|
17
|
+
* further filtering by the backend's ACTIVE channels and makes the final
|
|
18
|
+
* selection, so this only guarantees the bridge never forwards a default that is
|
|
19
|
+
* inconsistent with the offered channels.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveDefaultChannel(paymentChannels: PaymentChannel[], defaultChannel?: PaymentChannel | null): PaymentChannel | null;
|
|
22
|
+
//# sourceMappingURL=channelSelection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channelSelection.d.ts","sourceRoot":"","sources":["../../../src/channelSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,eAAe,EAAE,cAAc,EAAE,EACjC,cAAc,CAAC,EAAE,cAAc,GAAG,IAAI,GACrC,cAAc,GAAG,IAAI,CAMvB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { resolveDefaultChannel } from './channelSelection';
|
|
1
2
|
export type Currency = 'NGN' | 'USD';
|
|
2
3
|
export type PaymentChannel = 'card' | 'transfer' | 'ussd' | 'payattitude' | 'moniflow' | 'tap_to_pay';
|
|
3
4
|
export type ChargeAllocation = 'CUSTOMER' | 'MERCHANT';
|
|
@@ -16,8 +17,8 @@ export interface PaymentConfig {
|
|
|
16
17
|
narration: string;
|
|
17
18
|
/** Channels to display */
|
|
18
19
|
paymentChannels: PaymentChannel[];
|
|
19
|
-
/** Initially selected channel */
|
|
20
|
-
defaultChannel
|
|
20
|
+
/** Initially selected channel. Defaults to the first entry of `paymentChannels`. */
|
|
21
|
+
defaultChannel?: PaymentChannel;
|
|
21
22
|
/** Customer phone number */
|
|
22
23
|
phoneNumber?: string;
|
|
23
24
|
/** Address line 1 */
|
|
@@ -28,6 +29,7 @@ export interface PaymentConfig {
|
|
|
28
29
|
city?: string;
|
|
29
30
|
/** Custom key-value metadata */
|
|
30
31
|
metadata?: Record<string, any>;
|
|
32
|
+
mToken?: string;
|
|
31
33
|
/** Custom transaction reference */
|
|
32
34
|
transactionRef?: string;
|
|
33
35
|
/** Merchant display name */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAI3D,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAC;AAErC,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,UAAU,GACV,MAAM,GACN,aAAa,GACb,UAAU,GACV,YAAY,CAAC;AAEjB,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,UAAU,CAAC;AAEvD,MAAM,WAAW,aAAa;IAC5B,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,MAAM,EAAE,MAAM,CAAC;IACf,eAAe;IACf,QAAQ,EAAE,QAAQ,CAAC;IACnB,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,eAAe,EAAE,cAAc,EAAE,CAAC;IAClC,oFAAoF;IACpF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,4BAA4B;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,MAAM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M,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACrD,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IACnD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAiDD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,SAAS,CAAC,EAAE,gBAAgB,GAC3B,MAAM,IAAI,CA4DZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netappsng/react-native-pay",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.28",
|
|
4
|
+
"releaseLine": "0.4",
|
|
5
|
+
"nativeSdkVersions": {
|
|
6
|
+
"android": "1.4.58",
|
|
7
|
+
"ios": "1.1.1"
|
|
8
|
+
},
|
|
4
9
|
"description": "netapps payment sdk",
|
|
5
10
|
"main": "./lib/module/index.js",
|
|
6
11
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -37,7 +42,9 @@
|
|
|
37
42
|
"prepare": "bob build",
|
|
38
43
|
"typecheck": "tsc",
|
|
39
44
|
"test": "jest",
|
|
40
|
-
"
|
|
45
|
+
"sync-native": "node scripts/sync-native-versions.mjs",
|
|
46
|
+
"test:scripts": "node --test scripts/sync-native-versions.check.mjs",
|
|
47
|
+
"release:local": "node scripts/release-local.mjs"
|
|
41
48
|
},
|
|
42
49
|
"keywords": [
|
|
43
50
|
"react-native",
|
|
@@ -112,25 +119,6 @@
|
|
|
112
119
|
"<rootDir>/lib/"
|
|
113
120
|
]
|
|
114
121
|
},
|
|
115
|
-
"release-it": {
|
|
116
|
-
"git": {
|
|
117
|
-
"commitMessage": "chore: release ${version}",
|
|
118
|
-
"tagName": "v${version}"
|
|
119
|
-
},
|
|
120
|
-
"npm": {
|
|
121
|
-
"publish": true
|
|
122
|
-
},
|
|
123
|
-
"github": {
|
|
124
|
-
"release": true
|
|
125
|
-
},
|
|
126
|
-
"plugins": {
|
|
127
|
-
"@release-it/conventional-changelog": {
|
|
128
|
-
"preset": {
|
|
129
|
-
"name": "angular"
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
122
|
"create-react-native-library": {
|
|
135
123
|
"type": "turbo-module",
|
|
136
124
|
"languages": "kotlin-objc",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PaymentChannel } from './index';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve which payment channel the bridge should hand to the native SDK as the
|
|
5
|
+
* default/pre-selected channel.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the web/iOS/Android SDKs so behaviour is consistent across platforms:
|
|
8
|
+
* • Returns `defaultChannel` when it is one of `paymentChannels`.
|
|
9
|
+
* • Otherwise returns the first channel in `paymentChannels`.
|
|
10
|
+
* • Returns null when `paymentChannels` is empty.
|
|
11
|
+
*
|
|
12
|
+
* Card is never hard-coded: it is used only when it is the configured default
|
|
13
|
+
* (and present in the list) or genuinely the first channel.
|
|
14
|
+
*
|
|
15
|
+
* Note: this React Native package is a thin bridge — it does not know which
|
|
16
|
+
* channels the backend marked active. "Available" here means the channels the
|
|
17
|
+
* merchant chose to offer (`paymentChannels`). The native SDK performs the
|
|
18
|
+
* further filtering by the backend's ACTIVE channels and makes the final
|
|
19
|
+
* selection, so this only guarantees the bridge never forwards a default that is
|
|
20
|
+
* inconsistent with the offered channels.
|
|
21
|
+
*/
|
|
22
|
+
export function resolveDefaultChannel(
|
|
23
|
+
paymentChannels: PaymentChannel[],
|
|
24
|
+
defaultChannel?: PaymentChannel | null
|
|
25
|
+
): PaymentChannel | null {
|
|
26
|
+
if (!paymentChannels || paymentChannels.length === 0) return null;
|
|
27
|
+
if (defaultChannel && paymentChannels.includes(defaultChannel)) {
|
|
28
|
+
return defaultChannel;
|
|
29
|
+
}
|
|
30
|
+
return paymentChannels[0] ?? null;
|
|
31
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { NativeEventEmitter, Platform } from 'react-native';
|
|
2
2
|
import NativeNetappspay from './NativeNetappspay';
|
|
3
|
+
import { resolveDefaultChannel } from './channelSelection';
|
|
4
|
+
|
|
5
|
+
export { resolveDefaultChannel } from './channelSelection';
|
|
3
6
|
|
|
4
7
|
// ── Types ──
|
|
5
8
|
|
|
@@ -30,8 +33,8 @@ export interface PaymentConfig {
|
|
|
30
33
|
narration: string;
|
|
31
34
|
/** Channels to display */
|
|
32
35
|
paymentChannels: PaymentChannel[];
|
|
33
|
-
/** Initially selected channel */
|
|
34
|
-
defaultChannel
|
|
36
|
+
/** Initially selected channel. Defaults to the first entry of `paymentChannels`. */
|
|
37
|
+
defaultChannel?: PaymentChannel;
|
|
35
38
|
/** Customer phone number */
|
|
36
39
|
phoneNumber?: string;
|
|
37
40
|
/** Address line 1 */
|
|
@@ -42,6 +45,7 @@ export interface PaymentConfig {
|
|
|
42
45
|
city?: string;
|
|
43
46
|
/** Custom key-value metadata */
|
|
44
47
|
metadata?: Record<string, any>;
|
|
48
|
+
mToken?: string;
|
|
45
49
|
/** Custom transaction reference */
|
|
46
50
|
transactionRef?: string;
|
|
47
51
|
/** Merchant display name */
|
|
@@ -146,7 +150,6 @@ function validateConfig(config: PaymentConfig): string | null {
|
|
|
146
150
|
if (typeof config.amount !== 'number' || config.amount <= 0) return "'amount' must be a positive number in minor units (e.g. 150000 for ₦1,500.00).";
|
|
147
151
|
if (!config.currency) return "'currency' is required (e.g. 'NGN').";
|
|
148
152
|
if (!config.paymentChannels?.length) return "'paymentChannels' must contain at least one channel (e.g. ['card', 'transfer']).";
|
|
149
|
-
if (!config.defaultChannel) return "'defaultChannel' is required (e.g. 'card').";
|
|
150
153
|
return null;
|
|
151
154
|
}
|
|
152
155
|
|
|
@@ -171,9 +174,21 @@ export function presentPayment(
|
|
|
171
174
|
return () => {};
|
|
172
175
|
}
|
|
173
176
|
|
|
177
|
+
// Reconcile the default channel against the offered channels so we never hand
|
|
178
|
+
// the native SDK a default that isn't in the list (e.g. defaultChannel:'card'
|
|
179
|
+
// when card isn't offered). The native SDK then further validates this against
|
|
180
|
+
// the backend's ACTIVE channels and selects the first active one if needed —
|
|
181
|
+
// this is what prevents a blank payment screen when card is disabled.
|
|
182
|
+
// De-duped first: a repeated channel renders the same tab N times natively.
|
|
183
|
+
const paymentChannels = [...new Set(config.paymentChannels)];
|
|
184
|
+
const resolvedDefaultChannel =
|
|
185
|
+
resolveDefaultChannel(paymentChannels, config.defaultChannel) ?? paymentChannels[0];
|
|
186
|
+
|
|
174
187
|
// Apply defaults for fields the API requires to be non-empty
|
|
175
188
|
const sanitizedConfig = {
|
|
176
189
|
...config,
|
|
190
|
+
paymentChannels,
|
|
191
|
+
defaultChannel: resolvedDefaultChannel,
|
|
177
192
|
fullName: config.fullName?.trim() || '',
|
|
178
193
|
address1: config.address1?.trim() || 'Customer Address',
|
|
179
194
|
city: config.city?.trim() || 'Lagos',
|