in packages/fxa-shared/payments/iap/apple-app-store/subscription-purchase.ts [123:198]
static fromApiResponse(
apiResponse: StatusResponse,
subscriptionStatus: LastTransactionsItem['status'],
transactionInfo: JWSTransactionDecodedPayload,
renewalInfo: JWSRenewalInfoDecodedPayload,
originalTransactionId: string,
verifiedAt: number
): AppStoreSubscriptionPurchase {
const purchase = new AppStoreSubscriptionPurchase();
purchase.autoRenewStatus = renewalInfo.autoRenewStatus;
purchase.autoRenewProductId = renewalInfo.autoRenewProductId;
purchase.bundleId = apiResponse.bundleId;
purchase.environment = apiResponse.environment;
purchase.inAppOwnershipType = transactionInfo.inAppOwnershipType;
purchase.originalPurchaseDate = transactionInfo.originalPurchaseDate;
purchase.originalTransactionId = originalTransactionId;
purchase.productId = transactionInfo.productId;
purchase.status = subscriptionStatus;
purchase.transactionId = transactionInfo.transactionId;
purchase.type = transactionInfo.type;
purchase.verifiedAt = verifiedAt;
purchase.currency = transactionInfo.currency;
purchase.price = transactionInfo.price;
purchase.storefront = transactionInfo.storefront;
if (renewalInfo.expirationIntent) {
purchase.expirationIntent = renewalInfo.expirationIntent;
}
if (transactionInfo.expiresDate) {
purchase.expiresDate = transactionInfo.expiresDate;
}
if (renewalInfo.gracePeriodExpiresDate) {
purchase.gracePeriodExpiresDate = renewalInfo.gracePeriodExpiresDate;
}
if (renewalInfo.hasOwnProperty('isInBillingRetryPeriod')) {
// We don't check this.status === SubscriptionStatus.InBillingRetry, since
// it's not mutually exclusive with other subscription states (i.e.
// SubscriptionStatus.InBillingGracePeriod).
purchase.isInBillingRetry = renewalInfo.isInBillingRetryPeriod;
}
if (transactionInfo.hasOwnProperty('isUpgraded')) {
purchase.isUpgraded = transactionInfo.isUpgraded;
}
// Some offers (like introductory free trials) only apply to the current
// billing period. In these cases, the offerType and (if applicable)
// offerIdentifier would only be on transactionInfo, not renewalInfo.
if (transactionInfo.offerIdentifier) {
purchase.offerIdentifier = transactionInfo.offerIdentifier;
}
if (transactionInfo.offerType) {
purchase.offerType = transactionInfo.offerType;
}
if (renewalInfo.offerIdentifier) {
purchase.renewalOfferIdentifier = renewalInfo.offerIdentifier;
}
if (renewalInfo.offerType) {
purchase.renewalOfferType = renewalInfo.offerType;
}
if (transactionInfo.purchaseDate) {
purchase.purchaseDate = transactionInfo.purchaseDate;
}
if (transactionInfo.revocationDate) {
purchase.revocationDate = transactionInfo.revocationDate;
}
if (transactionInfo.hasOwnProperty('revocationReason')) {
purchase.revocationReason = transactionInfo.revocationReason;
}
if (renewalInfo.currency) {
purchase.renewalCurrency = renewalInfo.currency;
}
if (renewalInfo.renewalPrice) {
purchase.renewalPrice = renewalInfo.renewalPrice;
}
return purchase;
}