Skip to content

Add API endpoints to sync add-on purchases

What does this MR do and why?

Part of https://gitlab.com/gitlab-org/gitlab/-/issues/414605+

Depends on Add Add-on purchase API services (!123387 - merged) to be merged first

To be able to sync data from an add-on purchase from CustomersDot to GitLab.com new API endpoints are needed. This change adds endpoints to create, get and update an add-on purchase for a specific namespace and add-on. The endpoints are behind the feature flag purchase_code_suggestions.

How to set up and validate locally

  1. Create the code suggestions add-on in the rails console (note: This record will be added as a post migration in another MR):

    GitlabSubscriptions::AddOn.create(name: :code_suggestions, description: 'Add-on for code suggestions')
  2. Enable the feature flag purchase_code_suggestions: Feature.enable(:purchase_code_suggestions).

  3. Test the POST endpoint:

    Test scenarios
    1. With invalid access (same logic for all endpoints):
    curl --request POST \
      --url http://gdk.test:3000/api/v4/namespaces/<NAMESPACE_ID>/subscription_add_on_purchase/code_suggestions \
      --header 'Content-Type: application/json' \
      --header 'PRIVATE-TOKEN: invalid-access-token' \
      --data '{
          "quantity": 1,
          "expires_on": "2023-08-01",
          "purchase_xid": "1a2b3c" 
      }'
    1. With feature flag disabled namespace (same logic for all endpoints):

      1. Disable the feature flag in the rails console: Feature.disable(:purchase_code_suggestions) (turn it back on afterwards).
      2.  curl --request POST \
           --url http://gdk.test:3000/api/v4/namespaces/<NAMESPACE_ID>/subscription_add_on_purchase/code_suggestions \
           --header 'Content-Type: application/json' \
           --header 'PRIVATE-TOKEN: <PRIVATE_TOKEN>' \
           --data '{
               "quantity": 0,
               "expires_on": "2023-08-01",
               "purchase_xid": "1a2b3c" 
           }'
    2. With invalid namespace (same logic for all endpoints):

    curl --request GET \
      --url http://gdk.test:3000/api/v4/namespaces/123456789/subscription_add_on_purchase/code_suggestions \
      --header 'Content-Type: application/json' \
      --header 'PRIVATE-TOKEN: invalid-access-token'
    1. With invalid add-on (same logic for all endpoints):
    curl --request GET \
      --url http://gdk.test:3000/api/v4/namespaces/123456789/subscription_add_on_purchase/non-existing-add-on \
      --header 'Content-Type: application/json' \
      --header 'PRIVATE-TOKEN: invalid-access-token'
    1. With validation errors:
    curl --request POST \
      --url http://gdk.test:3000/api/v4/namespaces/<NAMESPACE_ID>/subscription_add_on_purchase/code_suggestions \
      --header 'Content-Type: application/json' \
      --header 'PRIVATE-TOKEN: <PRIVATE_TOKEN>' \
      --data '{
          "quantity": 0,
          "expires_on": "2023-08-01",
          "purchase_xid": "1a2b3c" 
      }'
    1. With successful request:
    curl --request POST \
      --url http://gdk.test:3000/api/v4/namespaces/<NAMESPACE_ID>/subscription_add_on_purchase/code_suggestions \
      --header 'Content-Type: application/json' \
      --header 'PRIVATE-TOKEN: <PRIVATE_TOKEN>' \
      --data '{
          "quantity": 1,
          "expires_on": "2023-08-01",
          "purchase_xid": "1a2b3c" 
      }'
  4. Test the GET endpoint:

     curl --request GET \
       --url http://gdk.test:3000/api/v4/namespaces/264/subscription_add_on_purchase/code_suggestions \
       --header 'Content-Type: application/json' \
       --header 'PRIVATE-TOKEN: <PRIVATE_TOKEN>'
  5. Test the PUT endpoint:

    Test scenarios
    1. With validation errors:
    curl --request PUT \
      --url http://gdk.test:3000/api/v4/namespaces/<NAMESPACE_ID>/subscription_add_on_purchase/code_suggestions \
      --header 'Content-Type: application/json' \
      --header 'PRIVATE-TOKEN: <PRIVATE_TOKEN>' \
      --data '{
          "quantity": 0,
          "expires_on": "2023-08-15",
          "purchase_xid": "1a2b3c" 
      }'
    1. With successful request:
    curl --request PUT \
      --url http://gdk.test:3000/api/v4/namespaces/<NAMESPACE_ID>/subscription_add_on_purchase/code_suggestions \
      --header 'Content-Type: application/json' \
      --header 'PRIVATE-TOKEN: <PRIVATE_TOKEN>' \
      --data '{
          "quantity": 5,
          "expires_on": "2023-08-15",
          "purchase_xid": "1a2b3c" 
      }'

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Corinna Gogolok

Merge request reports