--- displayed_sidebar: jsClientSidebar slug: /references/js-client/PaymentCollectionsResource --- import ParameterTypes from "@site/src/components/ParameterTypes" # PaymentCollectionsResource This class is used to send requests to [Store Payment Collection API Routes](https://docs.medusajs.com/api/store#payment-collections). All its method are available in the JS Client under the `medusa.paymentCollections` property. A payment collection is useful for managing additional payments, such as for Order Edits, or installment payments. ## Methods ### authorizePaymentSession Authorize a Payment Session of a Payment Collection. #### Example ```ts 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.paymentCollections .authorize(paymentId, sessionId) .then(({ payment_collection }) => { console.log(payment_collection.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "payment_sessions", "type": "[PaymentSession](../internal/classes/internal.PaymentSession.mdx)[]", "description": "The details of the payment sessions created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "payments", "type": "[Payment](../internal/classes/internal.Payment.mdx)[]", "description": "The details of the payments created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region", "type": "[Region](../internal/classes/internal.Region.mdx)", "description": "The details of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region_id", "type": "`string`", "description": "The ID of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[PaymentCollectionStatus](../internal/enums/internal.PaymentCollectionStatus.mdx)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "type", "type": "[ORDER_EDIT](../modules/internal.mdx#order_edit)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### authorizePaymentSessionsBatch Authorize the Payment Sessions of a Payment Collection. #### Example ```ts 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.paymentCollections .authorize(paymentId) .then(({ payment_collection }) => { console.log(payment_collection.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "payment_sessions", "type": "[PaymentSession](../internal/classes/internal.PaymentSession.mdx)[]", "description": "The details of the payment sessions created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "payments", "type": "[Payment](../internal/classes/internal.Payment.mdx)[]", "description": "The details of the payments created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region", "type": "[Region](../internal/classes/internal.Region.mdx)", "description": "The details of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region_id", "type": "`string`", "description": "The ID of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[PaymentCollectionStatus](../internal/enums/internal.PaymentCollectionStatus.mdx)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "type", "type": "[ORDER_EDIT](../modules/internal.mdx#order_edit)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### managePaymentSession Create a Payment Session for a payment provider in a Payment Collection. #### Example ```ts 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.paymentCollections .managePaymentSession(payment_id, { provider_id: "stripe" }) .then(({ payment_collection }) => { console.log(payment_collection.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "payment_sessions", "type": "[PaymentSession](../internal/classes/internal.PaymentSession.mdx)[]", "description": "The details of the payment sessions created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "payments", "type": "[Payment](../internal/classes/internal.Payment.mdx)[]", "description": "The details of the payments created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region", "type": "[Region](../internal/classes/internal.Region.mdx)", "description": "The details of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region_id", "type": "`string`", "description": "The ID of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[PaymentCollectionStatus](../internal/enums/internal.PaymentCollectionStatus.mdx)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "type", "type": "[ORDER_EDIT](../modules/internal.mdx#order_edit)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### managePaymentSessionsBatch Create, update, or delete a list of payment sessions of a Payment Collections. If a payment session is not provided in the `sessions` array, it's deleted. #### Example To add two new payment sessions: ```ts 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 // Total amount = 10000 medusa.paymentCollections .managePaymentSessionsBatch(paymentId, { sessions: [ { provider_id: "stripe", amount: 5000, }, { provider_id: "manual", amount: 5000, }, ], }) .then(({ payment_collection }) => { console.log(payment_collection.id) }) ``` To update a payment session and another one by not including it in the payload: ```ts medusa.paymentCollections .managePaymentSessionsBatch(paymentId, { sessions: [ { provider_id: "stripe", amount: 10000, session_id: "ps_123456", }, ], }) .then(({ payment_collection }) => { console.log(payment_collection.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "payment_sessions", "type": "[PaymentSession](../internal/classes/internal.PaymentSession.mdx)[]", "description": "The details of the payment sessions created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "payments", "type": "[Payment](../internal/classes/internal.Payment.mdx)[]", "description": "The details of the payments created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region", "type": "[Region](../internal/classes/internal.Region.mdx)", "description": "The details of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region_id", "type": "`string`", "description": "The ID of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[PaymentCollectionStatus](../internal/enums/internal.PaymentCollectionStatus.mdx)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "type", "type": "[ORDER_EDIT](../modules/internal.mdx#order_edit)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### refreshPaymentSession Refresh a Payment Session's data to ensure that it is in sync with the Payment Collection. #### Example ```ts import Medusa from "@medusajs/medusa-js" const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) medusa.paymentCollections .refreshPaymentSession(paymentCollectionId, sessionId) .then(({ payment_session }) => { console.log(payment_session.id) }) ``` #### Parameters `", "description": "", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "The data required for the Payment Provider to identify, modify and process the Payment Session. Typically this will be an object that holds an id to the external payment session, but can be an empty object if the Payment Provider doesn't hold any state.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "id", "type": "`string`", "description": "The payment session's ID", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "idempotency_key", "type": "`string`", "description": "Randomly generated key used to continue the completion of a cart in case of failure.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "is_initiated", "type": "`boolean`", "description": "A flag to indicate if a communication with the third party provider has been initiated.", "optional": false, "defaultValue": "false", "expandable": false, "children": [] }, { "name": "is_selected", "type": "``null`` \\| `boolean`", "description": "A flag to indicate if the Payment Session has been selected as the method that will be used to complete the purchase.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "payment_authorized_at", "type": "`Date`", "description": "The date with timezone at which the Payment Session was authorized.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "provider_id", "type": "`string`", "description": "The ID of the Payment Provider that is responsible for the Payment Session", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "`string`", "description": "Indicates the status of the Payment Session. Will default to `pending`, and will eventually become `authorized`. Payment Sessions may have the status of `requires\\_more` to indicate that further actions are to be completed by the Customer.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} /> ___ ### retrieve Retrieve a Payment Collection's details. #### Example A simple example that retrieves a payment collection by its ID: ```ts 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.paymentCollections .retrieve(paymentCollectionId) .then(({ payment_collection }) => { console.log(payment_collection.id) }) ``` To specify relations that should be retrieved: ```ts 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.paymentCollections .retrieve(paymentCollectionId, { expand: "region", }) .then(({ payment_collection }) => { console.log(payment_collection.id) }) ``` #### Parameters `", "description": "Custom headers to attach to the request.", "optional": false, "defaultValue": "{}", "expandable": false, "children": [] } ]} /> #### Returns `", "description": "An optional key-value map with additional details", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "payment_sessions", "type": "[PaymentSession](../internal/classes/internal.PaymentSession.mdx)[]", "description": "The details of the payment sessions created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "payments", "type": "[Payment](../internal/classes/internal.Payment.mdx)[]", "description": "The details of the payments created as part of the payment collection.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region", "type": "[Region](../internal/classes/internal.Region.mdx)", "description": "The details of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": true, "children": [] }, { "name": "region_id", "type": "`string`", "description": "The ID of the region this payment collection is associated with.", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "status", "type": "[PaymentCollectionStatus](../internal/enums/internal.PaymentCollectionStatus.mdx)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "type", "type": "[ORDER_EDIT](../modules/internal.mdx#order_edit)", "description": "The type of the payment collection", "optional": false, "defaultValue": "", "expandable": false, "children": [] }, { "name": "updated_at", "type": "`Date`", "description": "The date with timezone at which the resource was updated.", "optional": false, "defaultValue": "", "expandable": false, "children": [] } ] } ] } ] } ]} />