Webhooks

The print button can be configured to send Webhooks

Webhook Payload


interface PrintButtonCallbackPayload {
  /**
   * The partner ID Associated with this sale
   */
  partnerId: string

  /**
   * The Event that triggered this callback
   */
  event: 'ORDER_PLACED' | 'ORDER_CANCELED' | 'ORDER_FULLFILLED'

  /**
   * The Shopify order number
   */
  orderNumber: number

  /**
   * The Blockchain where the token lives
   */
  blockchain: 'eth'| 'flow'| 'matic'| 'xtz'| 'sol'| 'avax'| 'bsc'| 'palm'

  /**
   * The Contract Address
   */
  contractAddress: string

  /**
   * The Token ID
   */
  tokenId: string

  /**
   * The wallet of the owner of the token
   */
  ownerAddress: string

  /**
   * The video print ID associated with this sale
   */
  printId: string

  /**
   * Timestamp of the event
   */
  timestamp: Date
}

Webhook Verification

To verify the hooks come from Infinite Objects, you can use something like the following example on express

/**
 * The header we use for sending the signature
 */
 const PRINT_BUTTON_CALLBACK_SIGN_HEADER = 'X-InfiniteObjects-Hmac-SHA256'

 /**
  * The header we use for the topic
  */
 const PRINT_BUTTON_CALLBACK_TOPIC_HEADER = 'X-InfiniteObjects-Topic'

 /**
  * The header we use for Ids
  */

 const PRINT_BUTTON_CALLBACK_ID_HEADER = 'X-InfiniteObjects-Event-Id'

 /**
  * The shared secret used to sign the payload. You'll receive one during onboarding
  */
 const SHARED_SECRET = 'discover.ill.lemon.sun.cost.amused.castle.bike.sketch.prosper'

 server.post('/', (req, res, next) => {
  const body: Record<string, any> = req.body
  const rawBody: Buffer = req.rawBody // You need the body as a buffer
  const topic = req.get(PRINT_BUTTON_CALLBACK_TOPIC_HEADER)
  const signature = req.get(PRINT_BUTTON_CALLBACK_SIGN_HEADER)
  const hookId = req.get(PRINT_BUTTON_CALLBACK_ID_HEADER)

  // calculate the hash
  const hash = crypto.createHmac('sha256', SHARED_SECRET).update(rawBody).digest('base64')

  // compare the hashes
  if (signature !== hash) {
    return next(new Error('Signature mismatch'))
  }
  
  // You can use the `hookId` to avoid ingesting the same event twice

  // The hook is verified, do anything with the body object
  // ...
  //
  res.sendStatus(200)
})

Last updated