Skip to main content
Skip to main content
You're viewing the documentation for v1, which isn't the latest Medusa version.Latest documentation

PaymentCollectionsResource

This class is used to send requests to Store Payment Collection API Routes. 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​

retrieve​

Retrieve a Payment Collection's details.

Example​

A simple example that retrieves a payment collection by its ID:

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:

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​

idstringRequired
The ID of the payment collection.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Configurations to apply on the retrieved payment collection.

Returns​

ResponsePromiseResponsePromise<StorePaymentCollectionsRes>Required
Resolves to the payment collection's details.

authorizePaymentSession​

Authorize a Payment Session of a Payment Collection.

Example​

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​

idstringRequired
The ID of the payment collection.
session_idstringRequired
The ID of the payment session.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<StorePaymentCollectionsRes>Required
Resolves to the payment collection's details.

authorizePaymentSessionsBatch​

Authorize the Payment Sessions of a Payment Collection.

Example​

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.authorizePaymentSessionsBatch(paymentCollectionId, {
session_ids: ["ps_123456"]
})
.then(({ payment_collection }) => {
console.log(payment_collection.id);
})

Parameters​

idstringRequired
The ID of the payment collection.
The list of payment session IDs to authorize.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<StorePaymentCollectionsRes>Required
Resolves to the payment collection's details.

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:

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:

medusa.paymentCollections.managePaymentSessionsBatch(paymentId, {
sessions: [
{
provider_id: "stripe",
amount: 10000,
session_id: "ps_123456"
},
]
})
.then(({ payment_collection }) => {
console.log(payment_collection.id);
})

Parameters​

idstringRequired
The ID of the payment collection.
The attributes of each session to update.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<StorePaymentCollectionsRes>Required
Resolves to the payment collection's details.

managePaymentSession​

Create a Payment Session for a payment provider in a Payment Collection.

Example​

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​

idstringRequired
The ID of the payment collection.
The payment session to create.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns​

ResponsePromiseResponsePromise<StorePaymentCollectionsRes>Required
Resolves to the payment collection's details.

refreshPaymentSession​

Refresh a Payment Session's data to ensure that it is in sync with the Payment Collection.

Example​

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.status);
})

Parameters​

idstringRequired
The ID of the payment collection.
session_idstringRequired
The ID of the payment session.
customHeadersRecord<string, any>Required

Default: {}

Returns​

ResponsePromiseResponsePromise<StorePaymentCollectionsSessionRes>Required
Resolves to the refreshed payment session's details.
Was this section helpful?