123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Text.Json.Serialization;
- namespace Gateway.Payment.Shared
- {
- public enum TradeStatusEnum
- {
- PAYERROR,
- SUCCESS,
- CANCELLING,
- CLOSED,
- }
- public class PaymentOrderDto
- {
- public string PaymentMethod { get; set; }
- public bool IsForRefund { get; set; }
- public decimal TotalAmount { get; set; }
- /// <summary>
- /// the final charge will based on this value.
- /// </summary>
- public decimal NetAmount { get; set; }
- /// <summary>
- /// Gets or sets 用户授权码, 当商户用扫码枪扫用户的条形码时得到的字符串
- /// </summary>
- public string AuthCode { get; set; }
- /// <summary>
- /// Gets or sets the 商户订单号, used for refund.
- /// </summary>
- public string BillNumber { get; set; }
- public string ExtraCommand { get; set; }
- /// <summary>
- /// Gets or sets the 订单标题 UTF8编码格式,32个字节内,最长支持16个汉字
- /// </summary>
- public string Title { get; set; }
- public string OperatorId { get; set; }
- public string SiteId { get; set; }
- /// <summary>
- /// Gets or sets the terminal id for submit this order
- /// </summary>
- public string TerminalId { get; set; }
- }
- public class PaymentOrderPayResult
- {
- [Required]
- public int Id { get; set; }
- public string BillNumber { get; set; }
- [System.ComponentModel.DataAnnotations.Schema.ForeignKey("PaymentOrder")]
- public int PaymentOrderId { get; set; }
- public PaymentOrder PaymentOrder { get; set; }
- public string Stage { get; set; }
- [Required]
- public string PaymentResultCode { get; set; }
- public string PaymentResultMessage { get; set; }
- public string PaymentResultErrorDetail { get; set; }
- /// <summary>
- /// Gets or sets the raw result (a string) from 3rd party payment server.
- /// </summary>
- public string PaymentResultRawResult { get; set; }
- }
- /// <summary>
- /// Host the phase 1 supported transaction info.
- /// </summary>
- public class PaymentOrder
- {
- public string SiteId { get; set; }
- /// <summary>
- /// 根据不同场景选择不同的支付方式, accepted values: WX_SCAN、ALI_SCAN、ALL_IN_SCAN
- /// </summary>
- public string PaymentMethod { get; set; }
- public bool IsForRefund { get; set; }
- /// <summary>
- /// trade status, expected values: USERPAYING, SUCCESS, SUCCESS_CANCELLING, PAYERROR, PAYERROR_CANCELLING, CLOSED
- /// </summary>
- public TradeStatusEnum TradeStatus { get; set; }
- public decimal TotalAmount { get; set; }
- /// <summary>
- /// Gets or sets the netamount for this transaction, this amount deducted all the discount, and should be the final amount would be charged from
- /// customer account.
- /// </summary>
- public decimal NetAmount { get; set; }
- /// <summary>
- /// Gets or sets the 商户订单号, 确保唯一, key field used for refund
- /// </summary>
- public string BillNumber { get; set; }
- public string ExtraCommand { get; set; }
- [System.ComponentModel.DataAnnotations.Schema.NotMapped]
- public object Config { get; set; }
- [System.ComponentModel.DataAnnotations.Schema.NotMapped]
- public object Certification { get; set; }
- [System.ComponentModel.DataAnnotations.Schema.NotMapped]
- public Dictionary<string, string> Optional { get; set; }
- /// <summary>
- /// Gets or sets the 订单标题 UTF8编码格式,32个字节内,最长支持16个汉字
- /// </summary>
- public string Title { get; set; }
- /// <summary>
- /// Gets or sets 用户授权码, 当商户用扫码枪扫用户的条形码时得到的字符串
- /// </summary>
- public string AuthCode { get; set; }
- /// <summary>
- /// Gets or sets the operator id for who submit this order from site.
- /// </summary>
- public string OperatorId { get; set; }
- /// <summary>
- /// Gets or sets the terminal id for submit this order
- /// </summary>
- public string TerminalId { get; set; }
- /// <summary>
- /// Gets or sets the time that server received this order for processing.
- /// </summary>
- public DateTime ServerSideTimestamp { get; set; }
- public List<PaymentOrderPayResult> PayResults { get; set; }
- public string ToFullJsonLogString()
- {
- try
- {
- return System.Text.Json.JsonSerializer.Serialize(this,
- new System.Text.Json.JsonSerializerOptions()
- {
- MaxDepth = 5,
- WriteIndented = true,
- Converters = { new JsonStringEnumConverter() }
- });
- }
- catch
- {
- return this.ToSimpleLogString();
- }
- }
- public string ToSimpleLogString()
- {
- return $"Mop: {this.PaymentMethod}, IsForRefund: {this.IsForRefund.ToString()}, TradeStatus: {this.TradeStatus}, " +
- $"NetAmount: {this.NetAmount}, BillNumber: {this.BillNumber ?? ""}, ServerSideTimestamp: {this.ServerSideTimestamp.ToLongTimeString()}";
- }
- }
- public class ALiPayCertification
- {
- public string Merchant_Private_Key { get; set; }
- public string Merchant_Public_Key { get; set; }
- public string Alipay_Public_key { get; set; }
- }
- public class PostPayQRCodeFuelOrderOptionalFieldModel
- {
- public int Id { get; set; }
- public string key1 { get; set; }
- public string value1 { get; set; }
- public string key2 { get; set; }
- public string value2 { get; set; }
- public string key3 { get; set; }
- public string value3 { get; set; }
- public string key4 { get; set; }
- public string value4 { get; set; }
- public string key5 { get; set; }
- public string value5 { get; set; }
- public string key6 { get; set; }
- public string value6 { get; set; }
- public string key7 { get; set; }
- public string value7 { get; set; }
- public string key8 { get; set; }
- public string value8 { get; set; }
- public string key9 { get; set; }
- public string value9 { get; set; }
- public string key10 { get; set; }
- public string value10 { get; set; }
- public string key11 { get; set; }
- public string value11 { get; set; }
- public string key12 { get; set; }
- public string value12 { get; set; }
- public string key13 { get; set; }
- public string value13 { get; set; }
- public string key14 { get; set; }
- public string value14 { get; set; }
- public string key15 { get; set; }
- public string value15 { get; set; }
- }
- public class SequenceNumber
- {
- private const int INIT_VALUE = 1;
- private static readonly object obj = new object();
- private static int counter = INIT_VALUE;
- public static string Next()
- {
- lock (obj)
- {
- var now = DateTime.Now.ToString("yyyyMMddHHmmssfff");
- var cnt = counter.ToString().PadLeft(11, '0');
- if (counter >= int.MaxValue)
- counter = INIT_VALUE;
- else
- counter++;
- return now + cnt; // length of 28
- }
- }
- }
- public class SequenceNumber20
- {
- private const int INIT_VALUE = 1;
- private const int MAX_VALUE = 999;
- private static readonly object obj = new object();
- private static int counter = INIT_VALUE;
- public static string Next()
- {
- lock (obj)
- {
- var now = DateTime.Now.ToString("yyyyMMddHHmmssfff"); // length of 17
- var cnt = counter.ToString().PadLeft(3, '0');
- if (counter > MAX_VALUE)
- counter = INIT_VALUE;
- else
- counter++;
- return now + cnt; // length of 20
- }
- }
- }
- }
|