Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ dependencies {
implementation("com.stripe:financial-connections:$stripe_version") {
exclude group: 'androidx.emoji2', module: 'emoji2'
}
implementation("com.stripe:connect:$stripe_version")
implementation('androidx.emoji2:emoji2:1.3.0').force // Avoid using 1.4.0 since that requires targetSdkVersion 34
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
Expand Down
7 changes: 6 additions & 1 deletion android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
package="com.reactnativestripesdk">

<application>
<activity
<activity
android:name=".CustomPaymentMethodActivity"
android:theme="@style/Theme.StripeReactNative.Transparent"
android:exported="false"
android:launchMode="singleTop"
android:excludeFromRecents="true"
android:noHistory="true" />

<provider
android:name=".StripeSdkContentProvider"
android:authorities="com.reactnativestripesdk.initializationprovider"
android:exported="false" />
</application>
</manifest>

Choose a reason for hiding this comment

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

Let's cleanup logs in this file. I don't think they are valuable.

Choose a reason for hiding this comment

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

Let's cleanup all logs in this file, and the log function. I don't think they are valuable.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.reactnativestripesdk

import android.app.Activity
import android.app.Application
import android.content.ContentProvider
import android.content.ContentValues
import android.database.Cursor
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import com.stripe.android.connect.EmbeddedComponentManager

class StripeSdkContentProvider : ContentProvider() {
override fun onCreate(): Boolean {
(context?.applicationContext as Application).registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks {
override fun onActivityCreated(
activity: Activity,
savedInstanceState: Bundle?
) {
if (activity is ComponentActivity) {
EmbeddedComponentManager.onActivityCreate(activity)
}
}

override fun onActivityDestroyed(activity: Activity) {
}

override fun onActivityPaused(activity: Activity) {
}

override fun onActivityResumed(activity: Activity) {
}

override fun onActivitySaveInstanceState(
activity: Activity,
outState: Bundle
) {
}

override fun onActivityStarted(activity: Activity) {
}

override fun onActivityStopped(activity: Activity) {
}

})
return true
}

override fun query(
p0: Uri,
p1: Array<out String?>?,
p2: String?,
p3: Array<out String?>?,
p4: String?
): Cursor? = null

override fun getType(p0: Uri): String? = null

override fun insert(p0: Uri, p1: ContentValues?): Uri? = null

override fun delete(
p0: Uri,
p1: String?,
p2: Array<out String?>?
): Int = 0

override fun update(
p0: Uri,
p1: ContentValues?,
p2: String?,
p3: Array<out String?>?
): Int = 0
}

Choose a reason for hiding this comment

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

Same. Please cleanup logs, unless @gimenete-stripe wants to keep some of them.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import com.stripe.android.model.SetupIntent
import com.stripe.android.model.Token
import com.stripe.android.payments.bankaccount.CollectBankAccountConfiguration
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.connect.EmbeddedComponentManager
import com.stripe.android.connect.StripeComponentController
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -97,6 +99,8 @@ class StripeSdkModule(

internal var composeCompatView: StripeAbstractComposeView.CompatView? = null

private var embeddedComponentManager: EmbeddedComponentManager? = null

// If you create a new Fragment, you must put the tag here, otherwise result callbacks for that
// Fragment will not work on RN < 0.65
private val allStripeFragmentTags: List<String>
Expand Down Expand Up @@ -131,11 +135,6 @@ class StripeSdkModule(
it,
)
createPlatformPayPaymentMethodPromise = null
} ?: run {
Log.d(
"StripeReactNative",
"No promise was found, Google Pay result went unhandled,",
)
}
}

Expand Down Expand Up @@ -277,6 +276,39 @@ class StripeSdkModule(
}
}

@ReactMethod
override fun presentAccountOnboardingScreen(
options: ReadableMap,
promise: Promise,
) {
getCurrentActivityOrResolveWithError(promise)?.let { activity ->
try {
if (embeddedComponentManager == null) {
// Create the manager outside of the UI thread to keep initialization lightweight.
embeddedComponentManager = EmbeddedComponentManager(
publishableKey = this.publishableKey
)
}

val accountOnboardingController = embeddedComponentManager!!.createAccountOnboardingController(activity)
val delegate = AccountOnboardingDelegate(promise)
accountOnboardingController.listener = delegate
accountOnboardingController.onDismissListener = delegate

UiThreadUtil.runOnUiThread {
// Only invoke the presentation on the UI thread to avoid unnecessary main-thread work.
try {
accountOnboardingController.show()
} catch (e: Exception) {
promise.resolve(createError(ErrorType.Failed.toString(), e.message))
}
}
} catch (e: Exception) {
promise.resolve(createError(ErrorType.Failed.toString(), e.message))
}
}
}

@ReactMethod
override fun confirmPaymentSheetPayment(promise: Promise) {
if (paymentSheetFragment == null) {
Expand Down Expand Up @@ -1407,3 +1439,24 @@ class StripeSdkModule(
const val NAME = NativeStripeSdkModuleSpec.NAME
}
}

class AccountOnboardingDelegate(
private val promise: Promise
) : com.stripe.android.connect.AccountOnboardingListener, StripeComponentController.OnDismissListener {

override fun onExit() {
promise.resolve(Arguments.createMap())
}

override fun onLoadError(error: Throwable) {
promise.reject("account_onboarding_error", error.message, error)
}

override fun onLoaderStart() {

}

override fun onDismiss() {
promise.resolve(Arguments.createMap())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ protected final void emitOnCustomPaymentMethodConfirmHandlerCallback(ReadableMap
@DoNotStrip
public abstract void presentPaymentSheet(ReadableMap options, Promise promise);

@ReactMethod
@DoNotStrip
public abstract void presentAccountOnboardingScreen(ReadableMap options, Promise promise);

@ReactMethod
@DoNotStrip
public abstract void confirmPaymentSheetPayment(Promise promise);
Expand Down
13 changes: 11 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,7 @@ PODS:
- Stripe (~> 24.23.0)
- stripe-react-native/NewArch (= 0.51.0)
- StripeApplePay (~> 24.23.0)
- StripeConnect (~> 24.23.0)
- StripeFinancialConnections (~> 24.23.0)
- StripePayments (~> 24.23.0)
- StripePaymentSheet (~> 24.23.0)
Expand Down Expand Up @@ -1741,6 +1742,7 @@ PODS:
- ReactCommon/turbomodule/core
- Stripe (~> 24.23.0)
- StripeApplePay (~> 24.23.0)
- StripeConnect (~> 24.23.0)
- StripeFinancialConnections (~> 24.23.0)
- StripePayments (~> 24.23.0)
- StripePaymentSheet (~> 24.23.0)
Expand Down Expand Up @@ -1768,13 +1770,18 @@ PODS:
- ReactCommon/turbomodule/core
- Stripe (~> 24.23.0)
- StripeApplePay (~> 24.23.0)
- StripeConnect (~> 24.23.0)
- StripeFinancialConnections (~> 24.23.0)
- StripePayments (~> 24.23.0)
- StripePaymentSheet (~> 24.23.0)
- StripePaymentsUI (~> 24.23.0)
- Yoga
- StripeApplePay (24.23.0):
- StripeCore (= 24.23.0)
- StripeConnect (24.23.0):
- StripeCore (= 24.23.0)
- StripeFinancialConnections (= 24.23.0)
- StripeUICore (= 24.23.0)
- StripeCore (24.23.0)
- StripeFinancialConnections (24.23.0):
- StripeCore (= 24.23.0)
Expand Down Expand Up @@ -1880,6 +1887,7 @@ SPEC REPOS:
- SocketRocket
- Stripe
- StripeApplePay
- StripeConnect
- StripeCore
- StripeFinancialConnections
- StripePayments
Expand Down Expand Up @@ -2110,15 +2118,16 @@ SPEC CHECKSUMS:
RNScreens: 0d4cb9afe052607ad0aa71f645a88bb7c7f2e64c
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Stripe: 2306d32be47f9632942f3385e9c2bad31d6ddcab
stripe-react-native: d95f5aa4e5a2d4a0edc8b3ea06e3a55d33ad31eb
stripe-react-native: bab68a3371228fb369e3ef0f600c4dea621b00de
StripeApplePay: edf515972406df57bd860d5f00416a552be6a450
StripeConnect: 49bac1ebdbbedf27372425f2b7a1241ca8c9ba32
StripeCore: ff6173a175acc7c4c25acc7cfabbade717dbc4de
StripeFinancialConnections: 34a90401657135130fe5bfd93db5ac27c001ec65
StripePayments: 9efe7bd14cae1821dba13997e12e070dfb38610b
StripePaymentSheet: 1c04531a7eff2c721736fc7d433ee342a59fae0e
StripePaymentsUI: 1cd35149b88de69c3364b4d1d4bb28c653c7d626
StripeUICore: 539e667170d9c5c86c02a9c63f320d132c7c1b73
Yoga: 9b7fb56e7b08cde60e2153344fa6afbd88e5d99f
Yoga: afd04ff05ebe0121a00c468a8a3c8080221cb14c

PODFILE CHECKSUM: a2ed964678852d4cc306ff4add3e4fa90be77ea6

Expand Down
7 changes: 6 additions & 1 deletion example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ import EmbeddedPaymentElementImmediateActionScreen from './screens/EmbeddedPayme
import EmbeddedPaymentElementConfirmScreen from './screens/EmbeddedPaymentElementConfirmScreen';
import CustomerSheetScreen from './screens/CustomerSheetScreen';
import RevolutPayScreen from './screens/RevolutPayScreen';
import type { EmbeddedPaymentElementResult } from '@stripe/stripe-react-native';
import { type EmbeddedPaymentElementResult } from '@stripe/stripe-react-native';
import PaymentSheetWithPmoSfuScreen from './screens/PaymentSheetWithPmoSfuScreen';
import AccountOnboardingScreen from './screens/AccountOnboardingScreen';

const Stack = createNativeStackNavigator<RootStackParamList>();

Expand Down Expand Up @@ -275,6 +276,10 @@ export default function App() {
name="PaymentSheetWithPmoSfuScreen"
component={PaymentSheetWithPmoSfuScreen}
/>
<Stack.Screen
name="AccountOnboardingScreen"
component={AccountOnboardingScreen}
/>
</Stack.Navigator>
</NavigationContainer>
</>
Expand Down
5 changes: 5 additions & 0 deletions example/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Alert } from 'react-native';
import { API_URL } from './Config';

const fakePublishableKey = true;

export async function fetchPublishableKey(
paymentMethod?: string
): Promise<string | null> {
try {
if (fakePublishableKey) {
return 'uk_TEZmVlG97Bvkhi3hTJjI1or06NO970Ra00QZ7nWQ3i';
}
const response = await fetch(
`${API_URL}/stripe-key?paymentMethod=${paymentMethod}`
);
Expand Down
20 changes: 20 additions & 0 deletions example/src/screens/AccountOnboardingScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useStripe } from '@stripe/stripe-react-native';
import Button from '../components/Button';
import PaymentScreen from '../components/PaymentScreen';

export default function AccountOnboardingScreen() {
const { presentAccountOnboardingScreen } = useStripe();
return (
<PaymentScreen>
<Button
variant="primary"
onPress={async () => {
const result = await presentAccountOnboardingScreen({});

console.log('result', result.error);
}}
title="Present onboarding screen"
/>
</PaymentScreen>
);
}
12 changes: 12 additions & 0 deletions example/src/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,18 @@ export default function HomeScreen() {
</View>
</>
</Collapse>
<Collapse title="Account Onboarding">
<>
<View style={styles.buttonContainer}>
<Button
title="Account Onboarding screen"
onPress={() => {
navigation.navigate('AccountOnboardingScreen');
}}
/>
</View>
</>
</Collapse>
<View style={styles.infoContainer}>
<Text style={styles.infoText}>
New arch enabled:{' '}
Expand Down
7 changes: 7 additions & 0 deletions ios/StripeSdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ - (instancetype)init
[StripeSdkImpl.shared presentPaymentSheet:options resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(presentAccountOnboardingScreen:(nonnull NSDictionary *)options
resolve:(nonnull RCTPromiseResolveBlock)resolve
reject:(nonnull RCTPromiseRejectBlock)reject)
{
[StripeSdkImpl.shared presentAccountOnboardingScreen:options resolver:resolve rejecter:reject];
}

RCT_EXPORT_METHOD(resetPaymentSheetCustomer:(nonnull RCTPromiseResolveBlock)resolve
reject:(nonnull RCTPromiseRejectBlock)reject)
{
Expand Down
Loading