Skip to content

Commit

Permalink
Release v0.1.0-beta4 (#18)
Browse files Browse the repository at this point in the history
* Create api-integration-unit-tests.yml (#1)

* Create api-integration-unit-tests.yml

* Update api-integration-unit-tests.yml

* Update api-integration-unit-tests.yml

* Update api-integration-unit-tests.yml

* Update api-integration-unit-tests.yml

* Update api-integration-unit-tests.yml

* Update api-integration-unit-tests.yml

* Update api-integration-unit-tests.yml

* Improve dockerfile for better caching #3 (#4)

* Feature/helm deployment (#8)

* Create Helm Chart for Deployment inside Kubernetes #5

* Update deployment-staging.yml

* Update deployment-staging.yml

* Update deployment-staging.yml

* Update deployment-staging.yml

* Update deployment-staging.yml

* Update deployment-staging.yml

* Update deployment-staging.yml

* Update deployment-staging.yml

* Update deployment-staging.yml

* Adding production deployment workflow

* Fix patch Operation endpoint and add Swagger docs for it (#17)
  • Loading branch information
Paulo Sérgio Baima committed Dec 17, 2020
1 parent f92433d commit 148f91a
Show file tree
Hide file tree
Showing 8 changed files with 17,799 additions and 13 deletions.
3 changes: 2 additions & 1 deletion api/src/routes/MarketplaceRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ export default class MarketplaceRoute extends BaseRoute implements IMarketplaceR
@RouteConfig("patch", "/:subscriptionId/operations/:operationId")
async patchOperation(req: Request, res: Response, next: NextFunction): Promise<void> {
try {
console.log(req.params.operationId)
this.validateApiVersion(req);
await this.operationService.confirmChangePlan(req.params.subscriptionId, req.params.operationId, req.body.planId, req.body.quantity, req.body.status);
await this.operationService.confirmChangePlan(req.params.subscriptionId, req.params.operationId, req.body.status);
res.status(200).json("OK");
} catch (error) {
this.handleError(error, res);
Expand Down
74 changes: 74 additions & 0 deletions api/src/routes/interfaces/IMarketplaceRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,78 @@ export default interface IMarketplaceRoute extends BaseRoute {
* $ref: '#/components/schemas/InternalServerError'
*/
getOperation(req: Request, res: Response, next: NextFunction);

/**
* GET /api/saas/subscriptions/{subscriptionId}
* @swagger
* /api/saas/subscriptions/{subscriptionId}/operations/{operationId}:
* patch:
* tags:
* - "Operations"
* summary: "Update the status of an operation"
* description: "<p>Use this API to update the status of a pending operation to indicate the operation's success or failure on the publisher side.
The operationId for this API call can be retrieved from the value returned by Operation-Location, the get pending Operations API call, or the <id> parameter value received in a webhook call.</p>
* <br/>
* <a href=\"https://docs.microsoft.com/en-us/azure/marketplace/partner-center-portal/pc-saas-fulfillment-api-v2#update-the-status-of-an-operation\" target=\"_blank\">Official Documentation</a>"
* parameters:
* - in: header
* description: "(Ignored by the Sandbox) A unique string value for tracking the request from the client, preferably a GUID. If this value isn't provided, one will be generated and provided in the response headers."
* name: x-ms-requestid
* schema:
* type: string
* - in: header
* description: "(Ignored by the Sandbox) A unique string value for operation on the client. This parameter correlates all events from client operation with events on the server side. If this value isn't provided, one will be generated and provided in the response headers."
* name: x-ms-correlationid
* schema:
* type: string
* - in: header
* description: "(Ignored by the Sandbox) Get JSON web token (JWT) bearer token. For example: \"Bearer <access_token>\". https://docs.microsoft.com/en-us/azure/marketplace/partner-center-portal/pc-saas-registration#get-a-token-based-on-the-azure-ad-app"
* name: authorization
* schema:
* type: string
* - in: path
* description: "A unique identifier of the SaaS subscription that's obtained after resolving the token via Resolve API."
* name: subscriptionId
* schema:
* type: string
* required: true
* - in: path
* description: "The unique identifier of the operation being retrieved."
* name: operationId
* schema:
* type: string
* required: true
* - in: query
* name: api-version
* description: "The version of the API to use for this request. The Sandbox API currently validates against the API Version=2018-08-31"
* required: true
* example: "2018-08-31"
* requestBody:
* description: "Request payload example"
* required: true
* content:
* application/json:
* schema:
* type: object
* properties:
* status:
* type: string
* description: "Allowed Values: Success/Failure. Indicates the status of the operation on ISV side."
* example: "Success"
* responses:
* 200:
* description: Success
* 403:
* description: Unauthorized. The authentication token wasn't provided or is invalid, or the request is attempting to access an acquisition that doesn't belong to the current publisher.
* 404:
* description: Not found. The SaaS subscription with subscriptionId or the Operation with operation id is not found.
* 500:
* description: "Internal Server Error"
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/InternalServerError'
*/
patchOperation(req: Request, res: Response, next: NextFunction);
}
12 changes: 7 additions & 5 deletions api/src/services/OperationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ export default class OperationService implements IOperationService {
return this.operationRepository.listBySubscriptionDescendingByTimestamp(subscriptionId);;
}

async confirmChangePlan(subscriptionId: string, operationId: string, planId: string, quantity: string, status: string) {
async confirmChangePlan(subscriptionId: string, operationId: string, status: string) {
var operation = await this.operationRepository.getById(operationId);
var subscription = await this.subscriptionRepository.getById(subscriptionId);

operation.status = status == "Success" ? "Succeeded" : "Failed";
operation.status = status == "Success" ? "Succeed" : "Failed";

await this.operationRepository.updateOne(operation.id, operation);

subscription.planId = planId;
subscription.quantity = quantity;

if (operation.status == "Succeed") {
subscription.planId = operation.planId;
subscription.quantity = operation.quantity;
}

await this.subscriptionRepository.updateOne(subscription.id, subscription);
}

Expand Down
2 changes: 1 addition & 1 deletion api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface ISubscriptionService {
export interface IOperationService {
delete(operationId: string);
sendWebhook(operationId: string);
confirmChangePlan(operationId: string, subscriptionId: string, planId: string, quantity: string, status: string);
confirmChangePlan(operationId: string, subscriptionId: string, status: string);
changePlan(subscriptionId: string, planId: string, id?: string, activityId?: string, timeStamp?: string): Promise<{ id: string, webhookSent: boolean }>;
changeQuantity(subscriptionId: string, quantity: string, id?: string, activityId?: string, timeStamp?: string): Promise<{ id: string, webhookSent: boolean }>;
simulateSuspend(operation: IOperation): Promise<boolean>;
Expand Down
Loading

0 comments on commit 148f91a

Please sign in to comment.