Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ class EmbeddedPaymentElementView(
val intentConfiguration: PaymentSheet.IntentConfiguration,
) : Event

data class UpdateWithCheckout(
val checkout: Checkout,
) : Event

data object Confirm : Event

data object ClearPaymentOption : Event
Expand Down Expand Up @@ -347,20 +343,6 @@ class EmbeddedPaymentElementView(
latestIntentConfig = ev.intentConfiguration
}

is Event.UpdateWithCheckout -> {
val elemConfig = latestElementConfig ?: return@collect emitUpdateMissingConfiguration()

val result =
embedded.configure(
checkout = ev.checkout,
configuration = elemConfig,
)

handleUpdateResult(result)

latestCheckout = ev.checkout
}

is Event.Confirm -> {
embedded.confirm()
}
Expand Down Expand Up @@ -506,10 +488,6 @@ class EmbeddedPaymentElementView(
events.trySend(Event.Update(intentConfig))
}

fun updateWithCheckout(checkout: Checkout) {
events.trySend(Event.UpdateWithCheckout(checkout))
}

fun confirm() {
events.trySend(Event.Confirm)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,28 +244,6 @@ class EmbeddedPaymentElementViewManager :
}
}

override fun updateWithCheckout(
view: EmbeddedPaymentElementView,
sessionKey: String?,
) {
if (sessionKey == null) return

val stripeSdkModule =
(view.context as ThemedReactContext).getNativeModule(StripeSdkModule::class.java)
val checkout = stripeSdkModule?.checkoutInstances?.get(sessionKey)
if (checkout == null) {
val payload =
Arguments.createMap().apply {
putString("message", "Checkout session not found.")
}
stripeSdkModule?.eventEmitter?.emitEmbeddedPaymentElementLoadingFailed(payload)
stripeSdkModule?.eventEmitter?.emitEmbeddedPaymentElementUpdateComplete(null)
return
}

view.updateWithCheckout(checkout)
}

private fun jsonToWritableMap(json: JSONObject): WritableMap {
val map = Arguments.createMap()
val keys = json.keys()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1443,15 +1443,6 @@ class StripeSdkModule(
// TODO:
}

@ReactMethod
override fun updateEmbeddedPaymentElementWithCheckout(
sessionKey: String,
promise: Promise,
) {
// No-op on Android. JS dispatches Checkout updates through the view command instead.
promise.resolve(null)
}

@ReactMethod
override fun clearEmbeddedPaymentOption(
viewTag: Double,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ public void receiveCommand(T view, String commandName, @Nullable ReadableArray a
case "update":
mViewManager.update(view, args != null ? args.getString(0) : null);
break;
case "updateWithCheckout":
mViewManager.updateWithCheckout(view, args != null ? args.getString(0) : null);
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ public interface EmbeddedPaymentElementViewManagerInterface<T extends View> {
void confirm(T view);
void clearPaymentOption(T view);
void update(T view, @Nullable String intentConfigurationJson);
void updateWithCheckout(T view, @Nullable String sessionKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,6 @@ private void invoke(String eventName) {
@DoNotStrip
public abstract void updateEmbeddedPaymentElement(ReadableMap intentConfig, Promise promise);

@ReactMethod
@DoNotStrip
public abstract void updateEmbeddedPaymentElementWithCheckout(String sessionKey, Promise promise);

@ReactMethod
@DoNotStrip
public abstract void clearEmbeddedPaymentOption(double viewTag, Promise promise);
Expand Down
5 changes: 1 addition & 4 deletions etc/stripe-react-native.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4000,10 +4000,7 @@ export interface UseEmbeddedPaymentElementResult {
// (undocumented)
loadingError: Error | null;
paymentOption: PaymentOptionDisplayData | null;
update: {
(intentConfig: PaymentSheet.IntentConfiguration): void;
(checkout: Checkout): void;
};
update: (intentConfig: PaymentSheet.IntentConfiguration) => void;
}

// @public
Expand Down
4 changes: 0 additions & 4 deletions ios/NewArch/EmbeddedPaymentElementViewComponentView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ - (void)update:(NSString *)intentConfigurationJson
{
}

- (void)updateWithCheckout:(NSString *)sessionKey
{
}

#pragma mark - RCTComponentViewProtocol

+ (ComponentDescriptorProvider)componentDescriptorProvider
Expand Down
7 changes: 0 additions & 7 deletions ios/StripeSdk.mm
Original file line number Diff line number Diff line change
Expand Up @@ -578,13 +578,6 @@ - (instancetype)init
[StripeSdkImpl.shared updateEmbeddedPaymentElement:intentConfig resolve:resolve reject:reject];
}

RCT_EXPORT_METHOD(updateEmbeddedPaymentElementWithCheckout:(nonnull NSString *)sessionKey
resolve:(nonnull RCTPromiseResolveBlock)resolve
reject:(nonnull RCTPromiseRejectBlock)reject)
{
[StripeSdkImpl.shared updateEmbeddedPaymentElementWithCheckout:sessionKey resolve:resolve reject:reject];
}

RCT_EXPORT_METHOD(clearEmbeddedPaymentOption:(NSInteger)viewTag
resolve:(nonnull RCTPromiseResolveBlock)resolve
reject:(nonnull RCTPromiseRejectBlock)reject)
Expand Down
24 changes: 0 additions & 24 deletions ios/StripeSdkImpl+Embedded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,6 @@ extension StripeSdkImpl {
}
}

@objc(updateEmbeddedPaymentElementWithCheckout:resolve:reject:)
public func updateEmbeddedPaymentElementWithCheckout(
sessionKey: String,
resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock
) {
guard let checkout = checkoutInstances[sessionKey] else {
resolve(Errors.createError(ErrorType.Failed, "Checkout session not found"))
return
}

Task {
guard let updateResult = await self.embeddedInstance?.update(checkout: checkout) else {
resolve(Errors.createError(
ErrorType.Failed,
"No EmbeddedPaymentElement instance — did you call create first?"
))
return
}

self.resolveEmbeddedUpdateResult(updateResult, resolve: resolve)
}
}

@objc(clearEmbeddedPaymentOption)
public func clearEmbeddedPaymentOption() {
DispatchQueue.main.async {
Expand Down
11 changes: 1 addition & 10 deletions src/specs/NativeEmbeddedPaymentElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,10 @@ export interface NativeCommands {
viewRef: React.ElementRef<HostComponent<NativeProps>>,
intentConfigurationJson: string
) => void;
updateWithCheckout: (
viewRef: React.ElementRef<HostComponent<NativeProps>>,
sessionKey: string
) => void;
}

export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: [
'confirm',
'clearPaymentOption',
'update',
'updateWithCheckout',
],
supportedCommands: ['confirm', 'clearPaymentOption', 'update'],
});

type ComponentType = HostComponent<NativeProps>;
Expand Down
3 changes: 0 additions & 3 deletions src/specs/NativeStripeSdkModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ export interface Spec extends TurboModule {
updateEmbeddedPaymentElement(
intentConfig: UnsafeObject<IntentConfiguration>
): Promise<UnsafeObject<any> | null>;
updateEmbeddedPaymentElementWithCheckout(
sessionKey: string
): Promise<UnsafeObject<any> | null>;
clearEmbeddedPaymentOption(viewTag: Int32): Promise<void>;
createRadarSession(): Promise<CreateRadarSessionResult>;

Expand Down
31 changes: 4 additions & 27 deletions src/types/EmbeddedPaymentElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,6 @@ class EmbeddedPaymentElement {
);
}

async updateCheckout(checkout: Checkout): Promise<unknown> {
return await NativeStripeSdkModule.updateEmbeddedPaymentElementWithCheckout(
checkout.sessionKey
);
}

/**
* Confirm the payment or setup intent.
* Waits for any in-progress `update()` call to finish before proceeding.
Expand Down Expand Up @@ -438,16 +432,7 @@ export interface UseEmbeddedPaymentElementResult {
* @note Upon completion, `paymentOption` may become null if it's no longer available.
* @note If you call `update` while a previous call to `update` is still in progress, the previous call is canceled.
*/
update: {
(intentConfig: PaymentSheetTypes.IntentConfiguration): void;
/**
* Call this method when the Checkout Session values you used to initialize
* `EmbeddedPaymentElement` change.
* @checkoutSessionsPreview
* @internal
*/
(checkout: Checkout): void;
};
update: (intentConfig: PaymentSheetTypes.IntentConfiguration) => void;
// Sets the currently selected payment option to null
clearPaymentOption: () => void;
// Any error encountered during creation/update, or null
Expand Down Expand Up @@ -642,9 +627,7 @@ export function useEmbeddedPaymentElement(
return getElementOrThrow(elementRef).confirm();
}, [isAndroid]);
const update = useCallback(
(
updateSource: PaymentSheetTypes.IntentConfiguration | Checkout
): Promise<unknown> => {
(updateSource: PaymentSheetTypes.IntentConfiguration): Promise<unknown> => {
if (isAndroid) {
const currentRef = viewRef.current;
if (currentRef) {
Expand All @@ -656,11 +639,7 @@ export function useEmbeddedPaymentElement(
resolve(result);
}
);
if (isCheckoutSession(updateSource)) {
Commands.updateWithCheckout(currentRef, updateSource.sessionKey);
} else {
Commands.update(currentRef, JSON.stringify(updateSource));
}
Commands.update(currentRef, JSON.stringify(updateSource));
});
}
return Promise.reject(
Expand All @@ -670,9 +649,7 @@ export function useEmbeddedPaymentElement(

// iOS: use native module directly
const embeddedElement = getElementOrThrow(elementRef);
return isCheckoutSession(updateSource)
? embeddedElement.updateCheckout(updateSource)
: embeddedElement.updateIntent(updateSource);
return embeddedElement.updateIntent(updateSource);
},
[isAndroid]
);
Expand Down
Loading