Subscription Plans (User groups)

With the next request, you can get all info about the subscription plans:

method: GET
URL: /user_groups.json

PARAMETERS:
{
  “media_page”: “NUMBER” # Pagination, starting on 1 (if 0 or null, no pagination) 
}
RETURN:
{
  "page": "user_groups",
  "user_groups": [
    {
      “SUBSCRIPTION PLAN INFO"
    }
  ],
  "pagination": {
    "current": “NUMBER”, # Current page
    "last": true/false # If last page, true
  }
}

Using the subscription plan ID, you can get more detailed information:

method: GET
URL: /user_groups/ID.json # ID Format NUMBER-TEXT

PARAMETERS:
RETURN:
{
  "code": "ok", #In case of an error, a message will be displayed
  "error": true/false,
  "page": "user_group",
  “user_group”:
    {
      "id": "ID",
      "name": "NAME",
      "description": "DESCRIPTION",
      "html_description": "HTML ADDITIONAL DESCRIPTION",
      "promote": true/false, # Promote on Home Page
      "demote": true/false, # Do not show on Home
      "plans": {
        ["monthly"|"quarterly"|"triannually"|"semiannual"|"annual"|"biennial"|"perpetual"]: {
          "price": "PRICE”
          "installments": [ # If "installment" = true
            {
              "number": NUMBER,
              "price": "PRICE"
            }
          ]
        }
      },
      "recurrent": true/false,
      "installment": true/false,
      "max_installments": NUMBER,
      "coupon": true/false,
      "coupon_required": true/false,
      "payment_methods": ["card", "boleto","coupon"],
      "subscribed": true/false, # If current user has subscription for this plan
      "trial": true/false,
      "trial_days": NUMBER,
      "trial_user": true/false
    },
  "channels": [
    {
      “CHANNEL INFO” # Return info of all channels associated with this plan
    }
    "pagination": {
      "current": “NUMBER”, # Current page
      "last": true/false # If last page, true
    }
  ]
}

After get all info about the plans, you can subscribe an user with a specific TOKEN:

method: POST
URL: /user_groups/ID/subscribe.json # ID Format NUMBER-TEXT

PARAMETERS:
{
  “payment_method”: [“card”|”boleto”|”coupon”] 
  “card_token”: [“TOKEN”|"default"] # If “payment_method” = “card”
  “installments”: NUMBER # If “payment_method” = “card”
  "payer": { # If “payment_method” = “boleto”
    "name": "NAME",
    "cpf_cnpj": "CPF/CNPJ",
    "address": {
      "street": "STREET",
      "number": "NUMBER",
      "complement": "COMPLEMENT"
      "zip_code": "ZIP CODE"
      "city": "CITY"
      "state": "STATE"
      "country": "COUNTRY"
    }
  },
  “coupon”: "CODE", 
  “reload”: true, # To reload price using coupon
  “duration”: “DURATION”
}
RETURN:
{
  "status": true/false, # status_code 200/400
  "user_group": {
    "USER GROUP INFO"
  }, # If "reload" = true
  "coupon": {
    "id": "ID",
    "code": "CODE",
    "description": "DESCRIPTION",
  }, # If "reload" = true
  "errors": { # If "status" = false
    "user_group": {
      "FIELD": [ 
        "ERROR MESSAGE"
      ]
    }
  }
}

You can also subscribe using only the unique coupon code:

method: POST
URL: /code_redeems.json

PARAMETERS:
{
  “coupon”: {
    "code": "CODE"
  }
}
RETURN:
{
  "status": true/false, # status_code 200/400
  "user_group_id": "ID" # If logged in (coupon will only be validated if not logged in)
  "errors": { # If "status" = false
    "coupon": {
      "FIELD": [ 
        "ERROR MESSAGE"
      ]
    }
  }
}

Following, we show how to get a specific content thumbnail:

URL: /user_groups/[ID]/retrieve?format=thumb
ID: format NUMBER-TEXT

To allow or forbid a user access to the subscription plan:

method: POST

URL: /management/user_groups/[USER_GROUP_ID]/allow_user/[USER_ID].json

method: POST

URL: /management/user_groups/[USER_GROUP_ID]/forbid_user/[USER_ID].json

Performing the following calls, you can add or remove users to a specific subscription plan:

method: POST

URL: /management/user_groups/[USER_GROUP_ID]/add_user/[USER_ID].json

method: POST

URL: /management/user_groups/[USER_GROUP_ID]/remove_user/[USER_ID].json

To delete a subscription plan

method: DELETE

URL: /management/user_groups/[USER_GROUP_ID].json

You can duplicate an existing subscription plan

method: POST

URL: /management/user_groups/[USER_GROUP_ID]/duplicate.json

PARAMETERS:
{
  "user_group": {
    "name": "NAME"
  }
}
RETURN: 
{ 
  "code": "ok", #In case of an error, a message will be displayed 
  "error": true/false, 
  "user_group": 
         { 
         "USER GROUP INFO" 
         }
 }

To update a subscription plan

method: PUT

URL /management/user_groups/[USER_GROUP_ID].json

PARAMETERS:
{   
  "user_group": {               
          "available_languages": ["en", "pt", "es", "de"],              
          "name": "UPDATED NAME",              
          "promote": [ "0" | "1" ] , # Promote at Home Page        
          "demote": [ "0" | "1" ], # Do not show at Home Page        
          "recommended": [ "0" | "1" ],               
          "status": ["available" | "unavailable"],               
          "description": " UPDATED DESCRIPTION"
}
RETURN: 
{ 
  "code": "ok", #In case of an error, a message will be displayed 
  "error": true/false, 
  "user_group": { 
     "USER GROUP INFO" 
   }
}

To create a new subscription plan

method: POST

URL: /management/user_groups.json

PARAMETERS:
{
  "user_group": {
              "available_languages": ["en", "pt", "es", "de"],
              "name": "NAME",
              "promote": [ "0" | "1" ] , # Promote at Home Page
              "demote": [ "0" | "1" ], # Do not show at Home Page
              "recommended": [ "0" | "1" ],
              "status": ["available" | "unavailable"],
              "description": "DESCRIPTION",
              "start_date": "",
              "end_date": "",
              "free_subscription": "false",
              "subscriptions_limit": "",
              "security": [ "private" | "public" ],
              "recurrent": true/false
              "payment_gateway_id": "",
              "plans": {
                      "monthly": {
                        "enabled": "0"
                      },
                      "quarterly": {
                        "enabled": "0"
                      },
                      "triannually": {
                        "enabled": "0"
                      },
                      "semiannual": {     
                        "enabled": "1",   #Example of chosen plan
                        "price": "0.00",
                      },
                      "annual": {
                        "enabled": "0"
                      },
                      "biennial": {
                        "enabled": "0"
                      },
                      "perpetual": {
                        "enabled": "0"
                      }
                  },
              "trial": true/false,
              "trial_days": NUMBER, #if trial = true
              "installment": true/false,
              "max_installments": NUMBER, #if installment = true
              "interest_rate": "0.00",
              "coupon_required": [ "0" | "1" ],
              "payment_method": [
                                 "coupon"
                                ],
              "tvod": true/false
           }
  }

RETURN:
{
  "code": "ok", #In case of an error, a message will be displayed
  "error": true/false,
  "user_group": {
             "USER GROUP INFO"
           } 
}
<< Previous topic Next topic >>