Before starting this guide, ensure WaaS is already implemented in your application. If not, use the following guide
1. Contact Tweed support for Payments API keys
You will receive two pairs of API keys. One pair is for the backend SDK, which authenticates your requests. The other pair is for facilitating your checkout implementation, such as adding contract addresses or creating whitelists.
2. List Your contract Address
introduce your contract address to tweed by our API, use the management API keys you got from us.
read more how to deploy contract address here.
3. Let's start with the backend
1. Add tweed to your Backend
npmi@paytweed/backend-sdk
2. Setup
Import TweedBackendSDK from the @paytweed/backend-sdk and implement the setup function. Pass your API keys and specify the default blockchains for your application.
Next, we will create an endpoint to be accessed by the frontend SDK for sending and receiving messages. Within this endpoint, we will use the handleMessageFromFrontend function. This function will handle messages arriving from the frontend SDK, along with the user ID and user email.
This implementation does not include WaaS. You can keep the user ID and email the same for each transaction, as demonstrated in our example.
Alternatively, integrate our wallet product alongside the checkout process.
tweed facilitate multiple settlement options: you can receive payments via credit card and choose to receive funds in either fiat currency or crypto, including native chain currencies or ERC20 tokens.
The next step involves handling this purchase on your backend. To accomplish this, you need to implement a callback function named getTokenPurchaseData. This function receives the tokenId parameter from the frontend as an input and expects to retrieve transaction details such as contract address, price, and other relevant information.
To call the token checkout widget, a wallet must be created for the user associated with this widget on the payments SDK. Even though we are going to obtain the wallet address from the WaaS SDK for each transaction to receive the token, you must still have an existing wallet on the payments SDK.
3. Make sure user has wallet before calling token checkout widget
use the getEthereumProvider function from useWeb3 to obtain the user's wallet address. we will pass this address to the token checkout widget to handle sending the token to the user's wallet