feat(avatar): integrate Huihui payments
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from services.huihui_payment import HuihuiPaymentClient
|
||||
|
||||
|
||||
def test_create_payment_uses_huihui_payment_v3_contract():
|
||||
client = HuihuiPaymentClient({
|
||||
"HUIHUI_PAYMENT_BASE_URL": "https://open.example/api/payment-v3",
|
||||
"HUIHUI_APP_ID": "app-id",
|
||||
"HUIHUI_ACCESS_ID": "access-id",
|
||||
"HUIHUI_ACCESS_SECRET": "access-secret",
|
||||
})
|
||||
response = Mock()
|
||||
response.status_code = 200
|
||||
response.json.return_value = {
|
||||
"code": 0,
|
||||
"data": {"orderId": "provider-id", "status": "pending", "payMessage": "mock"},
|
||||
}
|
||||
|
||||
with patch("services.huihui_payment.httpx.post", return_value=response) as post:
|
||||
result = client.create_payment(
|
||||
huihui_token="user-token",
|
||||
huihui_user_id="user-id",
|
||||
real_name="测试用户",
|
||||
order_no="AV202608260001",
|
||||
amount="10.00",
|
||||
points_amount=2_000_000,
|
||||
pay_type="WECHAT",
|
||||
pay_way="APP",
|
||||
callback_url="https://digital.example/api/token/payment/callback/secret",
|
||||
)
|
||||
|
||||
assert result["orderId"] == "provider-id"
|
||||
assert post.call_args.args[0] == "https://open.example/api/payment-v3/payment/pay"
|
||||
assert post.call_args.kwargs["headers"] == {
|
||||
"Authorization": "Bearer user-token",
|
||||
"appId": "app-id",
|
||||
"windowAppId": "app-id",
|
||||
}
|
||||
params = post.call_args.kwargs["params"]
|
||||
assert params["appId"] == "app-id"
|
||||
assert params["accessId"] == "access-id"
|
||||
assert params["userId"] == "user-id"
|
||||
assert params["signature"]
|
||||
assert "accessSecret" not in params
|
||||
body = post.call_args.kwargs["json"]
|
||||
assert body["payType"] == "WECHAT"
|
||||
assert body["payWay"] == "APP"
|
||||
assert body["masterOrderAmt"] == "10.00"
|
||||
assert body["payAmt"] == 10.0
|
||||
Reference in New Issue
Block a user