我正在开发一个项目,我想使用 dart_frog 来实现条带订阅,dart_frog 是一个使用 dart 提供休息功能的库。
user_service.dart
Future<void> userSubscription(
UserSubscriptionModel userSubscriptionModel,
String? userId,
) async {
Logger().info(
'<---------------------------stripe-subscription----------------------->',
);
// initilize stripe
final stripe = Stripe(environment['STRIPE_PRIVATE_KEY']!);
final customerGetRes = await stripe.customer.get(
'$stripeBaseUrl/v1/customers/search',
queryParameters: {'query': "name: 'harsh jani'"},
);
Logger().info('customer res : $customerGetRes');
if (customerGetRes['id'] == null) {
final customerPostRes = await stripe.customer.post(
'$stripeBaseUrl/v1/customers',
data: {'name': 'harsh jani', 'email': '[email protected]'},
);
Logger().info('customer post res : $customerPostRes');
}
// await userCollection.update(
// where.eq('userId', userId),
// modify.set('brandSubscription', userSubscriptionModel.brandIds),
// upsert: true,
// );
final priceRes = await stripe.price.get('$stripeBaseUrl/v1/prices');
Logger().info('price res : $priceRes');
Logger().info(
'---------------------------stripe-subscription------------------------',
);
}
用户控制器.dart `
static Future<Response> userSubscription(RequestContext context) async {
try {
final request = context.request;
final authenticator = context.read<Authenticator>();
final userModuleServices = context.read<UserModuleService>();
// Retrieve userId from the Authenticator service
final userId = await authenticator.getUserId(context.request.headers);
final brandIds = UserSubscriptionModel.fromJson(
await request.json() as Map<String, dynamic>,
);
await userModuleServices.userSubscription(
brandIds,
userId.toString(),
);
return successResponse(
ResponseKey.subscribtionSuccessHintAppMsg,
);
} catch (e) {
Logger().info(e.toString());
if (e is ExceptionMsg) {
return Response.json(
statusCode: e.statusCode,
body: GeneralResponse(
status: e.status,
message: e.message,
),
);
} else {
return internalServerError();
}
}
}
我想实现条带订阅,也想在 dart 中实现订阅的 webhook。