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 @@ -277,6 +277,15 @@ internal class RNUsercentricsModule(
})
}

@ReactMethod
override fun notifySubscriptionLapsed(promise: Promise) {
usercentricsProxy.instance.notifySubscriptionLapsed({
promise.resolve(null)
}, {
promise.reject(it)
})
}

@ReactMethod
override fun addListener(eventName: String) {
if (eventName != ON_GPP_SECTION_CHANGE_EVENT) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ abstract class RNUsercentricsModuleSpec internal constructor(context: ReactAppli
@ReactMethod
abstract fun notifySubscribeSuccess(promise: Promise)

@ReactMethod
abstract fun notifySubscriptionLapsed(promise: Promise)

@ReactMethod
abstract fun getConsents(promise: Promise)

Expand Down
5 changes: 5 additions & 0 deletions ios/Manager/UsercentricsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public protocol UsercentricsManager {

func notifyLoginSuccess(onSuccess: @escaping (() -> Void), onError: @escaping ((Error) -> Void))
func notifySubscribeSuccess(onSuccess: @escaping (() -> Void), onError: @escaping ((Error) -> Void))
func notifySubscriptionLapsed(onSuccess: @escaping (() -> Void), onError: @escaping ((Error) -> Void))

func showSecondLayer(bannerSettings: BannerSettings?,
dismissViewHandler: @escaping (UsercentricsConsentUserResponse) -> Void)
Expand Down Expand Up @@ -81,6 +82,10 @@ final class UsercentricsManagerImplementation: UsercentricsManager {
UsercentricsCore.shared.notifySubscribeSuccess(onSuccess: onSuccess, onError: onError)
}

func notifySubscriptionLapsed(onSuccess: @escaping (() -> Void), onError: @escaping ((Error) -> Void)) {
UsercentricsCore.shared.notifySubscriptionLapsed(onSuccess: onSuccess, onError: onError)
}
Comment thread
islameldesoky95 marked this conversation as resolved.

func showSecondLayer(bannerSettings: BannerSettings?,
dismissViewHandler: @escaping (UsercentricsConsentUserResponse) -> Void) {
UsercentricsBanner(bannerSettings: bannerSettings).showSecondLayer(completionHandler: dismissViewHandler)
Expand Down
3 changes: 3 additions & 0 deletions ios/RNUsercentricsModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ @interface RCT_EXTERN_MODULE(RNUsercentricsModule, NSObject)

RCT_EXTERN_METHOD(notifySubscribeSuccess:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(notifySubscriptionLapsed:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
@end
8 changes: 8 additions & 0 deletions ios/RNUsercentricsModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ class RNUsercentricsModule: RCTEventEmitter {
}
}

@objc func notifySubscriptionLapsed(_ resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
usercentricsManager.notifySubscriptionLapsed {
resolve(nil)
} onError: { error in
reject("usercentrics_reactNative_notifySubscriptionLapsed_error", error.localizedDescription, error)
}
}

private static let onGppSectionChangeEvent = "onGppSectionChange"
private static let onLoginClickedEvent = "onLoginClicked"
private static let onSubscribeClickedEvent = "onSubscribeClicked"
Expand Down
3 changes: 3 additions & 0 deletions ios/RNUsercentricsModuleSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
- (void)notifySubscribeSuccess:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject;

- (void)notifySubscriptionLapsed:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject;

// Data Retrieval
- (void)getConsents:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject;
Expand Down
9 changes: 9 additions & 0 deletions sample/ios/sampleTests/Fake/FakeUsercentricsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,13 @@ final class FakeUsercentricsManager: UsercentricsManager {
}
onSuccess()
}

var notifySubscriptionLapsedError: Error?
func notifySubscriptionLapsed(onSuccess: @escaping (() -> Void), onError: @escaping ((Error) -> Void)) {
if let notifySubscriptionLapsedError = notifySubscriptionLapsedError {
onError(notifySubscriptionLapsedError)
return
}
onSuccess()
}
Comment thread
islameldesoky95 marked this conversation as resolved.
}
12 changes: 12 additions & 0 deletions sample/src/screens/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export const HomeScreen = ({ navigation }: { navigation: any }) => {
};
}, []);

async function notifySubscriptionLapsed() {
try {
await Usercentrics.notifySubscriptionLapsed();
console.log('[Usercentrics] notifySubscriptionLapsed done');
Alert.alert('notifySubscriptionLapsed', 'Subscription reset');
} catch (e) {
console.error('[Usercentrics] notifySubscriptionLapsed failed:', e);
Alert.alert('notifySubscriptionLapsed failed', String(e));
}
}

async function showSecondLayer() {
try {
const response = await Usercentrics.showSecondLayer({
Expand Down Expand Up @@ -129,6 +140,7 @@ export const HomeScreen = ({ navigation }: { navigation: any }) => {
<Button onPress={async () => { await Usercentrics.status(); navigation.navigate('CustomUI'); }} title="Custom UI" />
<Button onPress={async () => { await Usercentrics.status(); navigation.navigate('WebviewIntegration'); }} title="Webview Integration" />
<Button onPress={() => navigation.navigate('GPPTesting')} title="GPP Testing" />
<Button onPress={notifySubscriptionLapsed} title="Notify Subscription Lapsed" />
</View>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/NativeUsercentrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface Spec extends TurboModule {
// Consent or Pay
notifyLoginSuccess(): Promise<void>;
notifySubscribeSuccess(): Promise<void>;
notifySubscriptionLapsed(): Promise<void>;
Comment thread
islameldesoky95 marked this conversation as resolved.

// Data Retrieval
getConsents(): Promise<Array<UsercentricsServiceConsent>>;
Expand Down
8 changes: 8 additions & 0 deletions src/Usercentrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,12 @@ export const Usercentrics = {
await RNUsercentricsModule.isReady();
return RNUsercentricsModule.notifySubscribeSuccess();
},

// Notifies the SDK that a previously active Consent-or-Pay subscription has lapsed,
// resetting the subscriber flag so the host app can re-surface the banner. Does not
// alter any existing consent data, which remains accurate.
notifySubscriptionLapsed: async (): Promise<void> => {
await RNUsercentricsModule.isReady();
return RNUsercentricsModule.notifySubscriptionLapsed();
},
}
22 changes: 22 additions & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jest.mock("react-native", () => {
reset: jest.fn(),
getDpsMetadata: jest.fn(),
clearUserSession: jest.fn(),
notifySubscriptionLapsed: jest.fn(),
addListener: jest.fn(),
removeListeners: jest.fn()
};
Expand Down Expand Up @@ -618,4 +619,25 @@ describe('Test Usercentrics Module', () => {
expect(e).toBe("Failed");
}
})

test('testNotifySubscriptionLapsed', async () => {
RNUsercentricsModule.notifySubscriptionLapsed.mockImplementationOnce(
(): Promise<any> => Promise.resolve()
)

await Usercentrics.notifySubscriptionLapsed();
expect(RNUsercentricsModule.notifySubscriptionLapsed).toHaveBeenCalled();
})

test('testNotifySubscriptionLapsedWithError', async () => {
RNUsercentricsModule.notifySubscriptionLapsed.mockImplementationOnce(
(): Promise<any> => Promise.reject("Failed")
Comment thread
islameldesoky95 marked this conversation as resolved.
)

try {
await Usercentrics.notifySubscriptionLapsed();
} catch (e) {
expect(e).toBe("Failed");
}
})
})
1 change: 1 addition & 0 deletions src/fabric/NativeUsercentricsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Spec extends TurboModule {
// Consent or Pay
notifyLoginSuccess(): Promise<void>;
notifySubscribeSuccess(): Promise<void>;
notifySubscriptionLapsed(): Promise<void>;
Comment thread
islameldesoky95 marked this conversation as resolved.

// Data Retrieval
getConsents(): Promise<Array<Object>>;
Expand Down
Loading