using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Transactions;
namespace ConsoleApplication1
![InBlock.gif]()
{
public
class Service1
![InBlock.gif]()
{
public
void HandlePaymentResult(PaymentManner1 paymentManner,
string orderSeqNo)
![InBlock.gif]()
{
![InBlock.gif]()
IPaymentResultHandleService1 handleService = PaymentResultHandleServiceFactory1.GetService(paymentManner);
![InBlock.gif]()
handleService.Handle(orderSeqNo);
![InBlock.gif]()
}
![InBlock.gif]()
}
public
class OrderManagement1
![InBlock.gif]()
{
public
void Pay(
decimal money)
![InBlock.gif]()
{
![InBlock.gif]()
var manner=
new PaymentMannerManagement1().FindAvailableManner(money);
//后续支付
![InBlock.gif]()
}
![InBlock.gif]()
}
public
enum PaymentManner1
![InBlock.gif]()
{
![InBlock.gif]()
Zhifubao,
![InBlock.gif]()
Yinlian,
![InBlock.gif]()
PlatformAccount
![InBlock.gif]()
}
public
class PaymentMannerParams
![InBlock.gif]()
{
/// <summary>
/// 地址还是内部方法
/// </summary>
public UriOrFunction UriOrFunction { get; set; }
/// <summary>
/// 地址
/// </summary>
public
string Uri { get; set; }
/// <summary>
/// 方法名
/// </summary>
public
string FunctionName { get; set; }
enum UriOrFunction
![InBlock.gif]()
{
![InBlock.gif]()
Uri,
![InBlock.gif]()
Function
![InBlock.gif]()
}
![InBlock.gif]()
}
public
class PaymentMannerManagement1
![InBlock.gif]()
{
public Dictionary<PaymentManner1, PaymentMannerParams > FindAvailableManner(
decimal moneyOfPay)
![InBlock.gif]()
{
throw
new System.Exception();
![InBlock.gif]()
}
![InBlock.gif]()
}
public
class PaymentResultHandleServiceFactory1
![InBlock.gif]()
{
private
static PaymentResultHandleServiceFactory1()
![InBlock.gif]()
{
![InBlock.gif]()
_serviceMap =
new Dictionary<PaymentManner1, IPaymentResultHandleService1>();
![InBlock.gif]()
_serviceMap.Add(PaymentManner1.PlatformAccount,
new PlatformAccountPaymentResultHandleService1());
![InBlock.gif]()
_serviceMap.Add(PaymentManner1.Yinlian,
new YinlianPaymentResultHandleService1());
![InBlock.gif]()
_serviceMap.Add(PaymentManner1.Zhifubao,
new ZhifubaoPaymentResultHandleService1());
![InBlock.gif]()
}
private
static Dictionary<PaymentManner1 , IPaymentResultHandleService1> _serviceMap;
public
static IPaymentResultHandleService1 GetService(PaymentManner1 paymentManner )
![InBlock.gif]()
{
return _serviceMap[paymentManner];
![InBlock.gif]()
}
![InBlock.gif]()
}
public
interface IPaymentResultHandleService1
![InBlock.gif]()
{
void Handle(
string orderSeqNo);
![InBlock.gif]()
}
public
class ZhifubaoPaymentResultHandleService1:IPaymentResultHandleService1
![InBlock.gif]()
{
private OrderRepository1 _orderManagement;
private ZhifubaoRepository1 _zhifubaoManagement;
public
void Handle(
string orderSeqNo)
![InBlock.gif]()
{
using (TransactionScope scope =
new TransactionScope())
![InBlock.gif]()
{
![InBlock.gif]()
_orderManagement.UpdateState();
this._zhifubaoManagement.Update();
![InBlock.gif]()
scope.Complete();
![InBlock.gif]()
}
![InBlock.gif]()
}
![InBlock.gif]()
}
public
class YinlianPaymentResultHandleService1 : IPaymentResultHandleService1
![InBlock.gif]()
{
private OrderRepository1 _orderManagement;
private YinlianRepository1 _yinlianManagement;
public
void Handle(
string orderSeqNo)
![InBlock.gif]()
{
using (TransactionScope scope =
new TransactionScope())
![InBlock.gif]()
{
this._orderManagement.UpdateState();
this._yinlianManagement.Update();
![InBlock.gif]()
scope.Complete();
![InBlock.gif]()
}
![InBlock.gif]()
}
![InBlock.gif]()
}
public
class PlatformAccountPaymentResultHandleService1:IPaymentResultHandleService1
![InBlock.gif]()
{
private OrderRepository1 _orderManagement;
private PlatformAccountRepository1 _platformAccountManagement;
public
void Handle(
string orderSeqNo)
![InBlock.gif]()
{
using (TransactionScope scope =
new TransactionScope())
![InBlock.gif]()
{
this._orderManagement.UpdateState();
this._platformAccountManagement.Update();
![InBlock.gif]()
scope.Complete();
![InBlock.gif]()
}
![InBlock.gif]()
}
![InBlock.gif]()
}
public
class OrderRepository1
![InBlock.gif]()
{
public
void UpdateState()
![InBlock.gif]()
{
throw
new System.Exception(); }
![InBlock.gif]()
}
public
class PlatformAccountRepository1
![InBlock.gif]()
{
public
void Update()
![InBlock.gif]()
{
throw
new System.Exception(); }
![InBlock.gif]()
}
public
class ZhifubaoRepository1
![InBlock.gif]()
{
public
void Update()
![InBlock.gif]()
{
throw
new System.Exception(); }
![InBlock.gif]()
}
public
class YinlianRepository1
![InBlock.gif]()
{
public
void Update()
![InBlock.gif]()
{
throw
new System.Exception(); }
![InBlock.gif]()
}
![InBlock.gif]()
}