Libs.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Text.Json.Serialization;
  5. namespace Gateway.Payment.Shared
  6. {
  7. public enum TradeStatusEnum
  8. {
  9. PAYERROR,
  10. SUCCESS,
  11. CANCELLING,
  12. CLOSED,
  13. }
  14. public class PaymentOrderDto
  15. {
  16. public string PaymentMethod { get; set; }
  17. public bool IsForRefund { get; set; }
  18. public decimal TotalAmount { get; set; }
  19. /// <summary>
  20. /// the final charge will based on this value.
  21. /// </summary>
  22. public decimal NetAmount { get; set; }
  23. /// <summary>
  24. /// Gets or sets 用户授权码, 当商户用扫码枪扫用户的条形码时得到的字符串
  25. /// </summary>
  26. public string AuthCode { get; set; }
  27. /// <summary>
  28. /// Gets or sets the 商户订单号, used for refund.
  29. /// </summary>
  30. public string BillNumber { get; set; }
  31. public string ExtraCommand { get; set; }
  32. /// <summary>
  33. /// Gets or sets the 订单标题 UTF8编码格式,32个字节内,最长支持16个汉字
  34. /// </summary>
  35. public string Title { get; set; }
  36. public string OperatorId { get; set; }
  37. public string SiteId { get; set; }
  38. /// <summary>
  39. /// Gets or sets the terminal id for submit this order
  40. /// </summary>
  41. public string TerminalId { get; set; }
  42. }
  43. public class PaymentOrderPayResult
  44. {
  45. [Required]
  46. public int Id { get; set; }
  47. public string BillNumber { get; set; }
  48. [System.ComponentModel.DataAnnotations.Schema.ForeignKey("PaymentOrder")]
  49. public int PaymentOrderId { get; set; }
  50. public PaymentOrder PaymentOrder { get; set; }
  51. public string Stage { get; set; }
  52. [Required]
  53. public string PaymentResultCode { get; set; }
  54. public string PaymentResultMessage { get; set; }
  55. public string PaymentResultErrorDetail { get; set; }
  56. /// <summary>
  57. /// Gets or sets the raw result (a string) from 3rd party payment server.
  58. /// </summary>
  59. public string PaymentResultRawResult { get; set; }
  60. }
  61. /// <summary>
  62. /// Host the phase 1 supported transaction info.
  63. /// </summary>
  64. public class PaymentOrder
  65. {
  66. public string SiteId { get; set; }
  67. /// <summary>
  68. /// 根据不同场景选择不同的支付方式, accepted values: WX_SCAN、ALI_SCAN、ALL_IN_SCAN
  69. /// </summary>
  70. public string PaymentMethod { get; set; }
  71. public bool IsForRefund { get; set; }
  72. /// <summary>
  73. /// trade status, expected values: USERPAYING, SUCCESS, SUCCESS_CANCELLING, PAYERROR, PAYERROR_CANCELLING, CLOSED
  74. /// </summary>
  75. public TradeStatusEnum TradeStatus { get; set; }
  76. public decimal TotalAmount { get; set; }
  77. /// <summary>
  78. /// Gets or sets the netamount for this transaction, this amount deducted all the discount, and should be the final amount would be charged from
  79. /// customer account.
  80. /// </summary>
  81. public decimal NetAmount { get; set; }
  82. /// <summary>
  83. /// Gets or sets the 商户订单号, 确保唯一, key field used for refund
  84. /// </summary>
  85. public string BillNumber { get; set; }
  86. public string ExtraCommand { get; set; }
  87. [System.ComponentModel.DataAnnotations.Schema.NotMapped]
  88. public object Config { get; set; }
  89. [System.ComponentModel.DataAnnotations.Schema.NotMapped]
  90. public object Certification { get; set; }
  91. [System.ComponentModel.DataAnnotations.Schema.NotMapped]
  92. public Dictionary<string, string> Optional { get; set; }
  93. /// <summary>
  94. /// Gets or sets the 订单标题 UTF8编码格式,32个字节内,最长支持16个汉字
  95. /// </summary>
  96. public string Title { get; set; }
  97. /// <summary>
  98. /// Gets or sets 用户授权码, 当商户用扫码枪扫用户的条形码时得到的字符串
  99. /// </summary>
  100. public string AuthCode { get; set; }
  101. /// <summary>
  102. /// Gets or sets the operator id for who submit this order from site.
  103. /// </summary>
  104. public string OperatorId { get; set; }
  105. /// <summary>
  106. /// Gets or sets the terminal id for submit this order
  107. /// </summary>
  108. public string TerminalId { get; set; }
  109. /// <summary>
  110. /// Gets or sets the time that server received this order for processing.
  111. /// </summary>
  112. public DateTime ServerSideTimestamp { get; set; }
  113. public List<PaymentOrderPayResult> PayResults { get; set; }
  114. public string ToFullJsonLogString()
  115. {
  116. try
  117. {
  118. return System.Text.Json.JsonSerializer.Serialize(this,
  119. new System.Text.Json.JsonSerializerOptions()
  120. {
  121. MaxDepth = 5,
  122. WriteIndented = true,
  123. Converters = { new JsonStringEnumConverter() }
  124. });
  125. }
  126. catch
  127. {
  128. return this.ToSimpleLogString();
  129. }
  130. }
  131. public string ToSimpleLogString()
  132. {
  133. return $"Mop: {this.PaymentMethod}, IsForRefund: {this.IsForRefund.ToString()}, TradeStatus: {this.TradeStatus}, " +
  134. $"NetAmount: {this.NetAmount}, BillNumber: {this.BillNumber ?? ""}, ServerSideTimestamp: {this.ServerSideTimestamp.ToLongTimeString()}";
  135. }
  136. }
  137. public class ALiPayCertification
  138. {
  139. public string Merchant_Private_Key { get; set; }
  140. public string Merchant_Public_Key { get; set; }
  141. public string Alipay_Public_key { get; set; }
  142. }
  143. public class PostPayQRCodeFuelOrderOptionalFieldModel
  144. {
  145. public int Id { get; set; }
  146. public string key1 { get; set; }
  147. public string value1 { get; set; }
  148. public string key2 { get; set; }
  149. public string value2 { get; set; }
  150. public string key3 { get; set; }
  151. public string value3 { get; set; }
  152. public string key4 { get; set; }
  153. public string value4 { get; set; }
  154. public string key5 { get; set; }
  155. public string value5 { get; set; }
  156. public string key6 { get; set; }
  157. public string value6 { get; set; }
  158. public string key7 { get; set; }
  159. public string value7 { get; set; }
  160. public string key8 { get; set; }
  161. public string value8 { get; set; }
  162. public string key9 { get; set; }
  163. public string value9 { get; set; }
  164. public string key10 { get; set; }
  165. public string value10 { get; set; }
  166. public string key11 { get; set; }
  167. public string value11 { get; set; }
  168. public string key12 { get; set; }
  169. public string value12 { get; set; }
  170. public string key13 { get; set; }
  171. public string value13 { get; set; }
  172. public string key14 { get; set; }
  173. public string value14 { get; set; }
  174. public string key15 { get; set; }
  175. public string value15 { get; set; }
  176. }
  177. public class SequenceNumber
  178. {
  179. private const int INIT_VALUE = 1;
  180. private static readonly object obj = new object();
  181. private static int counter = INIT_VALUE;
  182. public static string Next()
  183. {
  184. lock (obj)
  185. {
  186. var now = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  187. var cnt = counter.ToString().PadLeft(11, '0');
  188. if (counter >= int.MaxValue)
  189. counter = INIT_VALUE;
  190. else
  191. counter++;
  192. return now + cnt; // length of 28
  193. }
  194. }
  195. }
  196. public class SequenceNumber20
  197. {
  198. private const int INIT_VALUE = 1;
  199. private const int MAX_VALUE = 999;
  200. private static readonly object obj = new object();
  201. private static int counter = INIT_VALUE;
  202. public static string Next()
  203. {
  204. lock (obj)
  205. {
  206. var now = DateTime.Now.ToString("yyyyMMddHHmmssfff"); // length of 17
  207. var cnt = counter.ToString().PadLeft(3, '0');
  208. if (counter > MAX_VALUE)
  209. counter = INIT_VALUE;
  210. else
  211. counter++;
  212. return now + cnt; // length of 20
  213. }
  214. }
  215. }
  216. }