payment_webhook_availability.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package controller
  2. import (
  3. "strings"
  4. "github.com/QuantumNous/new-api/setting"
  5. "github.com/QuantumNous/new-api/setting/operation_setting"
  6. )
  7. func isStripeTopUpEnabled() bool {
  8. return strings.TrimSpace(setting.StripeApiSecret) != "" &&
  9. strings.TrimSpace(setting.StripeWebhookSecret) != "" &&
  10. strings.TrimSpace(setting.StripePriceId) != ""
  11. }
  12. func isStripeWebhookConfigured() bool {
  13. return strings.TrimSpace(setting.StripeWebhookSecret) != ""
  14. }
  15. func isStripeWebhookEnabled() bool {
  16. return isStripeTopUpEnabled()
  17. }
  18. func isCreemTopUpEnabled() bool {
  19. products := strings.TrimSpace(setting.CreemProducts)
  20. return strings.TrimSpace(setting.CreemApiKey) != "" &&
  21. products != "" &&
  22. products != "[]"
  23. }
  24. func isCreemWebhookConfigured() bool {
  25. return strings.TrimSpace(setting.CreemWebhookSecret) != ""
  26. }
  27. func isCreemWebhookEnabled() bool {
  28. return isCreemTopUpEnabled() && isCreemWebhookConfigured()
  29. }
  30. func isWaffoTopUpEnabled() bool {
  31. if !setting.WaffoEnabled {
  32. return false
  33. }
  34. return isWaffoWebhookConfigured()
  35. }
  36. func isWaffoWebhookConfigured() bool {
  37. if setting.WaffoSandbox {
  38. return strings.TrimSpace(setting.WaffoSandboxApiKey) != "" &&
  39. strings.TrimSpace(setting.WaffoSandboxPrivateKey) != "" &&
  40. strings.TrimSpace(setting.WaffoSandboxPublicCert) != ""
  41. }
  42. return strings.TrimSpace(setting.WaffoApiKey) != "" &&
  43. strings.TrimSpace(setting.WaffoPrivateKey) != "" &&
  44. strings.TrimSpace(setting.WaffoPublicCert) != ""
  45. }
  46. func isWaffoWebhookEnabled() bool {
  47. return isWaffoTopUpEnabled()
  48. }
  49. func isWaffoPancakeTopUpEnabled() bool {
  50. if !setting.WaffoPancakeEnabled {
  51. return false
  52. }
  53. return isWaffoPancakeWebhookConfigured() &&
  54. strings.TrimSpace(setting.WaffoPancakeMerchantID) != "" &&
  55. strings.TrimSpace(setting.WaffoPancakePrivateKey) != "" &&
  56. strings.TrimSpace(setting.WaffoPancakeStoreID) != "" &&
  57. strings.TrimSpace(setting.WaffoPancakeProductID) != ""
  58. }
  59. func isWaffoPancakeWebhookConfigured() bool {
  60. currentWebhookKey := strings.TrimSpace(setting.WaffoPancakeWebhookPublicKey)
  61. if setting.WaffoPancakeSandbox {
  62. currentWebhookKey = strings.TrimSpace(setting.WaffoPancakeWebhookTestKey)
  63. }
  64. return currentWebhookKey != ""
  65. }
  66. func isWaffoPancakeWebhookEnabled() bool {
  67. return isWaffoPancakeTopUpEnabled()
  68. }
  69. func isEpayTopUpEnabled() bool {
  70. return isEpayWebhookConfigured() && len(operation_setting.PayMethods) > 0
  71. }
  72. func isEpayWebhookConfigured() bool {
  73. return strings.TrimSpace(operation_setting.PayAddress) != "" &&
  74. strings.TrimSpace(operation_setting.EpayId) != "" &&
  75. strings.TrimSpace(operation_setting.EpayKey) != ""
  76. }
  77. func isEpayWebhookEnabled() bool {
  78. return isEpayTopUpEnabled()
  79. }