card-react-native 0.0.7

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.
Files changed (65) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +307 -0
  3. package/android/build.gradle +118 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/cardsdkreactnative/CardSdkReactNativePackage.kt +17 -0
  8. package/android/src/main/java/com/cardsdkreactnative/CardSdkReactNativeViewManager.kt +164 -0
  9. package/android/src/main/res/layout/cardview.xml +15 -0
  10. package/card-react-native.podspec +44 -0
  11. package/ios/CardSdkReactNative-Bridging-Header.h +2 -0
  12. package/ios/CardSdkReactNative.xcodeproj/project.pbxproj +283 -0
  13. package/ios/CardSdkReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  14. package/ios/CardSdkReactNativeViewManager.m +21 -0
  15. package/ios/CardSdkReactNativeViewManager.swift +137 -0
  16. package/lib/commonjs/index.js +147 -0
  17. package/lib/commonjs/index.js.map +1 -0
  18. package/lib/commonjs/models/config.js +6 -0
  19. package/lib/commonjs/models/config.js.map +1 -0
  20. package/lib/commonjs/models/enums/TapCurrencyCode.js +188 -0
  21. package/lib/commonjs/models/enums/TapCurrencyCode.js.map +1 -0
  22. package/lib/commonjs/models/enums/index.js +28 -0
  23. package/lib/commonjs/models/enums/index.js.map +1 -0
  24. package/lib/commonjs/models/enums/sdkEnums.js +70 -0
  25. package/lib/commonjs/models/enums/sdkEnums.js.map +1 -0
  26. package/lib/commonjs/models/index.js +39 -0
  27. package/lib/commonjs/models/index.js.map +1 -0
  28. package/lib/commonjs/models/types.js +2 -0
  29. package/lib/commonjs/models/types.js.map +1 -0
  30. package/lib/module/index.js +123 -0
  31. package/lib/module/index.js.map +1 -0
  32. package/lib/module/models/config.js +2 -0
  33. package/lib/module/models/config.js.map +1 -0
  34. package/lib/module/models/enums/TapCurrencyCode.js +181 -0
  35. package/lib/module/models/enums/TapCurrencyCode.js.map +1 -0
  36. package/lib/module/models/enums/index.js +3 -0
  37. package/lib/module/models/enums/index.js.map +1 -0
  38. package/lib/module/models/enums/sdkEnums.js +56 -0
  39. package/lib/module/models/enums/sdkEnums.js.map +1 -0
  40. package/lib/module/models/index.js +4 -0
  41. package/lib/module/models/index.js.map +1 -0
  42. package/lib/module/models/types.js +2 -0
  43. package/lib/module/models/types.js.map +1 -0
  44. package/lib/typescript/src/index.d.ts +46 -0
  45. package/lib/typescript/src/index.d.ts.map +1 -0
  46. package/lib/typescript/src/models/config.d.ts +114 -0
  47. package/lib/typescript/src/models/config.d.ts.map +1 -0
  48. package/lib/typescript/src/models/enums/TapCurrencyCode.d.ts +180 -0
  49. package/lib/typescript/src/models/enums/TapCurrencyCode.d.ts.map +1 -0
  50. package/lib/typescript/src/models/enums/index.d.ts +3 -0
  51. package/lib/typescript/src/models/enums/index.d.ts.map +1 -0
  52. package/lib/typescript/src/models/enums/sdkEnums.d.ts +48 -0
  53. package/lib/typescript/src/models/enums/sdkEnums.d.ts.map +1 -0
  54. package/lib/typescript/src/models/index.d.ts +4 -0
  55. package/lib/typescript/src/models/index.d.ts.map +1 -0
  56. package/lib/typescript/src/models/types.d.ts +5 -0
  57. package/lib/typescript/src/models/types.d.ts.map +1 -0
  58. package/package.json +163 -0
  59. package/src/index.tsx +194 -0
  60. package/src/models/config.ts +124 -0
  61. package/src/models/enums/TapCurrencyCode.ts +356 -0
  62. package/src/models/enums/index.ts +2 -0
  63. package/src/models/enums/sdkEnums.ts +54 -0
  64. package/src/models/index.ts +3 -0
  65. package/src/models/types.ts +16 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 mahmoudAllam
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.
package/README.md ADDED
@@ -0,0 +1,307 @@
1
+ # card-react-native
2
+
3
+ Tap Card SDK Wrapper
4
+
5
+ #Card-SDK
6
+
7
+ We at [Tap Payments](https://www.tap.company/) strive to make your payments easier than ever. We as a PCI compliant company, provide you a from the self solution to process card payments in your iOS apps.
8
+
9
+ # Get your Tap keys
10
+
11
+ You can always use the example keys within our example app, but we do recommend you to head to our [onboarding](https://register.tap.company/sell) page. You will need to register your `bundle id` to get your `Tap Key` that you will need to activate our `Card SDK`.
12
+
13
+ # Installation
14
+
15
+ We got you covered, `TapCardSDK` can be installed with all possible technologies.
16
+
17
+ ## Node modules
18
+
19
+ ```sh
20
+ npm install card-react-native
21
+ ```
22
+
23
+ ```sh
24
+ yarn install card-react-native
25
+ ```
26
+
27
+ Then run in your terminal
28
+
29
+ ```swift
30
+ cd ios
31
+ pod install
32
+ pod update
33
+ ```
34
+
35
+ ## Documentation
36
+
37
+ To make our sdk as dynamic as possible, we do accept many configurations as input. Let us start by declaring them and explaining the structure and the usage of each.
38
+
39
+ ```js
40
+ /**
41
+
42
+ Creates a configuration model to be passed to the SDK
43
+
44
+ - Parameters:
45
+
46
+ - publicKey: The Tap public key
47
+
48
+ - scope: The scope of the card sdk. Default is generating a tap token
49
+
50
+ - purpose: The intended purpose of using the generated token afterwards.
51
+
52
+ - merchant: The Tap merchant details
53
+
54
+ - transaction: The transaction details
55
+
56
+ - order: The tap order id
57
+
58
+ - invoice: Link this token to an invoice
59
+
60
+ - customer: The Tap customer details
61
+
62
+ - acceptance: The acceptance details for the transaction
63
+
64
+ - fields: Defines the fields visibility
65
+
66
+ - addons: Defines some UI/UX addons enablement
67
+
68
+ - interface: Defines some UI related configurations
69
+
70
+ */
71
+ ```
72
+
73
+ | Configuration | Description | Required | Type | Sample |
74
+ | ------------- | ---------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
75
+ | publicKey | This is the `Tap Key` that you will get after registering you bundle id. | True | `String` | `let publicKey = "key"` |
76
+ | scope | Defines the intention of using the `TapCardSDK`. | True | `Scope` enum | ` let scope:Scope = .Token //This means you will get a Tap token to use afterwards` OR ` let scope:Scope = .Authenticate //This means you will get an authenticated Tap token to use in our charge api right away` |
77
+ | merchant | This is the `Merchant id` that you will get after registering you bundle id. | True | `Merchant` | ` let merchant: { id: ''}` |
78
+ | purpose | Defines the intention of using the `Token` after generation. | True | `String` | ` let purpose:String = "PAYMENT_TRANSACTION" //Using the token for a single charge.` OR ` let purpose:String = "RECURRING_TRANSACTION" //Using the token for multiple recurring charges.` OR ` let purpose:String = "INSTALLMENT_TRANSACTION" //Using the token for a charge that is a part of an installement plan.` OR ` let purpose:String = "ADD_CARD" //Using the token for a save a card for a customer.` OR ` let purpose:String = "CARDHOLDER_VERIFICATION" //Using the token for to verify the ownership of the card.` |
79
+ | transaction | Needed to define the amount and the currency, if you are generating an authenticated token. | False | `Transaction` | ` let transaction = { metadata: {}, reference: A reference to this transaciton in your system,` |
80
+ | customer | The customer details you want to attach to this tokenization process. | True | `Customer` | ` let customer = {nameOnCard: 'Tap Payments',editable: true,id: '',name: [ { first: 'Tap', lang: Locale.en, middle: '', last: 'Payments', },],contact: { phone: { number: '88888888', countryCode: '+965', }, email: 'tappayments@tap.company'},` |
81
+ | post | This is the `webhook` for your server, if you want us to update you server to server. | False | `Post` | ` let post = {url:""}` |
82
+ | acceptance | The acceptance details for the transaction. Including, which card brands and types you want to allow for the customer to tokenize. | False | `Acceptance` | ` let acceptance = {supportedBrands: [ SupportedBrands.AMEX, SupportedBrands.MASTERCARD, SupportedBrands.VISA, SupportedBrands.MADA,],supportedCards: [SupportedCards.Debit, SupportedCards.Credit]},` |
83
+ | order | This is the `Tap order id` that you created before and want to attach this token to it if any. | False | `Order` | ` let order = {id:"", amount: 1, currency: TapCurrencyCode.SAR, description: ''}` |
84
+ | invoice | This is the `invoice id` that you want to link this token to if any. | False | `Invoice` | ` let invoice:Invoice = {id:""}` |
85
+ | fields | Needed to define visibility of the optional fields in the card form. | False | `Fields` | ` let fields = {cardHolder: true}` |
86
+ | addons | Needed to define the enabling of some extra features on top of the basic card form. | False | `Addons` | ` let addons = { displayPaymentBrands: true, loader: true, saveCard: true }` `/**- displayPaymentBrands: Defines to show the supported card brands logos - loader: Defines to show a loader on top of the card when it is in a processing state - scanner: Defines whether to enable card scanning functionality or not*/` |
87
+ | interface | Needed to defines look and feel related configurations. | False | `Interface` | ` let interface = {locale: Locale.en,theme: Theme.dark,edges: Edges.curved,direction: Direction.ltr},` |
88
+ | perator | Operator publicKey. | False | `Operator` | ` let operator = {publicKey: "key"},` |
89
+
90
+ ## Initialisation of the input
91
+
92
+ ### Initialise Config
93
+
94
+ You can create a model from our defined structure to pass it afterwards to our `TapCardSDK` as a configuration.
95
+
96
+ ```Ts
97
+ const generateTransactionId = () => {
98
+ let result = '';
99
+ const characters =
100
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
101
+ const charactersLength = characters.length;
102
+ let counter = 0;
103
+ while (counter < 23) {
104
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
105
+ counter += 1;
106
+ }
107
+ return result;
108
+ };
109
+
110
+ const generateOrderId = () => {
111
+ let result = '';
112
+ const characters = '0123456789';
113
+ const charactersLength = characters.length;
114
+ let counter = 0;
115
+ while (counter < 17) {
116
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
117
+ counter += 1;
118
+ }
119
+ return result;
120
+ };
121
+ var config: Config = {
122
+ publicKey: 'pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7',
123
+ merchant: {
124
+ id: '',
125
+ },
126
+ transaction: {
127
+ metadata: {},
128
+ reference: `tck_LV${generateTransactionId()}`,
129
+ },
130
+ order: {
131
+ id: `${generateOrderId()}`,
132
+ amount: 1,
133
+ currency: TapCurrencyCode.SAR,
134
+ description: '',
135
+ },
136
+ invoice: {
137
+ id: 'Map to authenticate.reference.invoice',
138
+ },
139
+ post: {
140
+ url: 'Map to authenticate.reference.post',
141
+ },
142
+ purpose: 'PAYMENT_TRANSACTION',
143
+ operator: {
144
+ publicKey: 'pk_test_YhUjg9PNT8oDlKJ1aE2fMRz7',
145
+ },
146
+ scope: Scope.Authenticate,
147
+ customer: {
148
+ nameOnCard: 'Tap Payments',
149
+ editable: true,
150
+ id: '',
151
+ name: [
152
+ {
153
+ first: 'Tap',
154
+ lang: Locale.en,
155
+ middle: '',
156
+ last: 'Payments',
157
+ },
158
+ ],
159
+ contact: {
160
+ phone: {
161
+ number: '88888888',
162
+ countryCode: '+965',
163
+ },
164
+ email: 'tappayments@tap.company',
165
+ },
166
+ },
167
+ acceptance: {
168
+ supportedBrands: [
169
+ SupportedBrands.AMEX,
170
+ SupportedBrands.MASTERCARD,
171
+ SupportedBrands.VISA,
172
+ SupportedBrands.MADA,
173
+ ],
174
+ supportedCards: [SupportedCards.Debit, SupportedCards.Credit],
175
+ },
176
+ fields: {
177
+ cardHolder: true,
178
+ },
179
+ addons: {
180
+ displayPaymentBrands: true,
181
+ loader: true,
182
+ saveCard: true,
183
+ },
184
+ interface: {
185
+ locale: Locale.en,
186
+ theme: Theme.dark,
187
+ edges: Edges.curved,
188
+ direction: Direction.ltr,
189
+ },
190
+ }
191
+ ```
192
+
193
+ # Initializing the TapCardSDK form
194
+
195
+ ```ts
196
+ import TapCardView, {
197
+ TapCurrencyCode,
198
+ type Config,
199
+ Locale,
200
+ SupportedBrands,
201
+ SupportedCards,
202
+ Theme,
203
+ Edges,
204
+ Direction,
205
+ Scope,
206
+ type ITapCardViewInputRef,
207
+ } from 'card-react-native';
208
+
209
+ const tapCardRef =
210
+ React.useRef<ITapCardViewInputRef>() as MutableRefObject<ITapCardViewInputRef>;
211
+
212
+ <TapCardView
213
+ ref={tapCardRef}
214
+ style={{ width: '100%' }}
215
+ config={config}
216
+ onSuccess={(tokenValue) => {}}
217
+ onHeightChange={(height) => {}}
218
+ onReady={() => {}}
219
+ onFocus={() => {}}
220
+ onBinIdentification={(binIdentification: Object) => {}}
221
+ onInvalidInput={(invalidInput: boolean) => {}}
222
+ onError={(error: object) => {}}
223
+ />;
224
+ ```
225
+
226
+ # TapCardView Callbacks
227
+
228
+ callbacks that allows integrators to get notified from events fired from the `TapCardView`.
229
+
230
+ ```Ts
231
+ @objc public protocol TapCardViewDelegate {
232
+ /// Will be fired whenever the card is rendered and loaded
233
+ onReady={() => {}}
234
+ /// Will be fired once the user focuses any of the card fields
235
+ onFocus={() => {}}
236
+ /// Will be fired once we detect the brand and related issuer data for the entered card data
237
+ /** - Parameter data: will include the data in JSON format. example :
238
+ *{
239
+ "bin": "424242",
240
+ "bank": "",
241
+ "card_brand": "VISA",
242
+ "card_type": "CREDIT",
243
+ "card_category": "",
244
+ "card_scheme": "VISA",
245
+ "country": "GB",
246
+ "address_required": false,
247
+ "api_version": "V2",
248
+ "issuer_id": "bnk_TS02A5720231337s3YN0809429",
249
+ "brand": "VISA"
250
+ }* */
251
+ onBinIdentification={(binIdentification: Object) => {}}
252
+ /// Will be fired whenever the validity of the card data changes.
253
+ /// - Parameter invalid: Will be true if the card data is invalid and false otherwise.
254
+ onInvalidInput={(invalidInput: boolean) => {}}
255
+ /**
256
+ Will be fired whenever the card sdk finishes successfully the task assigned to it. Whether `TapToken` or `AuthenticatedToken`
257
+ - Parameter data: will include the data in JSON format. For `TapToken`:
258
+ {
259
+ "id": "tok_MrL97231045SOom8cF8G939",
260
+ "created": 1694169907939,
261
+ "object": "token",
262
+ "live_mode": false,
263
+ "type": "CARD",
264
+ "source": "CARD-ENCRYPTED",
265
+ "used": false,
266
+ "card": {
267
+ "id": "card_d9Vj7231045akVT80B8n944",
268
+ "object": "card",
269
+ "address": {},
270
+ "funding": "CREDIT",
271
+ "fingerprint": "gRkNTnMrJPtVYkFDVU485Gc%2FQtEo%2BsV44sfBLiSPM1w%3D",
272
+ "brand": "VISA",
273
+ "scheme": "VISA",
274
+ "category": "",
275
+ "exp_month": 4,
276
+ "exp_year": 24,
277
+ "last_four": "4242",
278
+ "first_six": "424242",
279
+ "name": "AHMED",
280
+ "issuer": {
281
+ "bank": "",
282
+ "country": "GB",
283
+ "id": "bnk_TS07A0720231345Qx1e0809820"
284
+ }
285
+ },
286
+ "url": ""
287
+ }
288
+ */
289
+ onSuccess={(tokenValue) => {}}
290
+ /// Will be fired whenever there is an error related to the card connectivity or apis
291
+ /// - Parameter data: includes a JSON format for the error description and error
292
+ onError={(error: object) => {}}
293
+ /// Will be fired whenever the card element changes its height for your convience
294
+ /// - Parameter height: The new needed height
295
+ onHeightChange={(height) => {}}
296
+
297
+ }
298
+ ```
299
+
300
+ # Tokenize the card
301
+
302
+ Once you get notified that the `TapCardView` now has a valid input from the callback. You can start the tokenization process by calling the public interface:
303
+
304
+ ```swift
305
+ /// Wil start the process of generating a `TapToken` with the current card data
306
+ tapCardRef.current.generateToken();
307
+ ```
@@ -0,0 +1,118 @@
1
+ buildscript {
2
+ // Buildscript is evaluated before everything else so we can't use getExtOrDefault
3
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["CardSdkReactNative_kotlinVersion"]
4
+
5
+ repositories {
6
+ google()
7
+ mavenCentral()
8
+ }
9
+
10
+ dependencies {
11
+ classpath "com.android.tools.build:gradle:7.2.1"
12
+ // noinspection DifferentKotlinGradleVersion
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14
+ }
15
+ }
16
+
17
+ def isNewArchitectureEnabled() {
18
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
19
+ }
20
+
21
+ apply plugin: "com.android.library"
22
+ apply plugin: "kotlin-android"
23
+
24
+
25
+ def appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') }
26
+
27
+ rootProject.allprojects {
28
+ repositories {
29
+ google()
30
+ mavenCentral()
31
+ jcenter()
32
+ maven { url 'https://jitpack.io' }
33
+ }
34
+ }
35
+
36
+ if (isNewArchitectureEnabled()) {
37
+ apply plugin: "com.facebook.react"
38
+ }
39
+
40
+ def getExtOrDefault(name) {
41
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["CardSdkReactNative_" + name]
42
+ }
43
+
44
+ def getExtOrIntegerDefault(name) {
45
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["CardSdkReactNative_" + name]).toInteger()
46
+ }
47
+
48
+ def supportsNamespace() {
49
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
50
+ def major = parsed[0].toInteger()
51
+ def minor = parsed[1].toInteger()
52
+
53
+ // Namespace support was added in 7.3.0
54
+ if (major == 7 && minor >= 3) {
55
+ return true
56
+ }
57
+
58
+ return major >= 8
59
+ }
60
+
61
+ android {
62
+ if (supportsNamespace()) {
63
+ namespace "com.cardsdkreactnative"
64
+
65
+ sourceSets {
66
+ main {
67
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
68
+ }
69
+ }
70
+ }
71
+
72
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
73
+
74
+ defaultConfig {
75
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
76
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
77
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
78
+ }
79
+ buildTypes {
80
+ release {
81
+ minifyEnabled false
82
+ }
83
+ }
84
+
85
+ lintOptions {
86
+ disable "GradleCompatible"
87
+ }
88
+
89
+ compileOptions {
90
+ sourceCompatibility JavaVersion.VERSION_1_8
91
+ targetCompatibility JavaVersion.VERSION_1_8
92
+ }
93
+
94
+ }
95
+
96
+ repositories {
97
+ mavenCentral()
98
+ google()
99
+ }
100
+
101
+ def kotlin_version = getExtOrDefault("kotlinVersion")
102
+
103
+ dependencies {
104
+ // For < 0.71, this will be from the local maven repo
105
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
106
+ //noinspection GradleDynamicVersion
107
+ implementation "com.facebook.react:react-native:+"
108
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
109
+ implementation 'com.github.Tap-Payments:Card-Android:0.0.24'
110
+ }
111
+
112
+ if (isNewArchitectureEnabled()) {
113
+ react {
114
+ jsRootDir = file("../src/")
115
+ libraryName = "CardSdkReactNativeView"
116
+ codegenJavaPackageName = "com.cardsdkreactnative"
117
+ }
118
+ }
@@ -0,0 +1,5 @@
1
+ CardSdkReactNative_kotlinVersion=1.7.0
2
+ CardSdkReactNative_minSdkVersion=21
3
+ CardSdkReactNative_targetSdkVersion=31
4
+ CardSdkReactNative_compileSdkVersion=31
5
+ CardSdkReactNative_ndkversion=21.4.7075529
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.cardsdkreactnative">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,17 @@
1
+ package com.cardsdkreactnative
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+
9
+ class CardSdkReactNativePackage : ReactPackage {
10
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
11
+ return emptyList()
12
+ }
13
+
14
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
15
+ return listOf(CardSdkReactNativeViewManager())
16
+ }
17
+ }
@@ -0,0 +1,164 @@
1
+ package com.cardsdkreactnative
2
+
3
+ import android.util.Log
4
+ import android.view.LayoutInflater
5
+ import android.view.View
6
+ import com.facebook.react.bridge.Arguments
7
+ import com.facebook.react.bridge.ReactContext
8
+ import com.facebook.react.bridge.ReadableArray
9
+ import com.facebook.react.bridge.ReadableMap
10
+ import com.facebook.react.common.MapBuilder
11
+ import com.facebook.react.uimanager.SimpleViewManager
12
+ import com.facebook.react.uimanager.ThemedReactContext
13
+ import com.facebook.react.uimanager.annotations.ReactProp
14
+ import com.facebook.react.uimanager.events.RCTEventEmitter
15
+ import company.tap.tapcardformkit.open.TapCardStatusDelegate
16
+ import company.tap.tapcardformkit.open.web_wrapper.TapCardConfiguration
17
+ import company.tap.tapcardformkit.open.web_wrapper.TapCardKit
18
+
19
+
20
+ class CardSdkReactNativeViewManager : SimpleViewManager<View>() {
21
+ val GENERATE_TOKEN = 3
22
+
23
+ lateinit var customView: TapCardKit
24
+ override fun getName() = "CardSdkReactNativeView"
25
+
26
+ override fun createViewInstance(reactContext: ThemedReactContext): View {
27
+ // init view
28
+ // add as subview
29
+ var testView = LayoutInflater.from(reactContext).inflate(R.layout.cardview, null)
30
+ customView = testView.findViewById(R.id.tapCardForm)
31
+ Log.e("configTest", "render")
32
+ return testView
33
+ }
34
+
35
+
36
+ override fun getCommandsMap(): MutableMap<String, Int>? {
37
+ return MapBuilder.of(
38
+ "generateToken",
39
+ GENERATE_TOKEN
40
+ );
41
+ }
42
+
43
+
44
+ override fun receiveCommand(root: View, commandId: Int, args: ReadableArray?) {
45
+ Log.e("configTest","receiveCommand")
46
+ if( commandId == GENERATE_TOKEN) {
47
+ customView.generateTapToken()
48
+ }
49
+ }
50
+
51
+
52
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
53
+ return MapBuilder.of(
54
+ "onHeightChange",MapBuilder.of("registrationName","onHeightChange"),
55
+ "onSuccess", MapBuilder.of("registrationName","onSuccess"),
56
+ "onReadyCallback", MapBuilder.of("registrationName","onReadyCallback"),
57
+ "onFocusCallback", MapBuilder.of("registrationName","onFocusCallback"),
58
+ "onBinIdentification", MapBuilder.of("registrationName","onBinIdentification"),
59
+ "onInvalidInput", MapBuilder.of("registrationName","onInvalidInput"),
60
+ "onError", MapBuilder.of("registrationName","onError"),
61
+ )
62
+ }
63
+ @ReactProp(name = "config")
64
+ fun setConfig(view: View, config: ReadableMap) {
65
+ print(config.toString())
66
+
67
+ TapCardConfiguration.configureWithTapCardDictionaryConfiguration(view.context, customView ,config.toHashMap(), object : TapCardStatusDelegate{
68
+
69
+ override fun onHeightChange(heightChange: String) {
70
+ // view.layoutParams.height = 95
71
+ // var webview = customView.webViewFrame.findViewById<WebView>(R.id.webview)
72
+ // webview.layoutParams.height = 95
73
+ //
74
+ // Log.e("configTest webview",webview.height.toString())
75
+ //
76
+ // val newHeight =95
77
+ // val params: ViewGroup.LayoutParams? = customView.webViewFrame.layoutParams
78
+ // params?.height = customView.webViewFrame.context.getDimensionsInDp(newHeight?.toInt() ?: 95)
79
+ // webview.layoutParams = params
80
+
81
+ // Log.e("configTest webview",webview.height.toString())
82
+
83
+ Log.e("configTest",heightChange.toString())
84
+ val event = Arguments.createMap().apply {
85
+ putInt("data", heightChange.toInt())
86
+ }
87
+ val reactContext = view.context as ReactContext
88
+ reactContext
89
+ .getJSModule(RCTEventEmitter::class.java)
90
+ .receiveEvent(view.id, "onHeightChange", event)
91
+ }
92
+
93
+ override fun onBindIdentification(data: String) {
94
+ val event = Arguments.createMap().apply {
95
+ putString("data", data)
96
+ }
97
+ val reactContext = view.context as ReactContext
98
+ reactContext
99
+ .getJSModule(RCTEventEmitter::class.java)
100
+ .receiveEvent(view.id, "onBinIdentification", event)
101
+ Log.e("configTest", data)
102
+ }
103
+
104
+ override fun onError(error: String) {
105
+ val event = Arguments.createMap().apply {
106
+ putString("data", error)
107
+ }
108
+ val reactContext = view.context as ReactContext
109
+ reactContext
110
+ .getJSModule(RCTEventEmitter::class.java)
111
+ .receiveEvent(view.id, "onError", event)
112
+ Log.e("configTest", error)
113
+ }
114
+
115
+ override fun onFocus() {
116
+ val event = Arguments.createMap().apply {
117
+ putString("data","")
118
+ }
119
+ val reactContext = view.context as ReactContext
120
+ reactContext
121
+ .getJSModule(RCTEventEmitter::class.java)
122
+ .receiveEvent(view.id, "onFocusCallback", event)
123
+ Log.e("configTest", "onFocus")
124
+ }
125
+
126
+ override fun onReady() {
127
+ val event = Arguments.createMap().apply {
128
+ putString("data","")
129
+ }
130
+ val reactContext = view.context as ReactContext
131
+ reactContext
132
+ .getJSModule(RCTEventEmitter::class.java)
133
+ .receiveEvent(view.id, "onReadyCallback", event)
134
+ Log.e("configTest", "onReady")
135
+ }
136
+
137
+ override fun onSuccess(data: String) {
138
+ val event = Arguments.createMap().apply {
139
+ putString("data",data)
140
+ }
141
+ val reactContext = view.context as ReactContext
142
+ reactContext
143
+ .getJSModule(RCTEventEmitter::class.java)
144
+ .receiveEvent(view.id, "onSuccess", event)
145
+ Log.e("configTest", data)
146
+ }
147
+
148
+ override fun onValidInput(isValid: String) {
149
+ Log.e("configTest", isValid)
150
+ val event = Arguments.createMap().apply {
151
+ putBoolean("data",!isValid.toBoolean())
152
+ }
153
+ val reactContext = view.context as ReactContext
154
+ reactContext
155
+ .getJSModule(RCTEventEmitter::class.java)
156
+ .receiveEvent(view.id, "onInvalidInput", event)
157
+ // customView.generateTapToken()
158
+ }
159
+
160
+ })
161
+ // customView.init()
162
+ // view.setBackgroundColor(Color.parseColor(color))
163
+ }
164
+ }
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:app="http://schemas.android.com/apk/res-auto"
4
+ android:layout_width="match_parent"
5
+ android:orientation="vertical"
6
+ android:layout_height="wrap_content">
7
+ <company.tap.tapcardformkit.open.web_wrapper.TapCardKit
8
+ android:id="@+id/tapCardForm"
9
+ android:layout_width="match_parent"
10
+ android:layout_height="wrap_content"
11
+ app:layout_constraintEnd_toEndOf="parent"
12
+ app:layout_constraintStart_toStartOf="parent"
13
+ app:layout_constraintTop_toTopOf="parent" />
14
+ </LinearLayout>
15
+