# Payment

Provider API v0.6.6 · 2 operasjoner
Kilde: https://plasapi.com/no/provider/v0.6.6/payment/

Ingen beskrivelse i spesifikasjonen.

## 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.


### Eksempel på kall

**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()
```

Verten og tokenet er miljøvariabler: `PLAS_BASE_URL` providerens adresse · `PLAS_TOKEN` et access token.

### Parametere

- `patronId` (i `path`, `string`, påkrevd) — Patron ID from authentication

Felles for operasjonene: `version`. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

### Request body

`application/json` · påkrevd

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

### Svar

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

`FinalizeFeesResponseBody`

Eksempel (Generert fra skjemaet):

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

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

`Errors`

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

Eksempel (Generert fra skjemaet):

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

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

Ikke noe innhold i svaret.

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

#### `404` Resource not found.

Ikke noe innhold i svaret.

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/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.


### Eksempel på kall

**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()
```

Verten og tokenet er miljøvariabler: `PLAS_BASE_URL` providerens adresse · `PLAS_TOKEN` et access token.

### Parametere

- `patronId` (i `path`, `string`, påkrevd) — Patron ID from authentication

Felles for operasjonene: `version`. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

### Request body

`application/json` · påkrevd

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

### Svar

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

`InitializePaymentResponseBody`

Eksempel (Generert fra skjemaet):

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

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

`Errors`

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

Eksempel (Generert fra skjemaet):

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

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

Ikke noe innhold i svaret.

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)

#### `404` Resource not found.

Ikke noe innhold i svaret.

Felles svar, definert én gang for hele API-et. [Se den felles kontrakten på versjonssiden.](https://plasapi.com/no/provider/v0.6.6/)
