# Payment

Provider API v0.6.6 · 2 operations
Source: https://plasapi.com/provider/v0.6.6/payment/

No description in the specification.

## Finalize Payment

`POST` `/patron/{patronId}/payment/finalize` · `FinalizePayment`

Finalize payment, mark fees as paid.

Multiple calls to finalize payment with the same payment ID will return the same confirmation ID, and the 
FinalizeFeeStatus will be 'registered' (provided, of course, that the previous call also resulted in status 'registered').

If in the configuration, payment->initialize->state is `use_initialize` and the initialize endpoint has not been called (e.g. if the order ID is not created), finalize returns the error code 300005.  
This also means that `orderId` is required in the request if payment->initialize->state is `use_initialize`. 

Multiple calls to finalize payment with the same payment ID will return the same confirmation ID for a minimum of 48 hours.  
If finalize is called a second time with the same payment ID, and any information in the request has changed, finalize returns the error code 300301.


### Example request

**cURL**

```bash
curl -X POST "$PLAS_BASE_URL/patron/40218873/payment/finalize?version=0.6.6" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $PLAS_TOKEN" \
  -d '{
  "fees": [
    {
      "amount": 15000,
      "id": "94549"
    }
  ],
  "method": "mobile_pay",
  "orderId": "ord_5f2a91c3",
  "paymentId": "pay_8d61b0e4"
}'
```

**JavaScript**

```javascript
const response = await fetch(`${process.env.PLAS_BASE_URL}/patron/40218873/payment/finalize?version=0.6.6`, {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": `Bearer ${process.env.PLAS_TOKEN}`,
  },
  body: JSON.stringify({
    "fees": [
      {
        "amount": 15000,
        "id": "94549"
      }
    ],
    "method": "mobile_pay",
    "orderId": "ord_5f2a91c3",
    "paymentId": "pay_8d61b0e4"
  }),
});
const data = await response.json();
```

**Python**

```python
import os
import requests

response = requests.post(
    f"{os.environ['PLAS_BASE_URL']}/patron/40218873/payment/finalize",
    params={
        "version": "0.6.6",
    },
    headers={
        "Accept": "application/json",
        "Content-Type": "application/json",
        "Authorization": f"Bearer {os.environ['PLAS_TOKEN']}",
    },
    json={
        "fees": [
            {
                "amount": 15000,
                "id": "94549",
            },
        ],
        "method": "mobile_pay",
        "orderId": "ord_5f2a91c3",
        "paymentId": "pay_8d61b0e4",
    },
)
data = response.json()
```

The host and token are environment variables: `PLAS_BASE_URL` the provider’s base URL · `PLAS_TOKEN` an access token.

### Parameters

- `patronId` (In `path`, `string`, required) — Patron ID from authentication

Shared across operations: `version`. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)

### Request body

`application/json` · required

[`FinalizePaymentRequestBody`](https://plasapi.com/provider/v0.6.6/schemas/#FinalizePaymentRequestBody)

### Responses

#### `200` Returns a response detailing how the finalize operation went for each fee ID.

`FinalizeFeesResponseBody`

Example (Generated from the schema):

```json
{
  "responses": {
    "response-1": {
      "confirmationId": "61946",
      "status": "registered"
    }
  }
}
```

#### `400` The list of errors.

`Errors`

Shared response, defined once for the whole API. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)

Example (Generated from the schema):

```json
{
  "errors": [
    {
      "code": 200103,
      "info": "200103: invalid/unsupported query parameter value"
    }
  ]
}
```

#### `401` Bearer token invalid, missing, or expired.

No response body.

Shared response, defined once for the whole API. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)

#### `404` Resource not found.

No response body.

Shared response, defined once for the whole API. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)

## Initialize payment

`POST` `/patron/{patronId}/payment/initialize` · `InitializePayment`

This validates that the method can be used, initializes the payment, and returns an order ID.


### Example request

**cURL**

```bash
curl -X POST "$PLAS_BASE_URL/patron/40218873/payment/initialize?version=0.6.6" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $PLAS_TOKEN" \
  -d '{
  "initialize": {
    "fees": [
      {
        "id": "94549"
      }
    ],
    "method": "mobile_pay"
  }
}'
```

**JavaScript**

```javascript
const response = await fetch(`${process.env.PLAS_BASE_URL}/patron/40218873/payment/initialize?version=0.6.6`, {
  method: "POST",
  headers: {
    "Accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": `Bearer ${process.env.PLAS_TOKEN}`,
  },
  body: JSON.stringify({
    "initialize": {
      "fees": [
        {
          "id": "94549"
        }
      ],
      "method": "mobile_pay"
    }
  }),
});
const data = await response.json();
```

**Python**

```python
import os
import requests

response = requests.post(
    f"{os.environ['PLAS_BASE_URL']}/patron/40218873/payment/initialize",
    params={
        "version": "0.6.6",
    },
    headers={
        "Accept": "application/json",
        "Content-Type": "application/json",
        "Authorization": f"Bearer {os.environ['PLAS_TOKEN']}",
    },
    json={
        "initialize": {
            "fees": [
                {
                    "id": "94549",
                },
            ],
            "method": "mobile_pay",
        },
    },
)
data = response.json()
```

The host and token are environment variables: `PLAS_BASE_URL` the provider’s base URL · `PLAS_TOKEN` an access token.

### Parameters

- `patronId` (In `path`, `string`, required) — Patron ID from authentication

Shared across operations: `version`. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)

### Request body

`application/json` · required

[`InitializePaymentRequestBody`](https://plasapi.com/provider/v0.6.6/schemas/#InitializePaymentRequestBody)

### Responses

#### `200` Returns a order ID which can be used to finalize the payment.

`InitializePaymentResponseBody`

Example (Generated from the schema):

```json
{
  "order": {
    "id": "94549"
  }
}
```

#### `400` The list of errors.

`Errors`

Shared response, defined once for the whole API. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)

Example (Generated from the schema):

```json
{
  "errors": [
    {
      "code": 200103,
      "info": "200103: invalid/unsupported query parameter value"
    }
  ]
}
```

#### `401` Bearer token invalid, missing, or expired.

No response body.

Shared response, defined once for the whole API. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)

#### `404` Resource not found.

No response body.

Shared response, defined once for the whole API. [See the shared contract on the version page.](https://plasapi.com/provider/v0.6.6/)
