24 lines
1001 B
Java
24 lines
1001 B
Java
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";
|
|
}
|
|
}
|