Add API endpoint to bulk provision add-on purchases
What does this MR do and why?
This change introduces a new API endpoint for subscription add-on purchases to bulk create or update add-on purchases from CDot via the API on GitLab. It uses the bulk provision service for add-on purchases for SaaS which gets introduced in the merge request Add bulk create or update service for add-on pu... (!164589 - merged). This is part of the larger effort https://gitlab.com/groups/gitlab-org/-/epics/14615+ to allow upgrade and downgrade of Duo add-on purchases.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
You can use a curl command to provision add-on purchases via the API:
curl --request POST \
--header "PRIVATE-TOKEN: glpat-LGC_dPdyk5yxgDYqX6g2" \
--header "Content-Type: application/json" \
--data '{ "add_on_purchases": { "duo_pro": [{ "quantity": 1, "started_on": "2024-01-01", "expires_on": "2024-12-31", "purchase_xid": "A-S1", "trial": false }] } }' \
"http://localhost:3000/api/v4/internal/gitlab_subscriptions/namespaces/319/subscription_add_on_purchases"
This request should return a response like the following:
[{"namespace_id":319,"namespace_name":"mr-161762","add_on":"Code Suggestions","quantity":1,"started_on":"2024-01-01","expires_on":"2024-12-31","purchase_xid":"A-S1","trial":false}]
You can also check the created add-on purchase on the Rails console with ::GitlabSubscriptions::AddOnPurchase.where(namespace: <namespace>)
Execute the curl command a second time with an adapted value like quantity
to test the update capabilities as well.
Besides that a green test suite should be suitable enough.
Resolves https://gitlab.com/gitlab-org/gitlab/-/issues/482132