Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.2 kB
1
Indexable
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class PaymentClient {
  public static void main(String[] args) {
    // Parse command-line arguments
    if (args.length != 2) {
      System.out.println("Usage: PaymentClient <csv file> <payment service endpoint>");
      return;
    }
    String csvFile = args[0];
    String endpoint = args[1];

    // Read CSV file and create list of payment objects
    List<Payment> payments = new ArrayList<>();
    try (BufferedReader reader = new BufferedReader(new FileReader(csvFile))) {
      String line;
      while ((line = reader.readLine()) != null) {
        String[] fields = line.split(",");
        String recipient = fields[0];
        double amount = Double.parseDouble(fields[1]);
        Payment payment = new Payment(recipient, amount);
        payments.add(payment);
      }
    } catch (IOException e) {
      System.out.println("Error reading CSV file: " + e.getMessage());
      return;
    }

    // Make payments through payment service
    for (Payment payment : payments) {
      try {
        PaymentResponse response = makePayment(endpoint, payment);
        System.out.println("Payment to " + payment.getRecipient() + " succeeded: " + response.isSuccess());
      } catch (IOException e) {
        System.out.println("Error making payment to " + payment.getRecipient() + ": " + e.getMessage());
      }
    }
  }

  private static PaymentResponse makePayment(String endpoint, Payment payment) throws IOException {
    // Send HTTP request to payment service endpoint with payment details
    // and return response
  }
}

class Payment {
  private String recipient;
  private double amount;

  public Payment(String recipient, double amount) {
    this.recipient = recipient;
    this.amount = amount;
  }

  public String getRecipient() {
    return recipient;
  }

  public double getAmount() {
    return amount;
  }
}

class PaymentResponse {
  private boolean success;

  public PaymentResponse(boolean success) {
    this.success = success;
  }

  public boolean isSuccess() {
    return success;
  }
}