Skip to content

Commit 1277887

Browse files
committed
adding PaymentGateway classes
1 parent 05a3af0 commit 1277887

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
}

0 commit comments

Comments
 (0)