Skip to content

Commit

Permalink
Merge branch 'feature/DELIVERY-70584/PurchaseConnectorRN' into develo…
Browse files Browse the repository at this point in the history
…pment
  • Loading branch information
al-af committed Nov 6, 2024
2 parents 89352bf + 9835995 commit fc7c8d9
Show file tree
Hide file tree
Showing 64 changed files with 153,559 additions and 639 deletions.
2 changes: 1 addition & 1 deletion Docs/RN_ExpoDeepLinkIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ For more info please check out the [OneLink™ Deep Linking Guide](https://suppo

1. In order to use AppsFlyer's deeplinks you need to configure intent filters/scheme/associatedDomains as described in [Expo's guide](https://docs.expo.dev/guides/linking/#universal-links-on-ios).

2. **For Android apps:** You need to add `setIntent()` inside the `onNewIntent` method like described [here](RN_DeepLinkIntegrate.md#android-deeplink-setup). This plugin is NOT adding this code out the box, so you need to implement it **manually or with [custom config plugin](https://docs.expo.dev/modules/config-plugin-and-native-module-tutorial/#4-creating-a-new-config-plugin)**
2. **For Android apps:** You need to add `setIntent()` inside the `onNewIntent` method like described [here](https://dev.appsflyer.com/hc/docs/rn_deeplinkintegrate#android-deeplink-setup). This plugin is NOT adding this code out the box, so you need to implement it **manually or with [custom config plugin](https://docs.expo.dev/modules/config-plugin-and-native-module-tutorial/#4-creating-a-new-config-plugin)**

## Full app.json example

Expand Down
373 changes: 373 additions & 0 deletions Docs/RN_PurchaseConnector.md

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions PurchaseConnector/constants/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class AppsFlyerConstants {
static readonly RE_CONFIGURE_ERROR_MSG: string = "[PurchaseConnector] Re configure instance is not permitted. Returned the existing instance";
static readonly MISSING_CONFIGURATION_EXCEPTION_MSG: string = "Could not create an instance without configuration";

// Adding method constants
static readonly SUBSCRIPTION_VALIDATION_SUCCESS: string = 'subscriptionValidationSuccess';
static readonly SUBSCRIPTION_VALIDATION_FAILURE: string = 'subscriptionValidationFailure';
static readonly IN_APP_PURCHASE_VALIDATION_SUCCESS: string = 'inAppPurchaseValidationSuccess';
static readonly IN_APP_PURCHASE_VALIDATION_FAILURE: string = 'inAppPurchaseValidationFailure';
static readonly DID_RECEIVE_PURCHASE_REVENUE_VALIDATION_INFO: string =
"onDidReceivePurchaseRevenueValidationInfo";

// Adding key constants
static readonly RESULT: string = "result";
static readonly ERROR: string = "error";
static readonly VALIDATION_INFO: string = "validationInfo";
static readonly CONFIGURE_KEY: string = "configure";
static readonly LOG_SUBS_KEY: string = "logSubscriptions";
static readonly LOG_IN_APP_KEY: string = "logInApps";
static readonly SANDBOX_KEY: string = "sandbox";
}

export default AppsFlyerConstants;
34 changes: 34 additions & 0 deletions PurchaseConnector/models/auto_renewing_plan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { SubscriptionItemPriceChangeDetailsJson, SubscriptionItemPriceChangeDetails } from "./subscription_item_price_change_details";

export type AutoRenewingPlanJson = {
autoRenewEnabled?: boolean;
priceChangeDetails?: SubscriptionItemPriceChangeDetailsJson;
};

export class AutoRenewingPlan {
autoRenewEnabled?: boolean;
priceChangeDetails?: SubscriptionItemPriceChangeDetails;

constructor(
autoRenewEnabled?: boolean,
priceChangeDetails?: SubscriptionItemPriceChangeDetails
) {
this.autoRenewEnabled = autoRenewEnabled;
this.priceChangeDetails = priceChangeDetails;
}

static fromJson(json: AutoRenewingPlanJson): AutoRenewingPlan {
return new AutoRenewingPlan(
json.autoRenewEnabled,
json.priceChangeDetails &&
SubscriptionItemPriceChangeDetails.fromJson(json.priceChangeDetails)
);
}

toJson(): AutoRenewingPlanJson {
return {
autoRenewEnabled: this.autoRenewEnabled,
priceChangeDetails: this.priceChangeDetails?.toJson(),
};
}
}
141 changes: 141 additions & 0 deletions PurchaseConnector/models/canceled_state_context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
export class CanceledStateContext {
developerInitiatedCancellation?: DeveloperInitiatedCancellation;
replacementCancellation?: ReplacementCancellation;
systemInitiatedCancellation?: SystemInitiatedCancellation;
userInitiatedCancellation?: UserInitiatedCancellation;

constructor(
developerInitiatedCancellation?: DeveloperInitiatedCancellation,
replacementCancellation?: ReplacementCancellation,
systemInitiatedCancellation?: SystemInitiatedCancellation,
userInitiatedCancellation?: UserInitiatedCancellation
) {
this.developerInitiatedCancellation = developerInitiatedCancellation;
this.replacementCancellation = replacementCancellation;
this.systemInitiatedCancellation = systemInitiatedCancellation;
this.userInitiatedCancellation = userInitiatedCancellation;
}

static fromJson(json: any): CanceledStateContext {
return new CanceledStateContext(
json.developerInitiatedCancellation != null
? DeveloperInitiatedCancellation.fromJson(
json.developerInitiatedCancellation
)
: undefined,
json.replacementCancellation != null
? ReplacementCancellation.fromJson(json.replacementCancellation)
: undefined,
json.systemInitiatedCancellation != null
? SystemInitiatedCancellation.fromJson(json.systemInitiatedCancellation)
: undefined,
json.userInitiatedCancellation != null
? UserInitiatedCancellation.fromJson(json.userInitiatedCancellation)
: undefined
);
}

toJson(): Record<string, any> {
return {
developerInitiatedCancellation:
this.developerInitiatedCancellation?.toJson(),
replacementCancellation: this.replacementCancellation?.toJson(),
systemInitiatedCancellation: this.systemInitiatedCancellation?.toJson(),
userInitiatedCancellation: this.userInitiatedCancellation?.toJson(),
};
}
}

/**
* TODO: Need to check each state context further...
*/
class DeveloperInitiatedCancellation {
constructor() {}

static fromJson(json: any): DeveloperInitiatedCancellation {
// Here you would implement the conversion from JSON to DeveloperInitiatedCancellation instance
return new DeveloperInitiatedCancellation();
}

toJson(): Record<string, unknown> {
// Here you would implement the conversion from DeveloperInitiatedCancellation instance to JSON
return {};
}
}

class ReplacementCancellation {
constructor() {}

static fromJson(json: any): ReplacementCancellation {
// Here you would implement the conversion from JSON to ReplacementCancellation instance
return new ReplacementCancellation();
}

toJson(): Record<string, unknown> {
return {};
}
}

class SystemInitiatedCancellation {
constructor() {}

static fromJson(json: any): SystemInitiatedCancellation {
// Here you would implement the conversion from JSON to SystemInitiatedCancellation instance
return new SystemInitiatedCancellation();
}

toJson(): Record<string, unknown> {
// Here you would implement the conversion from SystemInitiatedCancellation instance to JSON
return {};
}
}

class UserInitiatedCancellation {
cancelSurveyResult?: CancelSurveyResult; // Made optional as per Dart's CancelSurveyResult? declaration
cancelTime: string;

constructor(
cancelSurveyResult: CancelSurveyResult | undefined,
cancelTime: string
) {
this.cancelSurveyResult = cancelSurveyResult;
this.cancelTime = cancelTime;
}

static fromJson(json: any): UserInitiatedCancellation {
return new UserInitiatedCancellation(
json.cancelSurveyResult != null
? CancelSurveyResult.fromJson(json.cancelSurveyResult)
: undefined,
json.cancelTime
);
}

toJson(): Record<string, unknown> {
return {
cancelSurveyResult: this.cancelSurveyResult?.toJson(),
cancelTime: this.cancelTime,
};
}
}

class CancelSurveyResult {
reason: string;
reasonUserInput: string;

constructor(reason: string, reasonUserInput: string) {
this.reason = reason;
this.reasonUserInput = reasonUserInput;
}

static fromJson(json: any): CancelSurveyResult {
return new CancelSurveyResult(json.reason, json.reasonUserInput);
}

toJson(): Record<string, string> {
return {
reason: this.reason,
reasonUserInput: this.reasonUserInput,
};
}
}
21 changes: 21 additions & 0 deletions PurchaseConnector/models/deferred_item_replacement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export type DeferredItemReplacementJson = {
productId: string;
};

export class DeferredItemReplacement {
productId: string;

constructor(productId: string) {
this.productId = productId;
}

static fromJson(json: DeferredItemReplacementJson): DeferredItemReplacement {
return new DeferredItemReplacement(json.productId);
}

toJson(): DeferredItemReplacementJson {
return {
productId: this.productId,
};
}
}
39 changes: 39 additions & 0 deletions PurchaseConnector/models/external_account_identifiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export type ExternalAccountIdentifiersJson = {
externalAccountId: string;
obfuscatedExternalAccountId: string;
obfuscatedExternalProfileId: string;
};

export class ExternalAccountIdentifiers {
externalAccountId: string;
obfuscatedExternalAccountId: string;
obfuscatedExternalProfileId: string;

constructor(
externalAccountId: string,
obfuscatedExternalAccountId: string,
obfuscatedExternalProfileId: string
) {
this.externalAccountId = externalAccountId;
this.obfuscatedExternalAccountId = obfuscatedExternalAccountId;
this.obfuscatedExternalProfileId = obfuscatedExternalProfileId;
}

static fromJson(
json: ExternalAccountIdentifiersJson
): ExternalAccountIdentifiers {
return new ExternalAccountIdentifiers(
json.externalAccountId,
json.obfuscatedExternalAccountId,
json.obfuscatedExternalProfileId
);
}

toJson(): ExternalAccountIdentifiersJson {
return {
externalAccountId: this.externalAccountId,
obfuscatedExternalAccountId: this.obfuscatedExternalAccountId,
obfuscatedExternalProfileId: this.obfuscatedExternalProfileId,
};
}
}
34 changes: 34 additions & 0 deletions PurchaseConnector/models/in_app_purchase_validation_result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ProductPurchase } from "./product_purchase";
import { ValidationFailureData } from "./validation_failure_data";

export default class InAppPurchaseValidationResult {
success: boolean;
productPurchase?: ProductPurchase;
failureData?: ValidationFailureData;

constructor(
success: boolean,
productPurchase?: ProductPurchase,
failureData?: ValidationFailureData
) {
this.success = success;
this.productPurchase = productPurchase;
this.failureData = failureData;
}

static fromJson(json: any): InAppPurchaseValidationResult {
return new InAppPurchaseValidationResult(
json.success,
json.productPurchase,
json.failureData
);
}

toJson(): any {
return {
success: this.success,
productPurchase: this.productPurchase,
failureData: this.failureData,
};
}
}
52 changes: 52 additions & 0 deletions PurchaseConnector/models/ios_errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// TypeScript class for IOS Error
export class IosError {
localizedDescription: string;
domain: string;
code: number;

constructor(localizedDescription: string, domain: string, code: number) {
this.localizedDescription = localizedDescription;
this.domain = domain;
this.code = code;
}

// Converts the class instance to a JSON object
toJson(): object {
return {
localizedDescription: this.localizedDescription,
domain: this.domain,
code: this.code,
};
}

// Creates an instance of the class from a JSON object
static fromJson(json: any): IosError {
return new IosError(json.localizedDescription, json.domain, json.code);
}
}

/**
* Usage example:
* // Creating an instance of IosError
* const iosError = new IosError('An error occurred.', 'com.example.domain', 100);
*
* // Display information about the IOS error
* console.log(iosError.localizedDescription); // Outputs: An error occurred.
* console.log(iosError.domain); // Outputs: com.example.domain
* console.log(iosError.code); // Outputs: 100
*
* // Serializing IosError instance to a JSON object
* const iosErrorJson = iosError.toJson();
* console.log(iosErrorJson); // Outputs: { localizedDescription: 'An error occurred.', domain: 'com.example.domain', code: 100 }
*
* // Sample JSON objects
* const iosErrorData = {
* localizedDescription: 'A network error occurred.',
* domain: 'com.example.network',
* code: 404
* };
*
* // Deserializing the parsed JSON into instance of IosError
* const deserializedIosError = IosError.fromJson(iosErrorData);
* console.log(deserializedIosError);
*/
Loading

0 comments on commit fc7c8d9

Please sign in to comment.