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; }
///
/// the final charge will based on this value.
///
public decimal NetAmount { get; set; }
///
/// Gets or sets 用户授权码, 当商户用扫码枪扫用户的条形码时得到的字符串
///
public string AuthCode { get; set; }
///
/// Gets or sets the 商户订单号, used for refund.
///
public string BillNumber { get; set; }
public string ExtraCommand { get; set; }
///
/// Gets or sets the 订单标题 UTF8编码格式,32个字节内,最长支持16个汉字
///
public string Title { get; set; }
public string OperatorId { get; set; }
public string SiteId { get; set; }
///
/// Gets or sets the terminal id for submit this order
///
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; }
///
/// Gets or sets the raw result (a string) from 3rd party payment server.
///
public string PaymentResultRawResult { get; set; }
}
///
/// Host the phase 1 supported transaction info.
///
public class PaymentOrder
{
public string SiteId { get; set; }
///
/// 根据不同场景选择不同的支付方式, accepted values: WX_SCAN、ALI_SCAN、ALL_IN_SCAN
///
public string PaymentMethod { get; set; }
public bool IsForRefund { get; set; }
///
/// trade status, expected values: USERPAYING, SUCCESS, SUCCESS_CANCELLING, PAYERROR, PAYERROR_CANCELLING, CLOSED
///
public TradeStatusEnum TradeStatus { get; set; }
public decimal TotalAmount { get; set; }
///
/// 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.
///
public decimal NetAmount { get; set; }
///
/// Gets or sets the 商户订单号, 确保唯一, key field used for refund
///
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 Optional { get; set; }
///
/// Gets or sets the 订单标题 UTF8编码格式,32个字节内,最长支持16个汉字
///
public string Title { get; set; }
///
/// Gets or sets 用户授权码, 当商户用扫码枪扫用户的条形码时得到的字符串
///
public string AuthCode { get; set; }
///
/// Gets or sets the operator id for who submit this order from site.
///
public string OperatorId { get; set; }
///
/// Gets or sets the terminal id for submit this order
///
public string TerminalId { get; set; }
///
/// Gets or sets the time that server received this order for processing.
///
public DateTime ServerSideTimestamp { get; set; }
public List 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
}
}
}
}