Methods
(async, inner) fetchHasActivePlatformSubscription() → {Promise.<boolean>}
- Source:
Returns:
Whether the user has any subscription from a known platform (web, ios, android)
- Type
- Promise.<boolean>
(async, inner) fetchLastSubscriptionPlatform() → {Promise.<('ios'|'android'|'web'|null)>}
- Source:
Returns:
The platform of the user's last known subscription
- Type
- Promise.<('ios'|'android'|'web'|null)>
(async, inner) fetchMemberships() → {Promise.<Array.<Membership>>}
- Description:
- Fetches the authenticated user's memberships from the API.
- Source:
Example
fetchMemberships()
.then(memberships => console.log(memberships))
.catch(error => console.error(error));
Throws:
-
- Throws an error if the request fails.
- Type
- Error
Returns:
- A promise that resolves to an array of membership objects.
- Type
- Promise.<Array.<Membership>>
(async, inner) fetchRechargeTokens() → {Promise.<RechargeTokens>}
- Description:
- Fetches tokens required for interacting with Shopify and Recharge.
- Source:
Example
fetchRechargeTokens()
.then(tokens => console.log(tokens))
.catch(error => console.error(error));
Throws:
-
- Throws an error if the request fails.
- Type
- Error
Returns:
- A promise that resolves to an object containing:
- {string} shopify_customer_access_token - Shopify customer access token.
- {string} store_identifier - The store domain identifier.
- {string} recharge_storefront_access_token - Recharge storefront access token.
- {string} storefront_access_token - Shopify storefront access token.
- Type
- Promise.<RechargeTokens>
(async, inner) getUpgradePrice() → {Promise.<{price: number, currency: string, period: (string|null)}>}
- Description:
- Get the upgrade price from Basic to Plus membership. Returns the price based on the user's subscription interval. For monthly subscribers: Returns the monthly upgrade cost (difference between Plus and Base monthly prices, ~$5/month) For yearly subscribers: Returns the monthly equivalent upgrade cost ($3.33/month from $40/year) For lifetime subscribers: Returns the annual upgrade cost for songs add-on ($40/year) If interval cannot be determined: Defaults to monthly price
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
price |
number | The upgrade cost in USD (monthly for month/year, annual for lifetime) |
currency |
string | The currency |
period |
string | null | The billing period for the price ('month' or 'year'). Note: lifetime subscribers return 'year' period with annual price |
Example
getUpgradePrice()
.then(info => {
console.log(`Upgrade price: $${info.price} per ${info.period}`)
// Example outputs:
// Monthly: "Upgrade price: $5 per month"
// Yearly: "Upgrade price: $3.33 per month"
// Lifetime: "Upgrade price: $40 per year"
})
.catch(error => {
console.error('Failed to fetch upgrade price:', error)
})
Returns:
- The upgrade price information
- Type
- Promise.<{price: number, currency: string, period: (string|null)}>
(async, inner) restorePurchases(originalAppUserId, emailopt) → {Promise.<RestorePurchasesResponse>}
- Description:
- Restores purchases by verifying subscriber status with RevenueCat. This function verifies the subscriber's status with RevenueCat and attempts to sync their subscription data with the platform. The backend will search for a user by email (if provided) or by the RevenueCat original app user ID.
- Source:
Examples
// With email
restorePurchases('rc_user_123', 'user@example.com')
.then(response => {
if ('shouldCreateAccount' in response) {
// Handle account creation
} else if ('shouldLogin' in response) {
// Handle login with response.email
} else if ('success' in response) {
// Handle successful authentication with response.token
}
})
.catch(error => console.error(error));
// Without email (search by original app user ID only)
restorePurchases('rc_user_123')
.then(response => console.log(response))
.catch(error => console.error(error));
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
originalAppUserId |
string | The original app user ID from RevenueCat. | |
email |
string |
<optional> |
(Optional) The user's email address. If provided and a user with this email exists, their subscription will be synced. If omitted, the backend will only search by the RevenueCat original app user ID. |
Throws:
-
- Throws an error if the request fails or if required parameters are missing.
- Type
- Error
Returns:
- A promise that resolves to one of three possible responses:
**Case 1: Should Create Account** (No active entitlements OR user not found with active entitlements)
- {boolean} shouldCreateAccount - Always true
- {string} [originalAppUserId] - RevenueCat ID to link when creating account (only if user has entitlements)
**Case 2: Should Login** (User exists but not currently authenticated)
- {boolean} shouldLogin - Always true
- {string} email - The email address of the found user
**Case 3: Success** (User authenticated and synced successfully)
- {boolean} success - Always true
- {string} token - Authentication token
- {string} tokenType - Token type 'bearer'
- {number} userId - The user's ID
- Type
- Promise.<RestorePurchasesResponse>
(async, inner) upgradeSubscription() → {Promise.<UpgradeSubscriptionResponse>}
- Description:
- Upgrades the user's subscription or provides a prefilled add-to-cart URL.
- Source:
Example
upgradeSubscription()
.then(response => console.log(response))
.catch(error => console.error(error));
Throws:
-
Throws an error if the request fails.
- Type
- Error
Returns:
A promise that resolves to an object containing either:
- {string} action - The action performed (e.g., 'instant_upgrade').
- {string} message - Success message if the subscription was upgraded immediately.
OR
- {string} action - The action performed (e.g., 'shopify').
- {string} url - URL to the ecommerce store with prefilled add-to-cart parameters.
- Type
- Promise.<UpgradeSubscriptionResponse>