Backend SDK (Payments)

This page compliments the Basic Payment Integration guide. Here you will find additional information regarding functions used in the Payments Integration Guide.


Note: We show here an example for NFT checkout, but its the same process for Token checkout as well, the only difference being the name of the function and the id parameter.

The `getNftPurchaseData` callback function

In this function you are expected to define the transaction parameters, and define your desired settlement type. (For more info about settlement types see: Flow of Funds)

For each settlement type you will have to adjust your getNftPurchaseData parameters accordingly:

// Common parameters for all settlement types
const nftCheckoutCommon = {
  title: 'Tweed Demo NFT',
  fiatCurrencyId: 'USD',
  contractAddress: DEMO_NFT_CONTRACT_ADDRESS,
  chain: 'polygonAmoy',
  description: "Non-fungible token for demonstration of Tweed's capabilities",
  tokenUri: 'https://paytweed-assets.s3.amazonaws.com/pinky.png' // A simple PNG for the NFT on Tweed's widget
}

const nftCheckoutVariants: Record<string, NftPurchaseBackendPayload> = {
  'demo-freemint': {
    ...nftCheckoutCommon,
    nftId: 'demo-freemint',
    priceInCrypto: '0', // For free mint
    tokenContractAddress: undefined, // For free mint
    abi: DEMO_NFT_CONTRACT_ABI_FREE,
  },
  'demo-paidmint-native': {
    ...nftCheckoutCommon,
    nftId: 'demo-paidmint-native',
    priceInCrypto: String(1e16), // For native settlement -- set price to 0.01 MATIC
    abi: DEMO_NFT_CONTRACT_ABI_PAID_NATIVE,
  },
  'demo-paidmint-erc20': {
    ...nftCheckoutCommon,
    nftId: 'demo-paidmint-erc20',
    priceInCrypto: String(100e18), // For ERC20 settlement -- 100 fake USDC token
    tokenContractAddress: FAKE_USDC_CONTRACT_ADDRESS, // For ERC20 settlement -- fake USDC token address
    abi: DEMO_NFT_CONTRACT_ABI_PAID_ERC20,
  },
}

Note how we provide different parameters based on the type of the settlement.

The nftId should correlate to the nftId passed from the frontend in the buyWithFiat function call.

Correctly specifiying your ABI:

The abi parameter should contain the name of the function and its arguments declerations, similar to the following example: safeMint(sendTo address, tokenId uint256, tokenUri string). The arguments needs to get populated into thecustomMintParams object like so:

customMintParams : {
    sendTo: <THE_WALLET_ADDRESS_VAR>,
    tokenId: <YOUR_TOKEN_ID_VAR>,
    tokenUri: <YOUR_TOKEN_URI_VAR>
}

Last updated