chore: markAsAuthorized and payment collection tests (#2620)
* chore: markAsAuthorized and payment collection tests
This commit is contained in:
@@ -36,6 +36,11 @@ export default (app, container) => {
|
||||
middlewares.wrap(require("./update-payment-collection").default)
|
||||
)
|
||||
|
||||
route.post(
|
||||
"/:id/authorize",
|
||||
middlewares.wrap(require("./mark-authorized-payment-collection").default)
|
||||
)
|
||||
|
||||
route.delete(
|
||||
"/:id",
|
||||
middlewares.wrap(require("./delete-payment-collection").default)
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
import { EntityManager } from "typeorm"
|
||||
import { PaymentCollectionService } from "../../../../services"
|
||||
|
||||
/**
|
||||
* @oas [post] /payment-collections/{id}/authorize
|
||||
* operationId: "MarkAuthorizedPaymentCollectionsPaymentCollection"
|
||||
* summary: "Set the status of PaymentCollection as Authorized"
|
||||
* description: "Sets the status of PaymentCollection as Authorized."
|
||||
* x-authenticated: true
|
||||
* parameters:
|
||||
* - (path) id=* {string} The ID of the PaymentCollection.
|
||||
* x-codeSamples:
|
||||
* - lang: JavaScript
|
||||
* label: JS Client
|
||||
* source: |
|
||||
* import Medusa from "@medusajs/medusa-js"
|
||||
* const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
|
||||
* // must be previously logged in or use api token
|
||||
* medusa.admin.paymentCollections.markAsAuthorized(payment_collection_id)
|
||||
* .then(({ payment_collection }) => {
|
||||
* console.log(payment_collection.id)
|
||||
* })
|
||||
* - lang: Shell
|
||||
* label: cURL
|
||||
* source: |
|
||||
* curl --location --request POST 'https://medusa-url.com/admin/payment-collections/{id}/authorize' \
|
||||
* --header 'Authorization: Bearer {api_token}'
|
||||
* security:
|
||||
* - api_token: []
|
||||
* - cookie_auth: []
|
||||
* tags:
|
||||
* - PaymentCollection
|
||||
* responses:
|
||||
* 200:
|
||||
* description: OK
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* properties:
|
||||
* payment_collection:
|
||||
* $ref: "#/components/schemas/payment_collection"
|
||||
* "400":
|
||||
* $ref: "#/components/responses/400_error"
|
||||
* "401":
|
||||
* $ref: "#/components/responses/unauthorized"
|
||||
* "404":
|
||||
* $ref: "#/components/responses/not_found_error"
|
||||
* "409":
|
||||
* $ref: "#/components/responses/invalid_state_error"
|
||||
* "422":
|
||||
* $ref: "#/components/responses/invalid_request_error"
|
||||
* "500":
|
||||
* $ref: "#/components/responses/500_error"
|
||||
*/
|
||||
export default async (req, res) => {
|
||||
const { id } = req.params
|
||||
|
||||
const paymentCollectionService: PaymentCollectionService = req.scope.resolve(
|
||||
"paymentCollectionService"
|
||||
)
|
||||
|
||||
const manager: EntityManager = req.scope.resolve("manager")
|
||||
const paymentCollection = await manager.transaction(
|
||||
async (transactionManager) => {
|
||||
return await paymentCollectionService
|
||||
.withTransaction(transactionManager)
|
||||
.markAsAuthorized(id)
|
||||
}
|
||||
)
|
||||
|
||||
res.status(200).json({ payment_collection: paymentCollection })
|
||||
}
|
||||
Reference in New Issue
Block a user