pay_service.dart 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // import 'package:fluwx/fluwx.dart' as fluwx;
  2. // import 'package:flutter_alipay/flutter_alipay.dart';
  3. // import 'package:stripe_payment/stripe_payment.dart';
  4. class PayService {
  5. PayService._();
  6. /// 发起微信支付
  7. Future<WechatPaymentCreatedResponse> createWechatPayment({
  8. required String productId,
  9. String? source,
  10. }) async {
  11. return sendPostRequest(
  12. '/v1/payment/wechatpay/',
  13. (resp) {
  14. return WechatPaymentCreatedResponse.fromJson(resp.data);
  15. },
  16. formData: {
  17. 'product_id': productId,
  18. 'source': source,
  19. },
  20. );
  21. }
  22. void wechatPay() async {
  23. bool isInstalled = await fluwx.isWeChatAppInstalled();
  24. if (isInstalled) {
  25. fluwx
  26. .pay(fluwx.PayInfo(
  27. appId: 'your_app_id',
  28. partnerId: 'your_partner_id',
  29. prepayId: 'your_prepay_id',
  30. packageValue: 'Sign=WXPay',
  31. nonceStr: 'your_nonce_str',
  32. timeStamp: 'your_timestamp',
  33. sign: 'your_sign',
  34. ))
  35. .then((response) {
  36. // 处理支付结果
  37. });
  38. } else {
  39. // alert('未安装微信');
  40. }
  41. }
  42. void alipay() async {
  43. String orderString = 'your_order_string'; // 从服务器获取
  44. var result = await FlutterAlipay.pay(orderString);
  45. }
  46. void stripe() async {
  47. var token = await StripePayment.paymentRequestWithCardForm(
  48. CardFormPaymentRequest());
  49. // 发送 token 到服务器进行支付处理
  50. }
  51. }