# Set up required endpoints

## Set up required endpoints

FEATURE FOR MANAGED PARTNERS ONLY

This is a feature intended for managed partners. If you are not a managed partner and would like to become one, please reach out to us on our <mark style="color:blue;">#dev-discussion channel</mark> on Discord.

If you are a managed partner, your partner success manager needs to set up a commercial partnership with MoonPay for you. Please reach out to them to facilitate this.

In order to <mark style="color:blue;">implement</mark> this NFT primary sale card checkout feature, you need to complete the following:

1. Establish a commercial partnership with MoonPay (your partner success manager will facilitate this for you)
2. <mark style="color:blue;">Set up and register with XpansionChain with the required endpoints</mark>

### How to set up and register endpoints[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#how-to-set-up-and-register-endpoints) <a href="#how-to-set-up-and-register-endpoints" id="how-to-set-up-and-register-endpoints"></a>

💡STEPS:

1. <mark style="color:blue;">Create required endpoints</mark>
2. <mark style="color:blue;">Register with XpansionChain using created endpoints</mark>
3. <mark style="color:blue;">Validate the</mark> <mark style="color:blue;"></mark><mark style="color:blue;">`IMX-Signature`</mark>

#### 1. Create endpoints[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#1-create-endpoints) <a href="#id-1-create-endpoints" id="id-1-create-endpoints"></a>

You are required to provide the following endpoints:

1. <mark style="color:blue;">Trigger the mint</mark>: An endpoint to mint the asset once payment has been confirmed with MoonPay
2. <mark style="color:blue;">Get asset info</mark>: An endpoint to get information about the minted asset and render the checkout

#### Triggering the mint endpoint[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#triggering-the-mint-endpoint) <a href="#triggering-the-mint-endpoint" id="triggering-the-mint-endpoint"></a>

**Headers required:**[**​**](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#headers-required)

| Name                                                                    | Description                                                     |
| ----------------------------------------------------------------------- | --------------------------------------------------------------- |
| `IMX-Signature` - <mark style="color:blue;">How to validate this</mark> | Signature to confirm that the request was made by XpansionChain |
| `IMX-Timestamp` - <mark style="color:blue;">How to generate this</mark> | Timestamp header to validate `IMX-Signature`                    |

**Request body:**[**​**](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#request-body)

| Property                  | Type          | Description                                                                                  |
| ------------------------- | ------------- | -------------------------------------------------------------------------------------------- |
| `offer_id`                | String        | The ID of the offer provided for the NFT to be minted                                        |
| `contract_address`        | String        | Smart contract address of the NFT                                                            |
| `user`                    | String        | User that the NFT will be minted for (will become the NFT's owner)                           |
| `wallet_address`          | String        | Wallet address that will receive the payment, in crypto (from MoonPay), for the minted NFT   |
| `external_transaction_id` | String (UUID) | Unique XpansionChaintransaction ID that can be used to get information about the transaction |

**Response:**[**​**](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#response)

| Property           | Type    | Descrtiption                                                                      |
| ------------------ | ------- | --------------------------------------------------------------------------------- |
| `contract_address` | String  | Smart contract address of the NFT                                                 |
| `token_id`         | String  | Token ID (as specified by the NFT smart contract) of the minted asset             |
| `tx_id`            | Integer | Minting transaction ID - see <mark style="color:blue;">mintTokens</mark> response |

**Example:**[**​**](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#example)

```
Request: POST /mint
headers: {
  "IMX-Signature": "5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd",
  "IMX-Timestamp": "1492774577"
}

data: {
  "offer_id": "string",
  "contract_address": "string",
  "user": "string",
  "wallet_address": "string",
  "external_transaction_id": "string(UUID)",
}

Status: 200
Response: {
  "contract_address": "string",
  "token_id": "string",
  "tx_id": 0
}
```

ERROR ON MINT

If minting fails, please provide a response with the error code and message.

```
Response: {
 "code": "number", // the error code
 "message": "string", // the error message
 "details": "string" // the error details
}
```

#### Get asset info endpoint[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#get-asset-info-endpoint) <a href="#get-asset-info-endpoint" id="get-asset-info-endpoint"></a>

This endpoint will be used to get information about the asset to be minted using <mark style="color:blue;">trigger mint endpoint</mark>.

**Response:**[**​**](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#response-1)

| Property              | Type   | Description                                                                                |
| --------------------- | ------ | ------------------------------------------------------------------------------------------ |
| `offer_id`            | String | The ID of the offer provided for the NFT to be minted                                      |
| `contract_address`    | String | Smart contract address of the NFT                                                          |
| `name`                | String | Token name to be rendered at checkout                                                      |
| `collection`          | String | Collection name to be rendered at checkout                                                 |
| `image_url`           | String | URL where the image to be displayed for the minted asset is hosted                         |
| `price_currency_code` | String | Currency of the amount to be paid. Choose from: `"ETH"` or `"USDC"`                        |
| `price`               | String | Amount of the currency required to mint the token                                          |
| `seller_address`      | String | Wallet address that will receive the payment, in crypto (from MoonPay), for the minted NFT |

**Example:**[**​**](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#example-1)

```
Example Request: GET /:contract_address/:offer_id

Status: 200
Response: {
 "offer_id": "123",
 "contract_address": "0xacb3...",
 "name": "SiShinylver Card Pack",
 "collection": "Gods Unchained",
 "image_url": "https://images.godsunchained.com/cardpack-images--marketing/256/mortal--neutral--shiny--legendary.png",
 "price": "125.29",
 "price_currency_code": "USD",
 "seller_address": "0xacb3...",
}
```

UNAVAILABLE OFFER

If an offer is unavailable, a response should return `404 - Not Found`.

```
Status: 404
Response: {
 "code": "404", // the error code
 "message": "Missing offer", // the error message
 "details": "The offer id {offer_id} is not a valid offer for purchase" // the error details
}
```

#### 2. Register with XpansionChain using created endpoints[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#2-register-with-immutable-x-using-created-endpoints) <a href="#id-2-register-with-immutable-x-using-created-endpoints" id="id-2-register-with-immutable-x-using-created-endpoints"></a>

When you've set up the endpoints required in the previous step, please register with XpansionChain using the <mark style="color:blue;">registerNftPrimarySalesContract</mark> API endpoint.

After registration, XpansionChain will send you a webhook key that will be used to validate the signature when initiating mint requests.

#### 3. How to validate the `IMX-Signature`[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#3-how-to-validate-the-imx-signature) <a href="#id-3-how-to-validate-the-imx-signature" id="id-3-how-to-validate-the-imx-signature"></a>

Generate a `signed_payload` by concatenating the following:

* `IMX-Timestamp` header
* The character `.`
* JSON payload of the message to be signed

Example:

```
const payload = JSON.stringify({
  offer_id: '1',
  contract_address: '0x23a...',
  user: '0x8b1...',
  wallet_address: '0x11a...',
  external_transaction_id: '00000000-0000-0000-aaaa-0000a000aa00',
});

const signed_payload = imx_timestamp_header_value + '.' + payload;
```

You will then need to compute an HMAC with the SHA-256 hash function using the webhook key that we provided when you <mark style="color:blue;">registered the endpoints with</mark> XpansionChain for the `signed_payload` and use it to compare the signature in the header:

```
import crypto from 'crypto-js';

const generatedSignature = crypto
  .HmacSHA256(signed_payload, webhookKey)
  .toString();
```

### More information[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#more-information) <a href="#more-information" id="more-information"></a>

#### Main flow diagram:[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#main-flow-diagram) <a href="#main-flow-diagram" id="main-flow-diagram"></a>

![NFT Checkout Primary Main flow](https://3017072639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7a6afyDwSEkvWtt1UhmH%2Fuploads%2F7qzRYVHAiZLfxBE1N3Ac%2F1%20%E6%9C%80%E4%B8%8A%E9%9D%A2IIMUTABLE%20%E6%94%B9XpansionChain.png?alt=media\&token=af1db51e-834b-43a2-ad69-c318772c4aef)

#### Technical flow diagram:[​](https://docs.x.immutable.com/docs/x/setup-primary-sale-card-checkout#technical-flow-diagram) <a href="#technical-flow-diagram" id="technical-flow-diagram"></a>

![NFT Checkout Primary By Fiat Technical flow](https://3017072639-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7a6afyDwSEkvWtt1UhmH%2Fuploads%2F2AlC6TU2XS0ONRPj9GmI%2F2%20%E6%9C%80%E4%B8%8A%E9%9D%A2IMX%E6%94%B9XpansionChain.png?alt=media\&token=095270b7-2af4-4adc-bb7f-b97ea2335336)
