# Set a PIN for a PAN-less Issuer
source: https://developer.mastercard.com/mastercard-processing-core/documentation/sandbox-testing/pin-management/set-pin-for-panless-issuer/index.md

## Test case -- Success {#test-case--success}

This test case describes setting a PIN by sending a PIN block in ISO-1 format encrypted with the Mastercard Processing Public RSA key retrieved by using a dedicated `/public-keys` endpoint.

Note: The test case does not describe the end-to-end payload encryption used for every API operation in the Sandbox environment. Refer to [Encryption](https://developer.mastercard.com/mastercard-processing-core/documentation/api-basics-section/encryption/index.md) for more information. For this test case, use the following information in the request:

<br />

|    Field    | Available value |
|-------------|-----------------|
| `Key-Index` | A1564386531162  |

|  Path parameter  | Available value |
|------------------|-----------------|
| card_contract_id | 70001           |
|                  | 70002           |
|                  | 70003           |
|                  | 70004           |
|                  | 70005           |

Note: To generate an encrypted value of the `newPinBlock` field, use the PIN assigned to the `card_contract_id` value which you want to use in the request.

| card_contract_id | PIN  |
|------------------|------|
| 70001            | 7580 |
| 70002            | 5336 |
| 70003            | 2360 |
| 70004            | 3011 |
| 70005            | 4041 |

And encrypt it with the following Public RSA key (the `Key-Index` = A1564386531162)
`30820122300D06092A864886F70D01010105000382010F003082010A0282010100A7D079A8769BCD340574E8E6C0A2810C377279E5EA0B422B9132F955860730E7637DFAB0A1C6F117B25E3DB3D2A5A9F2691BBC7E0178ADFD12908C3E6E6D3A77AA26E25A6570FCC423561628879E918DC0C798527318308C70BBE2BC4597B83B96CB3680FE6F8E60D68B465E2B30558712A2D63A544239BE7B5F2A49C82FB3388A22644741A945EC9ACB3F219C3B6826241BE1706EF384100EC83D0D7FAE6CCF4E69E0EE02BF84C21553FA1999A8DB91C4193D1E671D5A22B1876E1DC81F1ED7033F3A26FF62E492A63ADA58AAE248D5E47896592CB9A7023CB8B8700882B4DCBF34C16F7FA00DF4C3931A4612E0E2A09586780E89D28FAAA195C07ADE88286F0203010001`

**Sample request**

`PUT /cards/70001/pin -H "Key-Index: A1564386531162"`

```JSON
{
  "cardExpiryDate": "3004",
  "cardSequenceNumber": "2",
  "newPinBlock": "
    69DF3BAA5CAF165A940FC1F8AE68573B8AF93F5EDB20E208953E87CC50C19F0BB11A448AE76FA87A8940EE290FEBC2518DDAAB85BF4AA393FAE060F4CD30CC73AAFF3755680E59FC59BF8D2303B7990C1EC648A0D24D66D57DAB0147434B54955FEA38890C1AFDE6C60EE6D9174BC567D151669576D0395A1B235AF4CD7C581EF238FD26E1DF53085B09DDA9A81EE9DA02D7C7C9E0C266B60C7E9BAC046DCF704EC6CA31486CF6B562C28D47CD6ED124CAE28D3A2E590CFBAA90604090F601B16423E375D6CC01FAC5E0125F7BCC735ED53F88CB7D34FDEFBB19A0EE09F156E337150CE96B2A16419D0F0981CCE44EC8A946CEA69A238AA04EC46FDFFE91A03D"
}
```

**Sample response**

`204 `

## Test case -- Fail -- Invalid PIN block {#test-case--fail--invalid-pin-block}

This test case describes an attempt to set a PIN by sending an invalid PIN block.
**Sample request**

`PUT /cards/70001/pin -H "Key-Index: A1564386531162"`

```JSON
{
  "cardExpiryDate": "3004",
  "newPinBlock": "FFFFFFFFXX"
}
```

**Sample response**

`400`

```JSON
{
  "Errors": {
    "Error": [
      {
        "Source": "MASTERCARD PROCESSING",
        "ReasonCode": "REQUEST_VALIDATION",
        "Description": "Invalid field newPinBlock value in object pinCreation. Validation error: Field contains incorrect hexadecimal value."
        "Recoverable": false,
      }
    ]
  }
}
```

## Test case -- Fail -- Incorrect Card expiry date {#test-case--fail--incorrect-card-expiry-date}

This test case describes an attempt to set a PIN by sending an invalid card expiry date.

For this test case, use the following information in the request:

|      Field       | Available value |
|------------------|-----------------|
| `cardExpiryDate` | 2101            |

**Sample request**

`PUT /cards/70001/pin -H "Key-Index: A1564386531162"`

```JSON
{
  "cardExpiryDate": "2101",
  "newPinBlock": "
    69DF3BAA5CAF165A940FC1F8AE68573B8AF93F5EDB20E208953E87CC50C19F0BB11A448AE76FA87A8940EE290FEBC2518DDAAB85BF4AA393FAE060F4CD30CC73AAFF3755680E59FC59BF8D2303B7990C1EC648A0D24D66D57DAB0147434B54955FEA38890C1AFDE6C60EE6D9174BC567D151669576D0395A1B235AF4CD7C581EF238FD26E1DF53085B09DDA9A81EE9DA02D7C7C9E0C266B60C7E9BAC046DCF704EC6CA31486CF6B562C28D47CD6ED124CAE28D3A2E590CFBAA90604090F601B16423E375D6CC01FAC5E0125F7BCC735ED53F88CB7D34FDEFBB19A0EE09F156E337150CE96B2A16419D0F0981CCE44EC8A946CEA69A238AA04EC46FDFFE91A03D"
}
```

**Sample response**

`404`

```JSON
{
  "Errors": {
    "Error": [
      {
        "Source": "MASTERCARD PROCESSING",
        "ReasonCode": "INVALID_EXPIRY_DATE",
        "Description": "Expiry date 2101 does not match for the card contract with id 70001.",
        "Recoverable": false
      }
    ]
  }
}
```

## Test case -- Fail -- Card contract is not active {#test-case--fail--card-contract-is-not-active}

This test case describes an attempt to set a PIN for a card contract that is not active.

For this test case, use the following information in the request:

| Path parameter | Available value |
|----------------|-----------------|
| `contract_id`  | 10002           |

**Sample request**

`PUT /cards/10002/pin -H "Key-Index: A1564386531162"`

```JSON
{
  "cardExpiryDate": "3004",
  "newPinBlock": "
69DF3BAA5CAF165A940FC1F8AE68573B8AF93F5EDB20E208953E87CC50C19F0BB11A448AE76FA87A8940EE290FEBC2518DDAAB85BF4AA393FAE060F4CD30CC73AAFF3755680E59FC59BF8D2303B7990C1EC648A0D24D66D57DAB0147434B54955FEA38890C1AFDE6C60EE6D9174BC567D151669576D0395A1B235AF4CD7C581EF238FD26E1DF53085B09DDA9A81EE9DA02D7C7C9E0C266B60C7E9BAC046DCF704EC6CA31486CF6B562C28D47CD6ED124CAE28D3A2E590CFBAA90604090F601B16423E375D6CC01FAC5E0125F7BCC735ED53F88CB7D34FDEFBB19A0EE09F156E337150CE96B2A16419D0F0981CCE44EC8A946CEA69A238AA04EC46FDFFE91A03D"
}
```

**Sample response**

`400`

```JSON
{
  "Errors": {
    "Error": [
      {
        "Source": "MASTERCARD PROCESSING",
        "ReasonCode": "CARD_CONTRACT_STATUS_IS_WRONG",
        "Description": "Card contract with id 10002 in wrong status to set PIN.",
        "Recoverable": false
      }
    ]
  }
}
```

