33using System . Web . Routing ;
44using SmartStore . Core . Configuration ;
55using SmartStore . Core . Domain . Orders ;
6+ using SmartStore . Core . Domain . Payments ;
67using SmartStore . Core . Logging ;
78using SmartStore . Core . Plugins ;
9+ using SmartStore . PayPal . Services ;
810using SmartStore . PayPal . Settings ;
911using SmartStore . Services ;
1012using SmartStore . Services . Orders ;
@@ -23,6 +25,7 @@ protected PayPalRestApiProviderBase()
2325 public ICommonServices Services { get ; set ; }
2426 public IOrderService OrderService { get ; set ; }
2527 public IOrderTotalCalculationService OrderTotalCalculationService { get ; set ; }
28+ public IPayPalService PayPalService { get ; set ; }
2629
2730 protected string GetControllerName ( )
2831 {
@@ -89,10 +92,29 @@ public override RefundPaymentResult Refund(RefundPaymentRequest request)
8992 } ;
9093
9194 var settings = Services . Settings . LoadSetting < TSetting > ( request . Order . StoreId ) ;
95+ var session = new PayPalSessionData ( ) ;
9296
93- var transactionId = request . Order . CaptureTransactionId ;
94-
95- // TODO
97+ var apiResult = PayPalService . EnsureAccessToken ( session , settings ) ;
98+ if ( result . Success )
99+ {
100+ apiResult = PayPalService . Refund ( settings , session , request ) ;
101+
102+ if ( apiResult . Success && apiResult . Json != null )
103+ {
104+ if ( request . IsPartialRefund )
105+ result . NewPaymentStatus = PaymentStatus . PartiallyRefunded ;
106+ else
107+ result . NewPaymentStatus = PaymentStatus . Refunded ;
108+ }
109+ else
110+ {
111+ result . Errors . Add ( apiResult . ErrorMessage ) ;
112+ }
113+ }
114+ else
115+ {
116+ result . Errors . Add ( apiResult . ErrorMessage ) ;
117+ }
96118
97119 return result ;
98120 }
0 commit comments