Tweed Docs
  • Welcome to Tweed
    • What Can Tweed Do?
  • Getting Started
    • Embedded Wallets | WaaS
    • Token Checkout | Payments
      • Flow of Funds: Purchase to Settlement
      • Token Checkout
      • Legacy Token Checkout
        • Basic Checkout Integration
        • Checkout + WaaS + Auth
        • Features
          • Payment links
          • Whitelist
          • Flow of Funds
          • Apple & Google Pay
          • AML & KYC Policy Overview
  • Developer Tools
    • Tweed SDKs
      • core-react
        • useAuth
        • useWallet
        • useTweed
        • usePayments
        • useWeb3
      • core-js
      • core-vue
      • Payments SDKs (v1)
        • Frontend SDKs (Payments)
        • Backend SDK (Payments)
        • How to set up your smart contract for Tweed
        • Tezos chain considerations
    • Management Dashboard
      • Create platform
      • Create application
        • UI Customization
    • Webhooks
      • Checkout Webhooks
    • API
      • API (V1)
      • API (V2)
        • Authorization
        • API reference
          • Contracts
            • Add
            • Add contract function
            • Contract
          • Payouts
            • Add
            • Payout
          • Items
            • Add
            • All
              • Contract
                • Count
              • Payout
                • Count
          • Assets
            • Blockchain
            • All
              • Blockchains
          • Blockchains
            • Multiple
            • Native asset
          • Audit event mappings
          • Platform webhooks
            • Set active
          • Tickets
        • Specification
    • External Integrations
      • Wagmi connector
      • Onramp to Crypto
    • Example Projects
    • Supported Blockchains
    • Pricing
  • Products
    • WaaS
    • Payments
Powered by GitBook
On this page
  1. Developer Tools
  2. Tweed SDKs
  3. Payments SDKs (v1)

Backend SDK (Payments)

PreviousFrontend SDKs (Payments)NextHow to set up your smart contract for Tweed

Last updated 8 months ago

This page compliments the 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>
}

See source repository for full example:

Basic Payment Integration
​
https://github.com/paytweed/demo-v2-next/blob/main/services/tweed.service.ts