Skip to content

Commit

Permalink
Updated entitlements fields (#49)
Browse files Browse the repository at this point in the history
* Updated entitlements fields

* Update plugin/src/plugin/Mapper.ts

Co-authored-by: Kamo Spertsyan <spertsiankamo@gmail.com>

* Update plugin/src/plugin/Mapper.ts

Co-authored-by: Kamo Spertsyan <spertsiankamo@gmail.com>

* Updated imports

* Update plugin/src/plugin/Qonversion.ts

Co-authored-by: Kamo Spertsyan <spertsiankamo@gmail.com>

* Updated imports

---------

Co-authored-by: Surik <action@github.com>
Co-authored-by: Kamo Spertsyan <spertsiankamo@gmail.com>
  • Loading branch information
3 people authored Jan 16, 2024
1 parent b94bf27 commit 4f690db
Show file tree
Hide file tree
Showing 8 changed files with 253 additions and 24 deletions.
5 changes: 3 additions & 2 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<js-module src="www/ActionResult.js" name="ActionResult" />
<js-module src="www/AutomationsEvent.js" name="AutomationsEvent" />
<js-module src="www/Entitlement.js" name="Entitlement" />
<js-module src="www/Transaction.js" name="Transaction" />
<js-module src="www/IntroEligibility.js" name="IntroEligibility" />
<js-module src="www/Offering.js" name="Offering" />
<js-module src="www/Offerings.js" name="Offerings" />
Expand All @@ -44,7 +45,7 @@
<param name="android-package" value="com.qonversion.android.sdk.QonversionPlugin"/>
</feature>
</config-file>
<framework src="io.qonversion.sandwich:sandwich:3.2.0" />
<framework src="io.qonversion.sandwich:sandwich:3.3.3" />
<source-file src="src/android/QonversionPlugin.java" target-dir="src/com/qonversion/android/sdk" />
<source-file src="src/android/EntitiesConverter.java" target-dir="src/com/qonversion/android/sdk" />
<source-file src="src/android/Utils.java" target-dir="src/com/qonversion/android/sdk" />
Expand All @@ -62,7 +63,7 @@
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="QonversionSandwich" spec="3.2.0" />
<pod name="QonversionSandwich" spec="3.3.3" />
</pods>
</podspec>
</platform>
Expand Down
46 changes: 36 additions & 10 deletions plugin/src/plugin/Entitlement.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {EntitlementSource, EntitlementRenewState} from "./enums";
import {EntitlementSource, EntitlementRenewState, EntitlementGrantType} from "./enums";
import {Transaction} from "./Transaction";

export class Entitlement {
id: string;
Expand All @@ -7,23 +8,48 @@ export class Entitlement {
renewState: EntitlementRenewState;
source: EntitlementSource;
startedDate: Date;
renewsCount: number;
grantType: EntitlementGrantType;
transactions: Array<Transaction>;
expirationDate?: Date;
trialStartDate?: Date;
firstPurchaseDate?: Date;
lastPurchaseDate?: Date;
autoRenewDisableDate?: Date;
lastActivatedOfferCode?: string;

constructor(
id: string,
productId: string,
isActive: boolean,
renewState: EntitlementRenewState,
source: EntitlementSource,
startedDate: number,
expirationDate: number | undefined,
id: string,
productId: string,
isActive: boolean,
renewState: EntitlementRenewState,
source: EntitlementSource,
startedTimestamp: number,
renewsCount: number,
grantType: EntitlementGrantType,
transactions: Array<Transaction>,
expirationTimestamp: number | undefined,
trialStartTimestamp: number | undefined,
firstPurchaseTimestamp: number | undefined,
lastPurchaseTimestamp: number | undefined,
autoRenewDisableTimestamp: number | undefined,
lastActivatedOfferCode: string | undefined,
) {
this.id = id;
this.productId = productId;
this.isActive = isActive;
this.renewState = renewState;
this.source = source;
this.startedDate = new Date(startedDate);
this.expirationDate = expirationDate ? new Date(expirationDate) : undefined;
this.startedDate = new Date(startedTimestamp);
this.expirationDate = expirationTimestamp ? new Date(expirationTimestamp) : undefined;
this.renewsCount = renewsCount;
this.grantType = grantType;
this.transactions = transactions;
this.expirationDate = expirationTimestamp ? new Date(expirationTimestamp) : undefined;
this.trialStartDate = trialStartTimestamp ? new Date(trialStartTimestamp) : undefined;
this.firstPurchaseDate = firstPurchaseTimestamp ? new Date(firstPurchaseTimestamp) : undefined;
this.lastPurchaseDate = lastPurchaseTimestamp ? new Date(lastPurchaseTimestamp) : undefined;
this.autoRenewDisableDate = autoRenewDisableTimestamp ? new Date(autoRenewDisableTimestamp) : undefined;
this.lastActivatedOfferCode = lastActivatedOfferCode;
}
}
136 changes: 126 additions & 10 deletions plugin/src/plugin/Mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import {
ExperimentGroupType,
UserPropertyKey,
RemoteConfigurationAssignmentType,
RemoteConfigurationSourceType
RemoteConfigurationSourceType,
TransactionType,
TransactionOwnershipType,
TransactionEnvironment,
EntitlementGrantType
} from "./enums";
import {IntroEligibility} from "./IntroEligibility";
import {Offering} from "./Offering";
Expand All @@ -37,6 +41,7 @@ import {ExperimentGroup} from "./ExperimentGroup";
import {Experiment} from "./Experiment";
import {UserProperty} from './UserProperty';
import {UserProperties} from './UserProperties';
import {Transaction} from "./Transaction";

export type QProduct = {
id: string;
Expand Down Expand Up @@ -118,8 +123,28 @@ export type QEntitlement = {
source: string;
startedTimestamp: number;
expirationTimestamp: number;
renewsCount: number;
trialStartTimestamp: number;
firstPurchaseTimestamp: number;
lastPurchaseTimestamp: number;
lastActivatedOfferCode: string;
grantType: string;
autoRenewDisableTimestamp: number;
transactions: Array<QTransaction>;
};

export type QTransaction = {
originalTransactionId: string;
transactionId: string;
offerCode: string;
transactionTimestamp: number;
expirationTimestamp: number;
transactionRevocationTimestamp: number;
environment: string;
ownershipType: string;
type: string;
}

export type QOfferings = {
availableOfferings?: Array<QOffering>;
main: QOffering;
Expand Down Expand Up @@ -194,8 +219,7 @@ class Mapper {
return mappedPermissions;
}

for (const key of Object.keys(entitlements)) {
const entitlement = entitlements[key];
for (const [key, entitlement] of Object.entries(entitlements)) {
let renewState: EntitlementRenewState;
switch (entitlement.renewState) {
case EntitlementRenewState.NON_RENEWABLE:
Expand All @@ -216,22 +240,99 @@ class Mapper {
}

const entitlementSource = this.convertEntitlementSource(entitlement.source);
const entitlementGrantType = this.convertEntitlementGrantType(entitlement.grantType);
const transactions: Array<Transaction> = [];

if (Array.isArray(entitlement.transactions)) {
entitlement.transactions.forEach((transaction) => {
const mappedTransaction = this.convertTransaction(transaction);

transactions.push(mappedTransaction);
});
}

const mappedPermission = new Entitlement(
entitlement.id,
entitlement.productId,
entitlement.active,
renewState,
entitlementSource,
entitlement.startedTimestamp,
entitlement.expirationTimestamp
entitlement.id,
entitlement.productId,
entitlement.active,
renewState,
entitlementSource,
entitlement.startedTimestamp,
entitlement.renewsCount,
entitlementGrantType,
transactions,
entitlement.expirationTimestamp,
entitlement.trialStartTimestamp,
entitlement.firstPurchaseTimestamp,
entitlement.lastPurchaseTimestamp,
entitlement.autoRenewDisableTimestamp,
entitlement.lastActivatedOfferCode,
);
mappedPermissions.set(key, mappedPermission);
}

return mappedPermissions;
}

static convertTransaction(transaction: QTransaction): Transaction {
const environment = this.convertTransactionEnvironment(transaction.environment);
const ownershipType = this.convertTransactionOwnershipType(transaction.ownershipType);
const type = this.convertTransactionType(transaction.type);

return new Transaction(
transaction.originalTransactionId,
transaction.transactionId,
transaction.transactionTimestamp,
environment,
ownershipType,
type,
transaction.expirationTimestamp,
transaction.transactionRevocationTimestamp,
transaction.offerCode,
);
}

static convertTransactionType(typeKey: string): TransactionType {
switch (typeKey) {
case "SubscriptionStarted":
return TransactionType.SUBSCRIPTION_STARTED;
case "SubscriptionRenewed":
return TransactionType.SUBSCRIPTION_RENEWED;
case "TrialStarted":
return TransactionType.TRIAL_STARTED;
case "IntroStarted":
return TransactionType.INTRO_STARTED;
case "IntroRenewed":
return TransactionType.INTRO_RENEWED;
case "NonConsumablePurchase":
return TransactionType.NON_CONSUMABLE_PURCHASE;
}

return TransactionType.UNKNOWN;
}

static convertTransactionOwnershipType(ownershipTypeKey: string): TransactionOwnershipType {
switch (ownershipTypeKey) {
case "Owner":
return TransactionOwnershipType.OWNER;
case "FamilySharing":
return TransactionOwnershipType.FAMILY_SHARING;
}

return TransactionOwnershipType.OWNER;
}

static convertTransactionEnvironment(envKey: string): TransactionEnvironment {
switch (envKey) {
case "Production":
return TransactionEnvironment.PRODUCTION;
case "Sandbox":
return TransactionEnvironment.SANDBOX;
}

return TransactionEnvironment.PRODUCTION;
}

static convertEntitlementSource(sourceKey: string): EntitlementSource {
switch (sourceKey) {
case "Unknown":
Expand All @@ -249,6 +350,21 @@ class Mapper {
return EntitlementSource.UNKNOWN;
}

static convertEntitlementGrantType(typeKey: string): EntitlementGrantType {
switch (typeKey) {
case "Purchase":
return EntitlementGrantType.PURCHASE;
case "FamilySharing":
return EntitlementGrantType.FAMILY_SHARING;
case "OfferCode":
return EntitlementGrantType.OFFER_CODE;
case "Manual":
return EntitlementGrantType.MANUAL;
}

return EntitlementGrantType.PURCHASE;
}

static convertDefinedUserPropertyKey(sourceKey: string): UserPropertyKey {
switch (sourceKey) {
case '_q_email':
Expand Down
20 changes: 20 additions & 0 deletions plugin/src/plugin/Qonversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
ActionResultType,
AttributionProvider,
AutomationsEventType,
EntitlementGrantType,
EntitlementRenewState,
EntitlementsCacheLifetime,
EntitlementSource,
Environment,
ExperimentGroupType,
IntroEligibilityStatus,
LaunchMode,
OfferingTag,
Expand All @@ -25,6 +27,9 @@ import {
SKPeriodUnit,
SKProductDiscountPaymentMode,
SKProductDiscountType,
TransactionEnvironment,
TransactionOwnershipType,
TransactionType,
TrialDuration,
UserPropertyKey
} from './enums';
Expand All @@ -37,6 +42,11 @@ import {User} from './User';
import {UserProperty} from './UserProperty';
import {UserProperties} from './UserProperties';
import {QonversionConfigBuilder} from './QonversionConfigBuilder';
import {Experiment} from "./Experiment";
import {Transaction} from './Transaction';
import {RemoteConfig} from './RemoteConfig';
import {RemoteConfigurationSource} from "./RemoteConfigurationSource";
import {ExperimentGroup} from './ExperimentGroup';

export default class Qonversion {
private constructor() {}
Expand Down Expand Up @@ -81,13 +91,23 @@ export default class Qonversion {
static ActionResult = ActionResult;
static AutomationsEvent = AutomationsEvent;
static Entitlement = Entitlement;
static Transaction = Transaction;
static RemoteConfig = RemoteConfig;
static Experiment = Experiment;
static LaunchMode = LaunchMode;
static Environment = Environment;
static ProductType = ProductType;
static ProductDuration = ProductDuration;
static TrialDuration = TrialDuration;
static EntitlementRenewState = EntitlementRenewState;
static EntitlementSource = EntitlementSource;
static RemoteConfigurationSource = RemoteConfigurationSource;
static ExperimentGroup = ExperimentGroup;
static ExperimentGroupType = ExperimentGroupType;
static EntitlementGrantType = EntitlementGrantType;
static TransactionEnvironment = TransactionEnvironment;
static TransactionOwnershipType = TransactionOwnershipType;
static TransactionType = TransactionType;
static UserPropertyKey = UserPropertyKey;
static UserProperty = UserProperty;
static UserProperties = UserProperties;
Expand Down
39 changes: 39 additions & 0 deletions plugin/src/plugin/Transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
TransactionEnvironment,
TransactionOwnershipType,
TransactionType
} from "./enums";

export class Transaction {
originalTransactionId: string;
transactionId: string;
transactionDate: Date;
environment: TransactionEnvironment;
ownershipType: TransactionOwnershipType;
type: TransactionType;
expirationDate?: Date;
transactionRevocationDate?: Date;
offerCode?: string;

constructor(
originalTransactionId: string,
transactionId: string,
transactionTimestamp: number,
environment: TransactionEnvironment,
ownershipType: TransactionOwnershipType,
type: TransactionType,
expirationTimestamp: number | undefined,
transactionRevocationTimestamp: number | undefined,
offerCode: string | undefined,
) {
this.originalTransactionId = originalTransactionId;
this.transactionId = transactionId;
this.transactionDate = new Date(transactionTimestamp);
this.environment = environment;
this.ownershipType = ownershipType;
this.type = type;
this.expirationDate = expirationTimestamp ? new Date(expirationTimestamp) : undefined;
this.transactionRevocationDate = transactionRevocationTimestamp ? new Date(transactionRevocationTimestamp) : undefined;
this.offerCode = offerCode;
}
}
Loading

0 comments on commit 4f690db

Please sign in to comment.