Follow this guide to create API functionality to create a B2C user subscription on your product using the Cofor.io Product SDK for Node.js.
To signup a new user for your B2C product, the user needs to first login or signup to Cofor.io through the OAuth screen. Send the user to https://cofor.io/oauth/create on the frontend with the query parameters: product_id, redirect_uri, the mode parameter set to b2c and optionally, state. (Use state to send information about product plan, etc.).
Email Verification
The user will be required to verify their email if creating a new account.
If the user is authenticated, a user signup token will be generated that allows the product to create a team on behalf of the user. Call the following function to create a new team using the team creation token provided.
const { membership, confirm_url } = await cio.SignupMember(USER_SIGNUP_TOKEN, scopes=[], data={}, subscribe_to_plans=[], trial_days=0);
The subscribe_to_plans argument is a list of Stripe pricing plans with quantities (optional) to subscribe the team to. The schema is as follows:
[{
plan_id: String, // Stripe pricing plan id
quantity: Number // Optional quantity
}, ... ]
After creating the team, the user needs to confirm that they would like to login to the team. This is how a login is created for the user. Send the user to https://cofor.io/oauth/confirm with the following URL query parameters:
- product - product ID
- user - user ID of the owner (returned by cio.NewTeam)
- membership - membership ID of the owner (returned by cio.NewTeam)
- redirect_uri - URL to return the user to after successful login or in case of error
- state - (Optional) any provided value which will be returned to the redirect URI as is.
The confirmation URL (minus redirect_uri which you can add yourself) is returned as well.
