xclade
Store APIPayment collections

Initialize Payment Session of a Payment Collection

Initialize and add a payment session to a payment collection. This is used during checkout, where you create a payment collection for the cart, then initialize a payment session for the payment provider that the customer chooses. It's highly recommended to have an amount greater than `0` in the payment collection, as some payment providers, such as Stripe, require a non-zero amount to create a payment session. Otherwise, an error will be thrown on the payment provider's side. In cases where you want to create a payment session for a payment collection with an amount of `0`, you can use the Manual System Payment Provider instead of third-party payment providers. The Manual System Payment Provider is built into Medusa and allows you to create payment sessions without interacting with an external payment provider. Make sure to configure the Manual System Payment Provider in your store's region. Learn more in the [Manage Region](https://) user guide.

POST
/store/payment-collections/{id}/payment-sessions

Path Parameters

id*string

The payment collection's ID.

Query Parameters

fields?string

Comma-separated fields that should be included in the returned data. if a field is prefixed with + it will be added to the default fields, using - will remove it from the default fields. without prefix it will replace the entire default fields.

Header Parameters

x-publishable-api-key*string

Publishable API Key created in the Medusa Admin.

Request Body

application/json

provider_id*string

The ID of the payment provider the customer chose.

data?object

Any data necessary for the payment provider to process the payment.

Response Body

application/json

application/json

text/plain

application/json

application/json

application/json

application/json

curl -X POST "https://{tenant}.api.myxclade.com/store/payment-collections/string/payment-sessions" \  -H "x-publishable-api-key: string" \  -H "Content-Type: application/json" \  -d '{    "provider_id": "pp_stripe_stripe"  }'
{
  "payment_collection": {
    "id": "string",
    "currency_code": "string",
    "amount": 0,
    "authorized_amount": 0,
    "captured_amount": 0,
    "refunded_amount": 0,
    "completed_at": "2019-08-24T14:15:22Z",
    "created_at": "2019-08-24T14:15:22Z",
    "updated_at": "2019-08-24T14:15:22Z",
    "metadata": {},
    "status": "canceled",
    "payment_providers": [
      {
        "id": "string"
      }
    ],
    "payment_sessions": [
      {
        "id": "string",
        "amount": 0,
        "currency_code": "usd",
        "provider_id": "string",
        "data": {},
        "context": {
          "customer": {
            "id": "cus_123"
          }
        },
        "status": "authorized",
        "authorized_at": "2019-08-24T14:15:22Z",
        "payment_collection": {},
        "payment": {
          "id": "string",
          "amount": 0,
          "authorized_amount": 0,
          "currency_code": "string",
          "provider_id": "string",
          "data": {},
          "created_at": "2019-08-24T14:15:22Z",
          "updated_at": "2019-08-24T14:15:22Z",
          "captured_at": "2019-08-24T14:15:22Z",
          "canceled_at": "2019-08-24T14:15:22Z",
          "captured_amount": 0,
          "refunded_amount": 0,
          "captures": [
            {
              "id": "string",
              "amount": 0,
              "created_at": "2019-08-24T14:15:22Z",
              "created_by": "string",
              "payment": {}
            }
          ],
          "refunds": [
            {
              "id": "string",
              "amount": 0,
              "refund_reason_id": "string",
              "note": "string",
              "created_at": "2019-08-24T14:15:22Z",
              "created_by": "string",
              "payment": {},
              "refund_reason": {
                "id": "string",
                "label": "string",
                "description": "string",
                "metadata": {},
                "created_at": "2019-08-24T14:15:22Z",
                "updated_at": "2019-08-24T14:15:22Z",
                "code": "string"
              }
            }
          ],
          "payment_collection": {},
          "payment_session": {}
        }
      }
    ],
    "payments": [
      {
        "id": "string",
        "amount": 0,
        "authorized_amount": 0,
        "currency_code": "string",
        "provider_id": "string",
        "data": {},
        "created_at": "2019-08-24T14:15:22Z",
        "updated_at": "2019-08-24T14:15:22Z",
        "captured_at": "2019-08-24T14:15:22Z",
        "canceled_at": "2019-08-24T14:15:22Z",
        "captured_amount": 0,
        "refunded_amount": 0,
        "captures": [
          {
            "id": "string",
            "amount": 0,
            "created_at": "2019-08-24T14:15:22Z",
            "created_by": "string",
            "payment": {}
          }
        ],
        "refunds": [
          {
            "id": "string",
            "amount": 0,
            "refund_reason_id": "string",
            "note": "string",
            "created_at": "2019-08-24T14:15:22Z",
            "created_by": "string",
            "payment": {},
            "refund_reason": {
              "id": "string",
              "label": "string",
              "description": "string",
              "metadata": {},
              "created_at": "2019-08-24T14:15:22Z",
              "updated_at": "2019-08-24T14:15:22Z",
              "code": "string"
            }
          }
        ],
        "payment_collection": {},
        "payment_session": {}
      }
    ]
  }
}

{
  "message": "Discount must be set to dynamic",
  "type": "not_allowed"
}

"Unauthorized"
{
  "message": "Entity with id 1 was not found",
  "type": "not_found"
}
{
  "code": "unknown_error",
  "message": "The request conflicted with another request. You may retry the request with the provided Idempotency-Key.",
  "type": "QueryRunnerAlreadyReleasedError"
}
{
  "code": "invalid_request_error",
  "message": "Discount with code TEST already exists.",
  "type": "duplicate_error"
}

{
  "code": "api_error",
  "message": "An error occured while hashing password",
  "type": "database_error"
}