Sync Adapter to Java 25: add StripePaymentClassAdapter, README mapping
This commit is contained in:
23
02-structural/adapter/StripePaymentClassAdapter.java
Normal file
23
02-structural/adapter/StripePaymentClassAdapter.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package adapter;
|
||||
// Class Adapter: extends Adaptee, implements Target
|
||||
// Can only be used when you CAN extend the Adaptee (it's not final)
|
||||
public class StripePaymentClassAdapter extends StripeClient implements PaymentGateway {
|
||||
public StripePaymentClassAdapter(String apiKey) {
|
||||
super(apiKey);
|
||||
}
|
||||
@Override
|
||||
public boolean charge(String customerId, double amount, String currency) {
|
||||
long cents = Math.round(amount * 100);
|
||||
return createCharge(customerId, cents, currency.toLowerCase()).success;
|
||||
// Note: calls inherited method directly — no 'stripe.' prefix needed
|
||||
}
|
||||
@Override
|
||||
public boolean refund(String transactionId, double amount) {
|
||||
return issueRefund(transactionId, Math.round(amount * 100));
|
||||
}
|
||||
@Override
|
||||
public String getStatus(String transactionId) {
|
||||
StripeChargeResult r = retrieveCharge(transactionId);
|
||||
return r.success ? (r.status != null ? r.status.toUpperCase() : "UNKNOWN") : "FAILED";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user