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
90 changes: 90 additions & 0 deletions apitesters/paywalls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import RevenueCatUI, {
FooterPaywallViewOptions,
FullScreenPaywallViewOptions,
PAYWALL_RESULT,
PaywallListener,
PaywallViewOptions,
PresentPaywallIfNeededParams,
PresentPaywallParams,
PurchaseResumable,
} from "../react-native-purchases-ui";
import {
CustomerInfo,
Expand Down Expand Up @@ -358,3 +360,91 @@ const FooterPaywallScreenNoOptions = () => {
<RevenueCatUI.PaywallFooterContainerView></RevenueCatUI.PaywallFooterContainerView>
);
};

// PaywallListener and PurchaseResumable type checks

function checkPaywallListener() {
const listener: PaywallListener = {
onPurchaseStarted: (args: { packageBeingPurchased: PurchasesPackage }) => {
const pkg: PurchasesPackage = args.packageBeingPurchased;
},
onPurchaseCompleted: (args: { customerInfo: CustomerInfo; storeTransaction: PurchasesStoreTransaction }) => {
const info: CustomerInfo = args.customerInfo;
const txn: PurchasesStoreTransaction = args.storeTransaction;
},
onPurchaseError: (args: { error: PurchasesError }) => {
const err: PurchasesError = args.error;
},
onPurchaseCancelled: () => {},
onRestoreStarted: () => {},
onRestoreCompleted: (args: { customerInfo: CustomerInfo }) => {
const info: CustomerInfo = args.customerInfo;
},
onRestoreError: (args: { error: PurchasesError }) => {
const err: PurchasesError = args.error;
},
onPurchaseInitiated: (args: { packageBeingPurchased: PurchasesPackage; resumable: PurchaseResumable }) => {
const pkg: PurchasesPackage = args.packageBeingPurchased;
const r: PurchaseResumable = args.resumable;
args.resumable.resume();
args.resumable.resume(true);
args.resumable.resume(false);
},
};
}

const PaywallScreenWithListener = () => {
const listener: PaywallListener = {
onPurchaseStarted: (args: { packageBeingPurchased: PurchasesPackage }) => {},
onPurchaseCompleted: (args: { customerInfo: CustomerInfo; storeTransaction: PurchasesStoreTransaction }) => {},
onPurchaseError: (args: { error: PurchasesError }) => {},
onPurchaseCancelled: () => {},
onRestoreStarted: () => {},
onRestoreCompleted: (args: { customerInfo: CustomerInfo }) => {},
onRestoreError: (args: { error: PurchasesError }) => {},
onPurchaseInitiated: (args: { packageBeingPurchased: PurchasesPackage; resumable: PurchaseResumable }) => {
args.resumable.resume(true);
},
};

return (
<RevenueCatUI.Paywall
style={{ marginBottom: 10 }}
listener={listener}
/>
);
};

const PaywallScreenWithListenerAndIndividualProps = () => {
// Individual props should take precedence over listener
const listener: PaywallListener = {
onPurchaseStarted: (args: { packageBeingPurchased: PurchasesPackage }) => {},
onPurchaseCompleted: (args: { customerInfo: CustomerInfo; storeTransaction: PurchasesStoreTransaction }) => {},
};

return (
<RevenueCatUI.Paywall
style={{ marginBottom: 10 }}
listener={listener}
onPurchaseStarted={onPurchaseStarted}
/>
);
};

const FooterPaywallScreenWithListener = () => {
const listener: PaywallListener = {
onPurchaseStarted: (args: { packageBeingPurchased: PurchasesPackage }) => {},
onPurchaseCompleted: (args: { customerInfo: CustomerInfo; storeTransaction: PurchasesStoreTransaction }) => {},
onPurchaseError: (args: { error: PurchasesError }) => {},
onPurchaseCancelled: () => {},
onRestoreStarted: () => {},
onRestoreCompleted: (args: { customerInfo: CustomerInfo }) => {},
onRestoreError: (args: { error: PurchasesError }) => {},
};

return (
<RevenueCatUI.OriginalTemplatePaywallFooterContainerView
listener={listener}
></RevenueCatUI.OriginalTemplatePaywallFooterContainerView>
);
};
59 changes: 59 additions & 0 deletions react-native-purchases-ui/apitesters/paywalls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type {
PresentPaywallIfNeededParams,
PresentPaywallParams,
CustomVariables,
PaywallListener,
PurchaseResumable,
} from "react-native-purchases-ui";
import type {
CustomerInfo,
Expand Down Expand Up @@ -509,6 +511,61 @@ const FooterPaywallScreenNoOptions = () => {
return <RevenueCatUI.PaywallFooterContainerView />;
};

const PaywallScreenWithListener = () => {
const listener: PaywallListener = {
onPurchaseStarted: ({ packageBeingPurchased }) => {
const pkg: PurchasesPackage = packageBeingPurchased;
void pkg;
},
onPurchaseCompleted: ({ customerInfo, storeTransaction }) => {
const info: CustomerInfo = customerInfo;
const txn: PurchasesStoreTransaction = storeTransaction;
void info;
void txn;
},
onPurchaseError: ({ error }) => {
const err: PurchasesError = error;
void err;
},
onPurchaseCancelled: () => {},
onRestoreStarted: () => {},
onRestoreCompleted: ({ customerInfo }) => {
const info: CustomerInfo = customerInfo;
void info;
},
onRestoreError: ({ error }) => {
const err: PurchasesError = error;
void err;
},
onPurchaseInitiated: ({ packageBeingPurchased, resumable }) => {
const pkg: PurchasesPackage = packageBeingPurchased;
const res: PurchaseResumable = resumable;
void pkg;
res.resume();
res.resume(true);
res.resume(false);
},
};
return (
<RevenueCatUI.Paywall
style={{ marginBottom: 10 }}
listener={listener}
onDismiss={onDismiss}
/>
);
};

const PaywallScreenWithListenerAndIndividualProps = () => {
return (
<RevenueCatUI.Paywall
style={{ marginBottom: 10 }}
listener={{ onPurchaseStarted: () => {} }}
onPurchaseCompleted={onPurchaseCompleted}
onDismiss={onDismiss}
/>
);
};

export {
FooterPaywallScreen,
FooterPaywallScreenNoOptions,
Expand All @@ -526,4 +583,6 @@ export {
PaywallScreenWithFontFamily,
PaywallScreenWithOffering,
PaywallScreenWithOfferingAndEvents,
PaywallScreenWithListener,
PaywallScreenWithListenerAndIndividualProps,
};
Loading