1. Introducing T-Chain Payment
Although cryptocurrency has been in the bear market for quite some time, the potential of blockchain is undisputed. Cryptocurrency is more and more accepted by organizations and regions ( reference ). Regarding electronic payments, many parties have used stable coins for payment. In this article, I guide the integration of T-Chain Payment SDK , a package of Tokoin, to help integrate payments with cryptocurrency quickly.
2. Goals
Currently, there are many projects that integrate E-Wallet payments, and may also want to integrate crypto payments. So, I created a shopping app in advance with basic features: view, select products, add products to cart and pay with momo. Because it’s a demo app, I don’t register app information with the payment method provider, but also use the information in the example of that package. The T-Chain Payment SDK will then be integrated, to see if the integration is quick and easy.
Collection | Details | Cart |
---|---|---|
To test on the testnet, you must download the My T-Wallet app. You can go to Tokoin homepage to get download link, or here ios , android .
After you have installed the app, you need to transfer the app to the sandbox environment so that it can be tested on the testnet. To change the environment, you click repeatedly on the Tokoin logo until a message appears, then restart the application, you will see as shown below.
3. Steps to integrate T-Chain Payment
To get started, I need to register information on the dev page . Fill out the form and wait for them to send relevant information. And if you just want to try like me, get the apiKey
information in the package’s example for quick
1 2 | final apiKey = '3e093592-3e0e-4a52-9601-ead49f794586' |
Configure the scheme according to the instructions so that My T-Wallet can callback separately for each platform
Android: Need to edit AndroidManifest.xml
file as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 | <activity ... android:launchMode="singleTask" ...> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="merchant.${applicationId}" android:host="app" /> </intent-filter> </activity> |
iOS: Need to edit Info.plist file as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLName</key> <string>Payment Scheme Callback</string> <key>CFBundleURLSchemes</key> <array> <string>merchant.$(PRODUCT_BUNDLE_IDENTIFIER)</string> </array> </dict> </array> <key>LSApplicationQueriesSchemes</key> <array> <string>mtwallet</string> <string>mtwallet.dev</string> </array> |
That’s it, the configuration for iOS and Android is complete. To integrate the SDK you need to pay attention to the env environment variable, chain. To pre-test on app published on store, you must use env as prod
, and isTestnet
as false
to test on testnet.
1 2 3 4 5 6 7 8 | TChainPaymentSDK.instance.init( apiKey: '3e093592-3e0e-4a52-9601-ead49f794586', bundleID: 'com.tokoin.tchainpayment.example', env: TChainPaymentEnv.prod, isTestnet: true, delegate: _handleResult, ); |
After selecting the product, go to the payment step, use the deposit(…) function to make the payment. Just like other payment methods, I need to call the API to create an order on the merchant server to be able to manage and control it later. In the example, I only use the id generated from Datetime.
1 2 3 4 5 6 | final TChainPaymentResult result = await TChainPaymentSDK.instance.deposit( orderID: orderID, amount: amount.toDouble(), currency: TChainPaymentCurrency.idr, ); |
After calling the deposit, and making the payment on the app wallet, and the merchant app will receive a callback with the payment result, and then the result is also sent to the webhook that we registered at first. The result received from the callback, is only the result on the testnet / mainnet network. To make sure the payment is recorded on the merchant’s server side, we should wait for the signal from the merchant’s server.
If you need to refer to the project’s code, I will put it in this repository .
4. Conclusion
I find the integration does not take too long. You can try and give Tokoin team feedback to improve the product. This T-Chain Payment SDK package has also just been posted, so there will definitely be more updates coming soon.
Hope you find the package useful, as well as being able to integrate cryptocurrency payments into your existing project.