Last active
January 2, 2020 13:36
-
-
Save GonchuB/37ceed953922e2652a710bf81978cd37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Option 1: Duplicating the function | |
async function payWithPayPal(payload) { | |
setLoading(true); | |
await apis.paypal(payload); | |
trackWithAnalytics({ method: 'paypal', amount: payload.amount }); | |
setLoading(false); | |
} | |
async function payWithCreditCard(payload) { | |
setLoading(true); | |
await apis.creditcard(payload); | |
trackWithAnalytics({ method: 'paypal', amount: payload.amount }); | |
setLoading(false); | |
} | |
// Option 2: "Creating an abstraction" to "pay" with any payment method | |
const paymentMethods = ['paypal', 'creditcard']; | |
async function pay(paymentMethod, payload) { | |
setLoading(true); | |
await apis[paymentMethod](payload); | |
trackWithAnalytics({ method: paymentMethod, amount: payload.amount }); | |
setLoading(false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment