Skip to content

Instantly share code, notes, and snippets.

@waptik
Created March 19, 2020 15:36
Show Gist options
  • Save waptik/775bd9c50c33567545c6ac0fbc118cbd to your computer and use it in GitHub Desktop.
Save waptik/775bd9c50c33567545c6ac0fbc118cbd to your computer and use it in GitHub Desktop.
Select preferred payment method based on user's location
import paymentService, {paymentServiceType} from '@/services/paymentService'
import locationService, {locationServiceType} from '@/services/locationService'
// import paymentService from '@/services/paymentService'
const payWith: paymentServiceType = new paymentService()
export const locate: locationServiceType = new locationService()
// 2 letters country code
const ISO2: string = locate.getLocation().country(2)
export default () {
const isPayStack: boolean = payWith.payStackCountries.map(
(country: string) => ISO2 === country)
const isRavepay: boolean = payWith.ravepayCountries.map(
(country: string) => ISO2 === country)
// const isPaddle = !isPayStack && !isRavepay
if(isRavepay) return payWith.ravepay()
if(isPayStack) return payWith.payStack()
return payWith.paddle()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment