Cloud Native 10 min read

Building a Subscription Management Mini Program with Tencent Cloud Serverless Functions

The article shows how a single front‑end developer can create the “Moly Subscription Assistant” WeChat mini‑program in five days using Tencent Cloud serverless development, covering OpenID authentication, cloud‑function CRUD for subscriptions, scheduled currency‑rate updates, and a fully managed backend without any traditional servers.

Tencent Cloud Developer
Tencent Cloud Developer
Tencent Cloud Developer
Building a Subscription Management Mini Program with Tencent Cloud Serverless Functions

With many online services offering subscription plans, managing recurring expenses becomes a common problem. The "Moly Subscription Assistant" mini‑program was created to help users conveniently track monthly subscriptions, leveraging WeChat Mini‑Program cloud development to avoid building a traditional backend server. The entire product was prototyped and launched in just five days.

The core product logic consists of three simple features: (1) users add a subscription, (2) the home page displays all subscriptions, and (3) a backend cloud function automatically calculates the average monthly expense.

Cloud development (Tencent Cloud Serverless) provides complete cloud support—cloud functions, a NoSQL database, and file storage—so developers can focus on business logic without managing servers or operations. A single qualified front‑end developer can implement the whole mini‑program.

To enable cloud development, add the field "cloudfunctionRoot":"cloudfunctions/" to project.config.json and set "cloud":true in app.json (or game.json ) for compatibility.

User authentication is handled by a cloud function that retrieves the trusted OpenID from the request context, eliminating the need for explicit user login. Example initialization in App.js :

App({
  onLaunch() {
    wx.cloud.init({ traceUser: true })
  }
})

Adding a subscription is implemented in a Node.js cloud function addUserSubscription (file main.js ):

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const openid = wxContext.OPENID
  const { data } = event
  return db.collection('subscriptions').add({
    data: Object.assign(data, { _openid: openid })
  })
}

Querying subscriptions uses another cloud function getUserSubscriptions :

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const openid = wxContext.OPENID
  return db.collection('subscriptions').where({ _openid: openid }).get()
}

After writing the functions, they can be deployed with a single "Upload and Deploy" click in the development tool, providing a fast and elegant backend deployment workflow.

On the client side, the mini‑program calls the cloud functions to retrieve the current user's subscriptions:

Page({
  data: { subscriptions: [] },
  onLoad() {
    wx.cloud.callFunction({ name: 'getUserSubscriptions' })
      .then(res => this.setData({ subscriptions: res.result.data }))
      .catch(console.log)
  }
})

To support multiple currencies, the app stores exchange rates in the cloud database and updates them periodically using a timed cloud‑function trigger. The trigger configuration ( config.json ) looks like:

{
  "triggers": [{
    "name": "updateCurrencyDaily",
    "type": "timer",
    "config": "0 0 */2 * * * *" // every 2 hours
  }]
}

The update function fetches real‑time rates from Alpha Vantage, iterates over a list of supported currencies, and writes the results back to the currency collection:

const cloud = require('wx-server-sdk')
const fetch = require('node-fetch')
cloud.init()
const db = cloud.database()
const API_KEY = 'SECRET'
const BASE_URL = `https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&to_currency=CNY&apikey=${API_KEY}`
exports.main = async (event, context) => {
  const supportCurrencyList = ['USD','JPY','EUR','GBP','HKD','AUD']
  const toCNY = {}
  for (const currency of supportCurrencyList) {
    const rate = await fetch(`${BASE_URL}&from_currency=${currency}`)
      .then(res => res.json())
      .then(res => res['Realtime Currency Exchange Rate']['5. Exchange Rate'])
    toCNY[currency] = parseFloat(rate)
  }
  return db.collection('currency').doc('some_id')
    .update({ data: Object.assign(toCNY, { date: new Date() }) })
}

Because the function uses node-fetch , the dependency must be added to package.json (e.g., "node-fetch":"^2.3.0" ) and installed via the cloud console or npm i node-fetch .

In summary, the article demonstrates how to use Tencent Cloud's serverless cloud development to quickly build a fully functional subscription‑management mini‑program, covering backend authentication, CRUD operations, scheduled tasks, and multi‑currency handling—all without provisioning any traditional servers.

DatabaseNode.jsWeChat Mini ProgramServerlessCloud FunctionsCurrency ExchangeSubscription Management
Tencent Cloud Developer
Written by

Tencent Cloud Developer

Official Tencent Cloud community account that brings together developers, shares practical tech insights, and fosters an influential tech exchange community.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.