File tree Expand file tree Collapse file tree
DesignPattern.Builder.PaymentService Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ namespace DesignPattern . Builder . PaymentService ;
2+
3+ public interface IPaymentGateway
4+ {
5+ IPaymentGateway GatewayName ( string gatewayName ) ;
6+ IPaymentGateway Currency ( string currency ) ;
7+ IPaymentGateway Amount ( decimal amount ) ;
8+ IPaymentGateway PaymentMethod ( string paymentMethod ) ;
9+ IPaymentGateway WebhookUrl ( string url ) ;
10+ IPaymentGateway TransactionFee ( decimal fee ) ;
11+
12+ PaymentGateway CreateGateway ( ) ;
13+ }
Original file line number Diff line number Diff line change 1+ using System . Text ;
2+
3+ namespace DesignPattern . Builder . PaymentService ;
4+
5+ public class PaymentGateway
6+ {
7+ public string Name { get ; set ; }
8+ public string Currency { get ; set ; }
9+ public decimal Amount { get ; set ; }
10+ public string SupportedPaymentMethod { get ; set ; }
11+ public string WebhookUrl { get ; set ; }
12+ public decimal TransactionFee { get ; set ; }
13+
14+ public override string ToString ( )
15+ {
16+ var text = $ "Payment Gateway: { Name } \n " +
17+ $ "Currency: { Currency } \n " +
18+ $ "Amount: { Amount : C2} { Currency } \n " +
19+ $ "Transaction Fee: { TransactionFee : P2} \n " +
20+ $ "Supported Payment Methods: { SupportedPaymentMethod } \n " +
21+ $ "Webhook URL: { WebhookUrl } \n " +
22+ $ "Total Charge (Amount + Fee): { ( Amount + ( Amount * TransactionFee ) ) : C2} { Currency } \n " +
23+ $ "Processing Status: { ProcessPaymentResult ( ) } ";
24+ return text ;
25+ }
26+
27+ private string ProcessPaymentResult ( )
28+ {
29+ if ( Amount > 0 && ! string . IsNullOrEmpty ( SupportedPaymentMethod ) )
30+ {
31+ return "Payment processed successfully." ;
32+ }
33+
34+ return "Payment failed. Invalid amount or payment method." ;
35+ }
36+ }
37+
38+ public enum EnumPaymentMethods
39+ {
40+ CreditCard = 1 ,
41+ DebitCard = 2 ,
42+ ApplePay = 3 ,
43+ GooglePay = 4
44+ }
You can’t perform that action at this time.
0 commit comments