payment.dart 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. class OtherPayCreatedReponse {
  2. String params;
  3. String paymentId;
  4. bool sandbox;
  5. OtherPayCreatedReponse(this.params, this.paymentId, {this.sandbox = false});
  6. toJson() => {
  7. 'params': params,
  8. 'payment_id': paymentId,
  9. 'sandbox': sandbox,
  10. };
  11. static OtherPayCreatedReponse fromJson(Map<String, dynamic> json) {
  12. return OtherPayCreatedReponse(
  13. json['params'],
  14. json['payment_id'],
  15. sandbox: json['sandbox'] ?? false,
  16. );
  17. }
  18. }
  19. class PaymentProduct {
  20. String id;
  21. String name;
  22. int quota;
  23. int retailPrice;
  24. int retailPriceUSD;
  25. String expirePolicy;
  26. String expirePolicyText;
  27. bool recommend;
  28. String? description;
  29. List<String> methods;
  30. PaymentProduct({
  31. required this.id,
  32. required this.name,
  33. required this.quota,
  34. required this.retailPrice,
  35. required this.expirePolicy,
  36. required this.expirePolicyText,
  37. this.recommend = false,
  38. this.description,
  39. this.retailPriceUSD = 0,
  40. this.methods = const [],
  41. });
  42. String get retailPriceText => '¥${(retailPrice / 100).toStringAsFixed(0)}';
  43. String get retailPriceUSDText =>
  44. '\$${(retailPriceUSD / 100).toStringAsFixed(2)}';
  45. /// 是否支持 Stripe 支付
  46. bool get supportStripe => methods.contains('stripe') || methods.isEmpty;
  47. toJson() => {
  48. 'id': id,
  49. 'name': name,
  50. 'quota': quota,
  51. 'retail_price': retailPrice,
  52. 'retail_price_usd': retailPriceUSD,
  53. 'expire_policy': expirePolicy,
  54. 'expire_policy_text': expirePolicyText,
  55. 'recommend': recommend,
  56. 'description': description,
  57. 'methods': methods,
  58. };
  59. static PaymentProduct fromJson(Map<String, dynamic> json) {
  60. return PaymentProduct(
  61. id: json['id'],
  62. name: json['name'],
  63. quota: json['quota'],
  64. retailPrice: json['retail_price'],
  65. retailPriceUSD: json['retail_price_usd'] ?? 0,
  66. expirePolicy: json['expire_policy'],
  67. expirePolicyText: json['expire_policy_text'],
  68. recommend: json['recommend'] ?? false,
  69. description: json['description'],
  70. methods: ((json['methods'] ?? []) as List<dynamic>)
  71. .map((e) => e.toString())
  72. .toList(),
  73. );
  74. }
  75. }
  76. class PaymentProducts {
  77. final List<PaymentProduct> consume;
  78. final String? note;
  79. final bool preferUSD;
  80. PaymentProducts(this.consume, {this.note, this.preferUSD = false});
  81. toJson() => {
  82. 'consume': consume,
  83. 'note': note,
  84. 'prefer_usd': preferUSD,
  85. };
  86. static PaymentProducts fromJson(Map<String, dynamic> json) {
  87. return PaymentProducts(
  88. (json['consume'] as List<dynamic>)
  89. .map((e) => PaymentProduct.fromJson(e))
  90. .toList(),
  91. note: json['note'],
  92. preferUSD: json['prefer_usd'] ?? false,
  93. );
  94. }
  95. }
  96. class PaymentStatus {
  97. final bool success;
  98. final String? note;
  99. PaymentStatus(this.success, {this.note});
  100. toJson() => {
  101. 'success': success,
  102. 'note': note,
  103. };
  104. static PaymentStatus fromJson(Map<String, dynamic> json) {
  105. return PaymentStatus(
  106. json['success'],
  107. note: json['note'],
  108. );
  109. }
  110. }
  111. class WechatPaymentCreatedResponse {
  112. final String paymentId;
  113. final bool sandbox;
  114. final String? codeUrl;
  115. final String? prepayId;
  116. final String? package;
  117. final String? partnerId;
  118. final String? appId;
  119. final String? noncestr;
  120. final String? timestamp;
  121. final String? sign;
  122. WechatPaymentCreatedResponse(
  123. this.paymentId,
  124. this.sandbox, {
  125. this.codeUrl,
  126. this.prepayId,
  127. this.package,
  128. this.partnerId,
  129. this.appId,
  130. this.noncestr,
  131. this.timestamp,
  132. this.sign,
  133. });
  134. toJson() => {
  135. 'payment_id': paymentId,
  136. 'sandbox': sandbox,
  137. 'code_url': codeUrl,
  138. 'prepay_id': prepayId,
  139. 'package': package,
  140. 'partner_id': partnerId,
  141. 'app_id': appId,
  142. 'noncestr': noncestr,
  143. 'timestamp': timestamp,
  144. 'sign': sign,
  145. };
  146. static WechatPaymentCreatedResponse fromJson(Map<String, dynamic> json) {
  147. return WechatPaymentCreatedResponse(
  148. json['payment_id'],
  149. json['sandbox'] ?? false,
  150. codeUrl: json['code_url'],
  151. prepayId: json['prepay_id'],
  152. package: json['package'],
  153. partnerId: json['partner_id'],
  154. appId: json['app_id'],
  155. noncestr: json['noncestr'],
  156. timestamp: json['timestamp'],
  157. sign: json['sign'],
  158. );
  159. }
  160. }
  161. class StripePaymentCreatedResponse {
  162. final String paymentId;
  163. final String customer;
  164. final String paymentIntent;
  165. final String ephemeralKey;
  166. final String publishableKey;
  167. final String proxyUrl;
  168. StripePaymentCreatedResponse(
  169. this.paymentId,
  170. this.customer,
  171. this.paymentIntent,
  172. this.ephemeralKey,
  173. this.publishableKey,
  174. this.proxyUrl,
  175. );
  176. toJson() => {
  177. 'payment_id': paymentId,
  178. 'customer': customer,
  179. 'payment_intent': paymentIntent,
  180. 'ephemeral_key': ephemeralKey,
  181. 'publishable_key': publishableKey,
  182. 'proxy_url': proxyUrl,
  183. };
  184. static StripePaymentCreatedResponse fromJson(Map<String, dynamic> json) {
  185. return StripePaymentCreatedResponse(
  186. json['payment_id'],
  187. json['customer'],
  188. json['payment_intent'],
  189. json['ephemeral_key'],
  190. json['publishable_key'],
  191. json['proxy_url'] ?? '',
  192. );
  193. }
  194. }