-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathPaymentProcessor.java
More file actions
32 lines (26 loc) · 1.13 KB
/
PaymentProcessor.java
File metadata and controls
32 lines (26 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.example.payment;
public class PaymentProcessor {
private static final String API_KEY = "sk_test_123456";
private final DatabaseConnection databaseConnection;
private final EmailService emailService;
private final PaymentApi paymentApi;
public PaymentProcessor(DatabaseConnection databaseConnection, EmailService emailService, PaymentApi paymentApi) {
this.databaseConnection = databaseConnection;
this.emailService = emailService;
this.paymentApi = paymentApi;
}
public boolean processPayment(double amount) {
// Anropar extern betaltjänst direkt med statisk API-nyckel
PaymentApiResponse response = this.paymentApi.charge(API_KEY, amount);
// Skriver till databas direkt
if (response.success()) {
this.databaseConnection
.executeUpdate("INSERT INTO payments (amount, status) VALUES (" + amount + ", 'SUCCESS')");
}
// Skickar e-post direkt
if (response.success()) {
emailService.sendPaymentConfirmation("user@example.com", amount);
}
return response.success();
}
}