0 purchases
coinforbarter sdk
CoinForBarter SDK #
Getting Started #
This SDK allows you to recieve payments in cryptocurrency for your projects.
Follow these simple steps to start
Visit www.coinforbarter.com to get started by creating an account.
Go to the API section of the dashboard and get your public keys [test keys for testing]
Import the CoinForBarter SDK and follow the code example.
You can read more on how to integrate this SDK in your flutter app via this medium post
Install CoinForBarter
Add the following line to your pubspec.yaml file.
dependencies:
coinforbarter_sdk:
copied to clipboard
You are advised to use the latest version of the SDK for the best experience.
Import the SDK
import 'package:coinforbarter_sdk/coinforbarter.dart';
copied to clipboard
Initialize the NavigatorKey in your MaterialApp
Under the hood, coinForBarter SDK depends on a contextless Navigation, so you have to provide a coinForBarterNavigator() to your MaterialApp()
import 'package:flutter/material.dart';
import 'package:coinforbarter_sdk/coinforbarter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
//Include coinForBarterNavigator as the value of your navigatorKey likeso
navigatorKey: coinForBarterNavigator(),
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ButtonPage());
}
}
class ButtonPage extends StatelessWidget {
ButtonPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("Testing payments")),
);
}
}
}
copied to clipboard
Initalize your PaymentConfig
The PaymentConfig() object allows you provide a payload that contains most of your payment requests that the CoinForBarter API uses to process your payment transactions. The filed variables include
publicKey
txRef
amount
baseCurrency
customer
customerFullName
callback //required
The callback function
Your callback function should recieve 4 main arguments which are going to be passed through into your function when a payment has been processed. The arguments are in this order
statusCode
Returns the status code of the payment after it has ended
message
Returns a standard coinForBarter message
data
This provides more details about the transaction.
Status
An enum that returns either Status.success, Status.error, Status.cancelled
The code from above should look something like this when your paymentConfig() is set:
import 'package:flutter/material.dart';
import 'package:coinforbarter_sdk/coinforbarter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
//Include coinForBarterNavigator as the value of your navigatorKey likeso
navigatorKey: coinForBarterNavigator(),
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ButtonPage());
}
}
class ButtonPage extends StatelessWidget {
final PaymentConfig newPayment = PaymentConfig(
publicKey: 'XXXXXXXX-XXXXXXXX-XXXXXXX',
txRef: 'Flutter final Reference 1',
amount: 0.1,
baseCurrency: 'ETH',
customer: '[email protected]',
customerFullName: 'John Amala Doe',
callback: myCallBackFunction);
ButtonPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text("Testing payments")),
);
}
}
myCallBackFunction(int statusCode, String data, String message, Status status) {
debugPrint('At the end of the day, The call back function works');
}
copied to clipboard
Starting a Payment
Now that we have our payment config already setup, we are noe ready to connect to the coinForbarter API. We can initialize payment by two major ways:
CoinForBarterButton()
The provides you a button that allows you pass in a color, textColor and your PaymentConfig() object.
coinForBarterInit()
This is a function of type Future<void> that gives you more control to use the payment API however you want to call it.
Example below:
import 'package:flutter/material.dart';
import 'package:coinforbarter_sdk/coinforbarter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
//Include coinForBarterNavigator as the value of your navigatorKey likeso
navigatorKey: coinForBarterNavigator(),
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: ButtonPage());
}
}
class ButtonPage extends StatelessWidget {
final PaymentConfig newPayment = PaymentConfig(
publicKey: 'XXXXXXXX-XXXXXXXX-XXXXXXX',
txRef: 'Flutter final Reference 1',
amount: 0.1,
baseCurrency: 'ETH',
customer: '[email protected]',
customerFullName: 'John Amala Doe',
callback: myCallBackFunction);
ButtonPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: CoinForBarterButton(
color: Colors.red,
textColor: Colors.white,
paymentConfig: newPayment)),
);
}
}
myCallBackFunction(int statusCode, String data, String message, Status status) {
debugPrint('At the end of the day, The call back function works');
}
copied to clipboard
or call the init function in a button like so:
ElevatedButton(
child:Text(data),
onTap: () async {
await coinForBarterInit();
}
);
copied to clipboard
Once the function is called, or the button pressed, CoinForBarter handles everything there on.
Error Handling
Errors are logged to the console, and sometimes also logged on the app in form of drop downs.
Want to contribute #
You can read more about CoinForBarter or the official docs here
Join the CoinForBarter Dev Slack Community here
If you would like to contribute to the SDK (e.g. by improving the documentation, solving a bug or adding a cool new feature), please carefully review the codebase and send in your pull request.
Author #
This CoinForBarter SDK for Flutter is developed by Github : Fiizzy or IG : Fizzy.codes with ❤️
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.