Compare commits
1
Commits
dev/novalink
...
v1.13.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd7c1bcaab |
No files matched your search
@@ -11,6 +11,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -142,6 +143,66 @@ func TestEpayChannelListRequiresMerchantConfiguration(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEpayDefaultChannelsAllowExplicitActivation(t *testing.T) {
|
||||
for _, dialect := range []struct{ kind, env string }{{"sqlite", ""}, {"mysql", "TEST_MYSQL_DSN"}, {"postgres", "TEST_POSTGRES_DSN"}} {
|
||||
t.Run(dialect.kind, func(t *testing.T) {
|
||||
dsn := os.Getenv(dialect.env)
|
||||
if dialect.env != "" && dsn == "" {
|
||||
t.Skip("set " + dialect.env + " to run this database")
|
||||
}
|
||||
t.Setenv("PAYMENT_CREDENTIAL_KEY", base64.StdEncoding.EncodeToString([]byte(strings.Repeat("p", 32))))
|
||||
db := modelManagementDB(t, dialect.kind, dsn)
|
||||
require.NoError(t, db.AutoMigrate(model.PaymentGatewayPersistenceModels()...))
|
||||
setupEpaySettings(t)
|
||||
confirmPaymentComplianceForTest(t)
|
||||
require.NoError(t, model.UpdateOptionsBulk(map[string]string{
|
||||
"PayAddress": "https://pay.example.com", "EpayId": "merchant", "EpayKey": "test-key",
|
||||
}))
|
||||
|
||||
router := gin.New()
|
||||
router.GET("/gateways", GetPaymentGateways)
|
||||
router.PUT("/gateways/:gateway", UpdatePaymentGateway)
|
||||
router.GET("/topup", GetTopUpInfo)
|
||||
type channel struct{ Type string }
|
||||
type paymentData struct {
|
||||
Epay struct{ Configured, Enabled bool }
|
||||
EpayChannels []channel `json:"epay_pay_methods"`
|
||||
}
|
||||
request := func(method, path, body string) paymentData {
|
||||
t.Helper()
|
||||
recorder := httptest.NewRecorder()
|
||||
router.ServeHTTP(recorder, httptest.NewRequest(method, path, strings.NewReader(body)))
|
||||
var response struct {
|
||||
Success bool
|
||||
Data paymentData
|
||||
}
|
||||
require.NoError(t, common.Unmarshal(recorder.Body.Bytes(), &response))
|
||||
require.True(t, response.Success, recorder.Body.String())
|
||||
return response.Data
|
||||
}
|
||||
|
||||
status := request(http.MethodGet, "/gateways", "").Epay
|
||||
require.True(t, status.Configured, "default channels must be usable without editing them")
|
||||
assert.False(t, status.Enabled)
|
||||
request(http.MethodPut, "/gateways/epay", `{"enabled":true}`)
|
||||
assert.Equal(t, []channel{{"alipay"}, {"wxpay"}, {"custom1"}}, request(http.MethodGet, "/topup", "").EpayChannels)
|
||||
|
||||
require.NoError(t, model.UpdateOption("PayMethods", `[{"type":"wxpay","name":"WeChat"}]`))
|
||||
status = request(http.MethodGet, "/gateways", "").Epay
|
||||
assert.True(t, status.Configured)
|
||||
assert.False(t, status.Enabled)
|
||||
request(http.MethodPut, "/gateways/epay", `{"enabled":true}`)
|
||||
assert.Equal(t, []channel{{"wxpay"}}, request(http.MethodGet, "/topup", "").EpayChannels)
|
||||
|
||||
require.NoError(t, model.UpdateOption("PayMethods", `[]`))
|
||||
status = request(http.MethodGet, "/gateways", "").Epay
|
||||
assert.False(t, status.Configured)
|
||||
assert.False(t, status.Enabled)
|
||||
assert.Empty(t, request(http.MethodGet, "/topup", "").EpayChannels)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// epayCallbackCase is one callback sent to every Epay callback endpoint.
|
||||
type epayCallbackCase struct {
|
||||
name string
|
||||
@@ -150,6 +211,12 @@ type epayCallbackCase struct {
|
||||
}
|
||||
|
||||
func setupEpayCallbackTest(t *testing.T) *gorm.DB {
|
||||
t.Helper()
|
||||
setupEpaySettings(t)
|
||||
return setupPaymentWebhookDB(t)
|
||||
}
|
||||
|
||||
func setupEpaySettings(t *testing.T) {
|
||||
t.Helper()
|
||||
oldPayAddress, oldEpayID, oldEpayKey := operation_setting.PayAddress, operation_setting.EpayId, operation_setting.EpayKey
|
||||
oldCallbackAddress, oldPayMethods := operation_setting.CustomCallbackAddress, operation_setting.PayMethods
|
||||
@@ -165,7 +232,6 @@ func setupEpayCallbackTest(t *testing.T) *gorm.DB {
|
||||
paymentSetting.EpaySignType = operation_setting.EpaySignTypeMD5
|
||||
paymentSetting.EpayMerchantPrivateKey, paymentSetting.EpayPlatformPublicKey = "", ""
|
||||
system_setting.ServerAddress = "https://dashboard.example.com"
|
||||
return setupPaymentWebhookDB(t)
|
||||
}
|
||||
|
||||
func insertEpayCallbackOrders(t *testing.T, revision int, tradeNumbers ...string) {
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ func InitOptionMap() {
|
||||
common.OptionMap["AutoGroups"] = setting.AutoGroups2JsonString()
|
||||
common.OptionMap["DefaultUseAutoGroup"] = strconv.FormatBool(setting.DefaultUseAutoGroup)
|
||||
common.OptionMap["MaxTokenAutoGroups"] = strconv.Itoa(setting.GetMaxTokenAutoGroups())
|
||||
common.OptionMap["PayMethods"] = operation_setting.PayMethods2JsonString()
|
||||
common.OptionMap["PayMethods"] = operation_setting.DefaultEpayPayMethodsJSON()
|
||||
common.OptionMap["GitHubClientId"] = ""
|
||||
common.OptionMap["GitHubClientSecret"] = ""
|
||||
common.OptionMap["TelegramBotToken"] = ""
|
||||
|
||||
@@ -102,6 +102,11 @@ func readPaymentGatewayDraft(db *gorm.DB, provider string) (map[string]string, e
|
||||
for _, key := range keys {
|
||||
values[key] = ""
|
||||
}
|
||||
if provider == PaymentProviderEpay {
|
||||
// Use the same default as the settings page when no channel option exists.
|
||||
// A stored empty list still overrides it.
|
||||
values["PayMethods"] = operation_setting.DefaultEpayPayMethodsJSON()
|
||||
}
|
||||
for _, row := range rows {
|
||||
values[row.Key] = row.Value
|
||||
}
|
||||
|
||||
@@ -36,17 +36,22 @@ var PayMethods = []map[string]string{
|
||||
},
|
||||
}
|
||||
|
||||
func UpdatePayMethodsByJsonString(jsonString string) error {
|
||||
PayMethods = make([]map[string]string, 0)
|
||||
return common.Unmarshal([]byte(jsonString), &PayMethods)
|
||||
}
|
||||
|
||||
func PayMethods2JsonString() string {
|
||||
jsonBytes, err := common.Marshal(PayMethods)
|
||||
// Keep the built-in channels even after a saved option replaces PayMethods.
|
||||
var defaultEpayPayMethodsJSON = func() string {
|
||||
encoded, err := common.Marshal(PayMethods)
|
||||
if err != nil {
|
||||
return "[]"
|
||||
}
|
||||
return string(jsonBytes)
|
||||
return string(encoded)
|
||||
}()
|
||||
|
||||
func DefaultEpayPayMethodsJSON() string {
|
||||
return defaultEpayPayMethodsJSON
|
||||
}
|
||||
|
||||
func UpdatePayMethodsByJsonString(jsonString string) error {
|
||||
PayMethods = make([]map[string]string, 0)
|
||||
return common.Unmarshal([]byte(jsonString), &PayMethods)
|
||||
}
|
||||
|
||||
func ContainsPayMethod(method string) bool {
|
||||
|
||||
@@ -24,6 +24,36 @@ const info: TopupInfo = {
|
||||
|
||||
afterEach(() => vi.restoreAllMocks())
|
||||
|
||||
it('shows configured channel icons alongside their accessible names', async () => {
|
||||
vi.spyOn(api, 'post').mockResolvedValue({
|
||||
data: { message: 'success', data: '7.30' },
|
||||
})
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<EpayRechargeDialog
|
||||
info={{
|
||||
...info,
|
||||
epay_pay_methods: [
|
||||
{ type: 'alipay', name: 'Alipay channel', icon: 'SiAlipay' },
|
||||
{ type: 'wxpay', name: 'WeChat channel', icon: 'SiWechat' },
|
||||
],
|
||||
}}
|
||||
initialAmount={1}
|
||||
onOpenChange={() => undefined}
|
||||
onSuccess={() => undefined}
|
||||
/>
|
||||
</QueryClientProvider>
|
||||
)
|
||||
|
||||
for (const name of ['Alipay channel', 'WeChat channel']) {
|
||||
const icon = (await screen.findByTitle(name)).closest('svg')
|
||||
expect(icon).toBeVisible()
|
||||
expect(icon?.closest('label')).toContainElement(
|
||||
screen.getByRole('radio', { name })
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it('selects the only eligible channel and discards the old quote after changing the amount', async () => {
|
||||
const request = vi
|
||||
.spyOn(api, 'post')
|
||||
|
||||
@@ -6,6 +6,7 @@ import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
|
||||
import { toIntlLocale } from '@/i18n/languages'
|
||||
import { formatNumber } from '@/lib/format'
|
||||
|
||||
import { getPaymentIcon } from '../lib/ui'
|
||||
import type { PaymentMethod } from '../types'
|
||||
|
||||
export function EpayChannelPicker(props: {
|
||||
@@ -42,6 +43,17 @@ export function EpayChannelPicker(props: {
|
||||
className='min-w-0 rounded-md border p-2'
|
||||
>
|
||||
<RadioGroupItem id={id} value={method.type} disabled={disabled} />
|
||||
<span
|
||||
aria-hidden='true'
|
||||
className='inline-flex shrink-0 empty:hidden'
|
||||
>
|
||||
{getPaymentIcon(
|
||||
method.type,
|
||||
'size-4',
|
||||
method.icon,
|
||||
method.name
|
||||
)}
|
||||
</span>
|
||||
<span className='flex min-w-0 flex-col gap-1'>
|
||||
<span className='break-all'>{method.name}</span>
|
||||
{disabled && (
|
||||
|
||||
Reference in new issue
Block a user