Skip to content

Commit a5a86ea

Browse files
Feat/add given + samsung pay (#27)
* feat: implement the native layer integration of Samsung Pay * feat: finalize samsung pay implementation (left backward compat) * feat: add support for merchant id and country code for samsung pay * feat: add samung pay sheet canceled detection * feat: add merchant country code (+ extra enhacements) * docs: fix currency code format typo * refactor: add copilot comments * feat: implement backward compatibility at native layer * fix: fix SP component config not found issue * fix: fix SP component config not found issue (Rename component) * fix: re-export files for ESM * fix: add react native field * fix: re-export files for CommonJS Should be a temp solution only * fix: make index file resolved relatively * feat: add optional given_id PaymentConfig To support idempotency * test: add unit tests * refactor: add copilot comments * refactor: modify comment and log * feat: update example app and trivial tweaks * fix: remove save_only field in TokenRequest
1 parent 2b79619 commit a5a86ea

45 files changed

Lines changed: 1359 additions & 240 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,6 @@ android/generated
8484

8585
# React Native Nitro Modules
8686
nitrogen/
87+
88+
# Kotlin
89+
**/.kotlin/sessions/

android/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def supportsNamespace() {
4141
}
4242

4343
android {
44+
4445
if (supportsNamespace()) {
4546
namespace "com.moyasarsdk"
4647

@@ -61,6 +62,7 @@ android {
6162

6263
buildFeatures {
6364
buildConfig true
65+
dataBinding true
6466
}
6567

6668
buildTypes {
@@ -106,6 +108,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
106108
dependencies {
107109
implementation "com.facebook.react:react-android"
108110
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
111+
implementation files('libs/samsungpay_2.22.00.jar')
109112
}
110113

111114
if (isNewArchitectureEnabled()) {
412 KB
Binary file not shown.
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1+
<manifest xmlns:tools="http://schemas.android.com/tools"
2+
xmlns:android="http://schemas.android.com/apk/res/android"
23
package="com.moyasarsdk">
4+
<queries>
5+
<package android:name="com.samsung.android.spay" />
6+
<package android:name="com.samsung.android.samsungpay.gear" />
7+
</queries>
8+
<application>
9+
<meta-data
10+
android:name="spay_sdk_api_level"
11+
android:value="2.22"
12+
tools:node="merge"/>
13+
</application>
314
</manifest>
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
1+
<!-- Looks like there are 2 manifests for supporting different AGP versions, see build.gradle 'supportsNamespace()' -->
2+
<manifest xmlns:tools="http://schemas.android.com/tools"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
<queries>
5+
<package android:name="com.samsung.android.spay" />
6+
<package android:name="com.samsung.android.samsungpay.gear" />
7+
</queries>
8+
<application>
9+
<meta-data
10+
android:name="spay_sdk_api_level"
11+
android:value="2.22"
12+
tools:node="merge"/>
13+
</application>
214
</manifest>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.moyasarsdk
2+
3+
import android.util.Log
4+
import com.moyasarsdk.BuildConfig
5+
6+
val isDebugLogsEnabled = false
7+
8+
class Logger {
9+
companion object {
10+
@JvmStatic
11+
fun d(tag: String, message: String) {
12+
if (BuildConfig.DEBUG && isDebugLogsEnabled) {
13+
Log.d(tag, message)
14+
}
15+
}
16+
17+
@JvmStatic
18+
fun i(tag: String, message: String) {
19+
if (BuildConfig.DEBUG) {
20+
Log.i(tag, message)
21+
}
22+
}
23+
24+
@JvmStatic
25+
fun w(tag: String, message: String, throwable: Throwable? = null) {
26+
if (BuildConfig.DEBUG) {
27+
Log.w(tag, message, throwable)
28+
} else {
29+
Log.w(tag, message)
30+
}
31+
}
32+
33+
@JvmStatic
34+
fun e(tag: String, message: String, throwable: Throwable? = null) {
35+
if (BuildConfig.DEBUG) {
36+
Log.e(tag, message, throwable)
37+
} else {
38+
Log.e(tag, message)
39+
}
40+
}
41+
}
42+
}

android/src/main/java/com/moyasarsdk/MoyasarSdkPackage.kt

Whitespace-only changes.

android/src/main/java/com/moyasarsdk/RTNDeviceLanguageImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import androidx.annotation.Nullable;
44
import com.facebook.react.bridge.ReactApplicationContext;
5+
import com.moyasarsdk.Logger;
56

67
public class RTNDeviceLanguageImpl {
78

89
protected static final String NAME = "RTNDeviceLanguage";
910

1011
@Nullable
1112
public String getPreferredLanguage(ReactApplicationContext reactContext) {
13+
Logger.d("MoyasarSDK", "getPreferredLanguage");
14+
1215
try {
1316
return reactContext.getResources().getConfiguration().locale.getLanguage();
1417
} catch (Exception e) {

android/src/main/java/com/moyasarsdk/RTNDeviceLanguagePackage.java

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.moyasarsdk;
2+
3+
import androidx.annotation.Nullable;
4+
import com.facebook.react.TurboReactPackage;
5+
import com.facebook.react.bridge.NativeModule;
6+
import com.facebook.react.bridge.ReactApplicationContext;
7+
import com.facebook.react.module.model.ReactModuleInfo;
8+
import com.facebook.react.module.model.ReactModuleInfoProvider;
9+
import com.facebook.react.ReactPackage;
10+
import com.facebook.react.uimanager.ViewManager;
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
import java.util.Collections;
14+
import java.util.List;
15+
import com.moyasarsdk.Logger;
16+
17+
public class RTNMoyasarPackage extends TurboReactPackage implements ReactPackage {
18+
19+
@Nullable
20+
@Override
21+
public NativeModule getModule(String name, ReactApplicationContext reactContext) {
22+
Logger.d("MoyasarSDK", "getModule");
23+
24+
if (name.equals(RTNDeviceLanguageImpl.NAME)) {
25+
return new RTNDeviceLanguage(reactContext);
26+
} else {
27+
return null;
28+
}
29+
}
30+
31+
@Override
32+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
33+
Logger.d("MoyasarSDK", "createViewManagers");
34+
return Collections.singletonList(new RTNSamsungPayButtonFragmentManager(reactContext));
35+
}
36+
37+
@Override
38+
public ReactModuleInfoProvider getReactModuleInfoProvider() {
39+
Logger.d("MoyasarSDK", "getReactModuleInfoProvider");
40+
41+
return () -> {
42+
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
43+
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
44+
45+
moduleInfos.put(
46+
RTNDeviceLanguageImpl.NAME,
47+
new ReactModuleInfo(
48+
RTNDeviceLanguageImpl.NAME,
49+
RTNDeviceLanguageImpl.NAME,
50+
false, // canOverrideExistingModule
51+
false, // needsEagerInit
52+
true, // hasConstants
53+
false, // isCxxModule
54+
isTurboModule // isTurboModule
55+
)
56+
);
57+
return moduleInfos;
58+
};
59+
}
60+
}

0 commit comments

Comments
 (0)