petsHero-AI/lib/core/api/services/payment_api.dart
2026-03-15 11:25:09 +08:00

129 lines
3.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import '../api_client.dart';
import '../api_config.dart';
import '../proxy_client.dart';
/// 支付相关 API
abstract final class PaymentApi {
static final _client = ApiClient.instance.proxy;
/// 获取 Google 商品列表Android
static Future<ApiResponse> getGooglePayActivities({
String? sentinel,
String? shield,
String? vambrace,
String? portal,
}) async {
return _client.request(
path: '/v1/payment/getGooglePayActivities',
method: 'GET',
queryParams: {
'sentinel': sentinel ?? ApiConfig.appId,
'portal': portal ?? ApiConfig.packageName,
if (shield != null) 'shield': shield,
if (vambrace != null) 'vambrace': vambrace,
},
);
}
/// 获取 Apple 商品列表iOS
static Future<ApiResponse> getApplePayActivities({
String? sentinel,
String? shield,
String? vambrace,
String? portal,
}) async {
return _client.request(
path: '/v1/payment/getApplePayActivities',
method: 'GET',
queryParams: {
'sentinel': sentinel ?? 'HAndroid',
'portal': portal ?? ApiConfig.packageName,
if (shield != null) 'shield': shield,
if (vambrace != null) 'vambrace': vambrace,
},
);
}
/// 获取支付方式列表(传 activityId
static Future<ApiResponse> getPaymentMethods({
required String warrior,
String? vambrace,
}) async {
return _client.request(
path: '/v1/payment/get-payment-methods',
method: 'POST',
body: {
'warrior': warrior,
if (vambrace != null && vambrace.isNotEmpty) 'vambrace': vambrace,
},
);
}
/// 创建支付订单
static Future<ApiResponse> createPayment({
required String sentinel,
required String asset,
required String warrior,
required String resource,
String? ceremony,
String? lineage,
String? armor,
}) async {
return _client.request(
path: '/v1/payment/createPayment',
method: 'POST',
queryParams: {
'sentinel': sentinel,
'asset': asset,
},
body: {
'sentinel': sentinel,
'asset': asset,
'warrior': warrior,
'resource': resource,
if (ceremony != null && ceremony.isNotEmpty) 'ceremony': ceremony,
if (lineage != null) 'lineage': lineage,
if (armor != null) 'armor': armor,
},
);
}
/// 获取订单详情(用于三方支付 webview 关闭后轮询)
static Future<ApiResponse> getOrderDetail({
required String asset,
required String federation,
}) async {
return _client.request(
path: '/v1/payment/getOrderDetail',
method: 'GET',
queryParams: {
'asset': asset,
'federation': federation,
},
);
}
/// Google 支付结果回调。body 为 sample(signature)、merchant(purchaseData)、federation(id)、asset(userId),见 docs/googlepay.md。
static Future<ApiResponse> googlepay({
required String sample,
required String merchant,
required String federation,
required String asset,
}) async {
return _client.request(
path: '/v1/payment/googlepay',
method: 'POST',
queryParams: {
'sentinel': ApiConfig.appId,
'asset': asset,
},
body: {
'sample': sample,
'merchant': merchant,
'federation': federation,
'asset': asset,
},
);
}
}