Skip to content

Feature(SDK-137): Add isSamsungPayAvailable API to check Samsung Pay readiness - #45

Merged
AbdulazizAlrabiah merged 1 commit into
mainfrom
feature/samsung-pay-availability-check
Aug 17, 2026
Merged

Feature(SDK-137): Add isSamsungPayAvailable API to check Samsung Pay readiness#45
AbdulazizAlrabiah merged 1 commit into
mainfrom
feature/samsung-pay-availability-check

Conversation

@sultan-algarbi

Copy link
Copy Markdown
Contributor

Description

Exposes a new public helper, isSamsungPayAvailable(serviceId), so apps building their own payment UI can check whether Samsung Pay is available and ready (set up and active) on the device before showing a Samsung Pay option or rendering the built-in button. Previously the native getSamsungPayStatus result was only used internally to toggle the button's visibility and was never surfaced to JS. The helper is backed by a new RTNSamsungPay TurboModule that mirrors the existing RTNDeviceLanguage module pattern and works on both the old and new RN architectures. It resolves true only when Samsung Pay is SPAY_READY, and false in every other case (non-Android, not supported, not set up, or any failure) — it never rejects, so callers always get a simple boolean.

Ticket #:

https://moyasar-team.atlassian.net/browse/SDK-137

How to test

  1. On a Samsung device with Samsung Pay set up and an active card: await isSamsungPayAvailable('<your Samsung service ID>') → resolves true.
  2. On a Samsung device where Samsung Pay is not set up / no card added → false.
  3. On a non-Samsung Android device (Samsung Pay not supported) → false.
  4. On iOS → false immediately (short-circuits without touching native).
  5. Pass an empty/blank serviceId → false (logs a clear error, skips the native call).
  6. Verify it builds and runs on BOTH architectures (new arch codegen must generate NativeRTNSamsungPaySpec, and old arch registers the module manually).

Deployment Notes

N/A — additive public API, no config, migrations, or breaking changes. iOS returns false since Samsung Pay is Android-only (tracked as a follow-up in SDK-137).

Suggested Plan for Review:

  1. src/specs/NativeRTNSamsungPay.ts — TurboModule spec (the JS↔native contract); start here to see the isSamsungPayAvailable(serviceId): Promise<boolean> signature.
  2. src/helpers/samsung_pay_availability.ts — public helper: Platform guard, blank-serviceId guard, null-module guard, and the native call wrapped so it never rejects.
  3. src/index.tsx — exports isSamsungPayAvailable from the package entry point.
  4. android/src/main/java/com/moyasarsdk/RTNSamsungPayModuleImpl.kt — the actual availability logic: builds PartnerInfo, calls getSamsungPayStatus, one-shot promise resolution, keeps the SamsungPay instance alive for the async callback.
  5. android/src/newarch/java/com/RTNSamsungPay.java — new-arch wrapper extending the codegen NativeRTNSamsungPaySpec.
  6. android/src/oldarch/java/com/RTNSamsungPay.java — old-arch wrapper (ReactContextBaseJavaModule + @ReactMethod).
  7. android/src/main/java/com/moyasarsdk/RTNMoyasarPackage.java — registers the module in getModule and getReactModuleInfoProvider.
  8. src/__tests__/helpers/samsung_pay_availability.test.ts — unit tests: ready/not-ready, non-Android, blank serviceId, and native rejection.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new public JS API to let host apps check whether Samsung Pay is available and ready on Android devices, backed by a dedicated native module implemented for both the old and new React Native architectures.

Changes:

  • Added a new TurboModule spec (RTNSamsungPay) and JS helper isSamsungPayAvailable(serviceId) that resolves a boolean and never rejects.
  • Implemented the Android native availability check (Samsung Pay status → true only for SPAY_READY) and wired it up for both architectures + package registration.
  • Added unit tests for the helper and exported the helper from the package entry point.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/specs/NativeRTNSamsungPay.ts Defines the TurboModule JS↔native contract and module lookup.
src/helpers/samsung_pay_availability.ts Public helper with platform/serviceId guards and safe boolean-only behavior.
src/index.tsx Exposes the new helper from the package entry point.
src/tests/helpers/samsung_pay_availability.test.ts Adds Jest tests for the helper’s platform/blank-id/native-error behavior.
android/src/main/java/com/moyasarsdk/RTNSamsungPayModuleImpl.kt Implements Samsung Pay readiness check and resolves boolean result.
android/src/newarch/java/com/RTNSamsungPay.java New-architecture wrapper module bridging to the shared implementation.
android/src/oldarch/java/com/RTNSamsungPay.java Old-architecture wrapper module bridging to the shared implementation.
android/src/main/java/com/moyasarsdk/RTNMoyasarPackage.java Registers the new module for lookup and TurboModule info provider.
Suppressed comments (1)

src/tests/helpers/samsung_pay_availability.test.ts:44

  • Same issue here: avoid assigning to Platform.OS directly; redefine it so the test compiles and works reliably.
  it('returns false on non-Android platforms without calling native', async () => {
    Platform.OS = 'ios';

    await expect(isSamsungPayAvailable(serviceId)).resolves.toBe(false);
    expect(nativeModule.isSamsungPayAvailable).not.toHaveBeenCalled();

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +16 to +21
beforeEach(() => {
jest.clearAllMocks();
Platform.OS = 'android';
// The helper logs via `console.error` in dev; keep test output clean.
jest.spyOn(console, 'error').mockImplementation(() => {});
});
Comment on lines +39 to +43
try {
if (!NativeRTNSamsungPay) {
errorLog('Moyasar SDK: Samsung Pay native module is not available');
return false;
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@AbdulazizAlrabiah
AbdulazizAlrabiah merged commit 1c44f0d into main Aug 17, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants