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
authorizePaymentSession
Authorize a Payment Session of a Payment Collection.
Example
Parameters
id
stringRequiredsession_id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredResolves to the payment collection's details.
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredauthorizePaymentSessionsBatch
Authorize the Payment Sessions of a Payment Collection.
Example
Parameters
id
stringRequiredThe list of payment session IDs to authorize.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredResolves to the payment collection's details.
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredmanagePaymentSession
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
id
stringRequiredThe payment session to create.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredResolves to the payment collection's details.
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredmanagePaymentSessionsBatch
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:
Parameters
id
stringRequiredThe attributes of each session to update.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredResolves to the payment collection's details.
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredrefreshPaymentSession
Refresh a Payment Session's data to ensure that it is in sync with the Payment Collection.
Example
Parameters
id
stringRequiredsession_id
stringRequiredcustomHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StorePaymentCollectionsSessionRes>RequiredResolves to the refreshed payment session's details.
ResponsePromise
ResponsePromise<StorePaymentCollectionsSessionRes>Requiredretrieve
Retrieve a Payment Collection's details.
Example
A simple example that retrieves a payment collection by its 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
id
stringRequiredConfigurations to apply on the retrieved payment collection.
customHeaders
Record<string, any>RequiredDefault: {}
Returns
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>RequiredResolves to the payment collection's details.
ResponsePromise
ResponsePromise<StorePaymentCollectionsRes>Required