User Story
No user story. This is just another practice.
Solution
PaymentGateway Interface Class:
public interface PaymentGateway {
void processPayment(Double amount);
Boolean refundPayment(String transactionId);
}
PayPalGateway Class:
public class PayPalGateway implements PaymentGateway {
public void processPayment(Double amount) {
System.debug('Payment processed through PayPal for amount: $' + amount);
}
public Boolean refundPayment(String transactionId) {
System.debug('Refund processed for transaction ID: ' + transactionId);
return true;
}
}
StripeGateway Class:
public class StripeGateway implements PaymentGateway {
public void processPayment(Double amount) {
// Code to process payment through Stripe API
System.debug('Payment processed through Stripe for amount: $' + amount);
}
public Boolean refundPayment(String transactionId) {
// Code to refund payment through Stripe API
System.debug('Refund processed for charge ID: ' + transactionId);
return true;
}
}
PaymentGateway paypal = new PayPalGateway();
paypal.processPayment(100.00);
paypal.refundPayment("PAY1234");
PaymentGateway stripe = new StripeGateway();
stripe.processPayment(75.50);
stripe.refundPayment("CHARGE5678");
Video
Video does not exists.