server.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import type { ConnectorContext, ConnectorServer } from '@/features/integrations/Lib/types'
  2. import { PaystackProvider, paystackConfigFrom } from '@/lib/payment-providers/paystack'
  3. import { manifest } from './manifest'
  4. function providerOf(ctx: ConnectorContext): PaystackProvider | null {
  5. const config = paystackConfigFrom(ctx.credentials)
  6. return config ? new PaystackProvider(config) : null
  7. }
  8. /**
  9. * Reading one row of the account's own transactions is the cheapest call
  10. * that proves a secret key. A test key and a live key both pass: which one
  11. * it is shows in the key itself, and a workshop is meant to try a payment on
  12. * the test key first.
  13. */
  14. export const connector: ConnectorServer = {
  15. manifest,
  16. async test(ctx) {
  17. const provider = providerOf(ctx)
  18. if (!provider) return { ok: false, message: 'Paystack: a secret key is required' }
  19. try {
  20. await provider.checkKey()
  21. return { ok: true }
  22. } catch (err) {
  23. return { ok: false, message: err instanceof Error ? err.message : 'Paystack did not answer' }
  24. }
  25. },
  26. jobs: {},
  27. }