Flutter电商存款管理插件deposits_ecommerce的使用
Flutter电商存款管理插件deposits_ecommerce的使用

Deposits Commerce SDK
Deposits Commerce SDK 是一个易于嵌入的电子商务系统,允许创作者设置和运营在线商店而无需拥有自己的电子商务网站。它赋能商家在不需要投入大量工程时间的情况下推出商业功能,并且成本低于内部构建电子商务能力。购物者可以在不离开应用程序的情况下查看商品并从每个商家的商店中逐个结账。

安装
pubspec.yaml :
dependencies:
flutter:
sdk: flutter
deposits_ecommerce: <Latest version>
终端 :
flutter pub add deposits_ecommerce
特性
- 创建商店。
- 客户管理。
- 购物车管理。
- 订单管理。
- 产品管理。
- 分类。
- 配送地址管理。
- 商家管理。
- 等等更多。
要求
Android
此插件需要对Android设备进行一些更改才能正常工作。请确保遵循以下步骤:
- 使用Android 5.0(API级别21)及更高版本。
- 重新构建应用,因为上述更改不会通过热重载更新。
iOS
与目标iOS 10或更高版本的应用程序兼容。
Web
目前,此插件不支持Web。
使用
库提供了一个UI组件,用于创建和管理商店以及管理客户。
客户管理/流程示例
depositsCustomerWidget(
context,
merchantId: '1',
customerID: '1',
envMode: envMode,
apiKey: apiKey,
)
商家管理/流程示例
depositsMerchantWidget(
context,
ButtonConfig(buttonText: 'buttonText'),
merchantID: '',
apiKey: apiKey,
envMode: envMode,
)
参数 [buttonText]
是你希望按钮上显示的文字。
参数 [merchantID]
是由Deposits API提供的商家ID(你想展示其产品的商家),例如 43cba34n65l
。
参数 [customerID]
是由Deposits API提供的客户ID(即将购买的用户),例如 98iei74uij
。
参数 [apiKey]
是由Deposits API提供的商家密钥,例如 deposits-ecommerce-test
。
参数 [envMode]
告诉库是否应该使用测试环境还是生产环境。
/// 在调试或开发时非常有用。
Deposits Commerce SDK 的目标是使使用Flutter和Deposits构建出色的电子商务应用变得尽可能简单,并帮助提高你的工作效率。
初始化Deposit Commerce SDK
要在Flutter应用中初始化Deposit Ecommerce Customer Management/Flow,请使用 depositsCustomerWidget
和 depositsMerchantWidget
来初始化Deposit Ecommerce Merchant Management/Flow。
depositsCustomerWidget
和 depositsMerchantWidget
提供了 context
,buttonConfig
,initialScreen
,envMode
,merchantID
和 customerID
,apiKey
。只有 apiKey
,envMode
和 buttonConfig
是必需的。envMode
是一个布尔值,可以为真或假。
Dart API
Deposits
库提供了多个方法来处理客户和商家相关的操作:
import 'package:deposits_ecommerce/deposits_ecommerce.dart';
DepositsApi depositsApi = DepositsApi(
apiKey: 'deposits-ecommerce-test',
isProduction: false,
isDebug: true
);
===================商家外部API's===================
print("======>>>>>>");
var categoryApiResponse = await depositsApi.getCategories();
print("categoryApiResponse $categoryApiResponse");
print("======>>>>>>");
var setUpShopApiResponse = await depositsApi.setupMerchant('233', 'demo shop', 'my demo shop', 'support@example.com', 'Electronics', '500443', 'Mina avenue', 'Dallas', 'Texas', 'USA');
print("setUpShopApiResponse $setUpShopApiResponse");
print("======>>>>>>");
var getMerchantApiResponse = await depositsApi.getMerchant('22');
print("getMerchantApiResponse $getMerchantApiResponse");
print("======>>>>>>");
var getMerchantInfoApiResponse = await depositsApi.getMerchantInfo('22');
print("getMerchantInfoApiResponse $getMerchantInfoApiResponse");
print("======>>>>>>");
var getSelectedMerchantsApiResponse = await depositsApi.getSelectedMerchants(['22']);
print("getSelectedMerchantsApiResponse $getSelectedMerchantsApiResponse");
print("======>>>>>>");
var updateMerchantApiResponse = await depositsApi.updateMerchant('22', 'demo shop', 'my demo shop', 'support@example.com', 'Electronics', '500443', 'Mina avenue', 'Dallas', 'Texas', 'USA');
print("updateMerchantApiResponse $updateMerchantApiResponse");
print("======>>>>>>");
var updateMerchantContactInfoApiResponse = await depositsApi.updateMerchantContactInfo('22', 'mysupport@example.com', '74 clinoda avenue, dave town');
print("updateMerchantContactInfoApiResponse $updateMerchantContactInfoApiResponse");
print("======>>>>>>");
var updateMerchantPolicyApiResponse = await depositsApi.updateMerchantPolicy('22', 'we allow return but only if item is not defected', 'when we ship an order can not be cancelled and we deliver straight to your door step');
print("updateMerchantPolicyApiResponse $updateMerchantPolicyApiResponse");
print("======>>>>>>");
var updateMerchantShippingAndTaxInfoApiResponse = await depositsApi.updateMerchantShippingAndTaxInfo('22', '893883HHHJH', '20%', '30');
print("updateMerchantShippingAndTaxInfoApiResponse $updateMerchantShippingAndTaxInfoApiResponse");
print("======>>>>>>");
var createAssetApiResponse = await depositsApi.createAsset('22', 'file/csdvhrufre.png', 'my product', 'front image for my product');
print("createAssetApiResponse $createAssetApiResponse");
print("======>>>>>>");
var createProductApiResponse = await depositsApi.createProduct('22', 'HGDYU7374743', 'my product', '34', 'my book to help you sell', '3', 'true', '', '3', '10', {}, {});
print("createProductApiResponse $createProductApiResponse");
===================客户外部API's===================
print("======>>>>>>");
var createCustomerApiResponse = await depositsApi.createCustomer('22','calmpress@gmail.com','james','Bova','null','null',{'address':'null'});
print("createCustomerApiResponse $createCustomerApiResponse");
print("======>>>>>>");
var findCustomerApiResponse = await depositsApi.findCustomer('22','calmpress@gmail.com');
print("findCustomerApiResponse $findCustomerApiResponse");
print("======>>>>>>");
var getProductsApiResponse = await depositsApi.getProducts('22');
print("getProductsApiResponse $getProductsApiResponse");
print("======>>>>>>");
var getProductApiResponse = await depositsApi.getProduct('22', '2');
print("getProductApiResponse $getProductApiResponse");
print("======>>>>>>");
var getFeaturedProductsApiResponse = await depositsApi.getFeaturedProducts('22');
print("getFeaturedProductsApiResponse $getFeaturedProductsApiResponse");
更多关于Flutter电商存款管理插件deposits_ecommerce的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter电商存款管理插件deposits_ecommerce的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
deposits_ecommerce
是一个用于电商应用中管理存款的 Flutter 插件。它可以帮助开发者轻松地处理用户的存款、提款、余额查询等操作。以下是如何在 Flutter 项目中使用 deposits_ecommerce
插件的基本步骤。
1. 添加依赖
首先,你需要在 pubspec.yaml
文件中添加 deposits_ecommerce
插件的依赖。
dependencies:
flutter:
sdk: flutter
deposits_ecommerce: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来获取依赖。
2. 初始化插件
在你的 Flutter 应用中,首先需要初始化 deposits_ecommerce
插件。通常,你可以在 main.dart
文件中的 main
函数中进行初始化。
import 'package:deposits_ecommerce/deposits_ecommerce.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// 初始化插件
await DepositsEcommerce.initialize(
apiKey: 'YOUR_API_KEY', // 替换为你的API密钥
environment: Environment.sandbox, // 或者 Environment.production
);
runApp(MyApp());
}
3. 存款操作
你可以使用 DepositsEcommerce
类中的方法来处理存款操作。例如,用户存款到他们的账户:
void depositFunds() async {
try {
DepositResponse response = await DepositsEcommerce.deposit(
userId: 'USER_ID', // 用户ID
amount: 100.0, // 存款金额
currency: 'USD', // 货币类型
);
if (response.success) {
print('Deposit successful: ${response.transactionId}');
} else {
print('Deposit failed: ${response.errorMessage}');
}
} catch (e) {
print('Error depositing funds: $e');
}
}
4. 提款操作
类似地,你可以处理用户的提款请求:
void withdrawFunds() async {
try {
WithdrawalResponse response = await DepositsEcommerce.withdraw(
userId: 'USER_ID', // 用户ID
amount: 50.0, // 提款金额
currency: 'USD', // 货币类型
);
if (response.success) {
print('Withdrawal successful: ${response.transactionId}');
} else {
print('Withdrawal failed: ${response.errorMessage}');
}
} catch (e) {
print('Error withdrawing funds: $e');
}
}
5. 查询余额
你可以查询用户的当前余额:
void checkBalance() async {
try {
BalanceResponse response = await DepositsEcommerce.getBalance(
userId: 'USER_ID', // 用户ID
);
if (response.success) {
print('Current balance: ${response.balance}');
} else {
print('Failed to fetch balance: ${response.errorMessage}');
}
} catch (e) {
print('Error fetching balance: $e');
}
}
6. 处理回调
你还可以设置回调来处理交易完成后的操作:
void setupCallbacks() {
DepositsEcommerce.onDepositSuccess((transactionId) {
print('Deposit successful: $transactionId');
});
DepositsEcommerce.onWithdrawalSuccess((transactionId) {
print('Withdrawal successful: $transactionId');
});
DepositsEcommerce.onError((errorMessage) {
print('Error: $errorMessage');
});
}
7. UI 集成
最后,你可以将这些操作集成到你的 UI 中,例如在按钮点击时调用这些方法:
ElevatedButton(
onPressed: depositFunds,
child: Text('Deposit Funds'),
),
ElevatedButton(
onPressed: withdrawFunds,
child: Text('Withdraw Funds'),
),
ElevatedButton(
onPressed: checkBalance,
child: Text('Check Balance'),
),