payment.dart 6.0 KB

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