@gt6/sdk 1.0.17 → 1.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1886,6 +1886,83 @@ class TransactionsAPI {
1886
1886
  }
1887
1887
  return null;
1888
1888
  }
1889
+ /**
1890
+ * 创建支付记录
1891
+ * @param paymentData 支付记录数据
1892
+ * @returns 创建支付记录响应
1893
+ */
1894
+ async createPaymentRecord(paymentData) {
1895
+ try {
1896
+ // 获取用户token
1897
+ const token = this.getToken();
1898
+ if (!token) {
1899
+ return {
1900
+ success: false,
1901
+ message: '用户未登录'
1902
+ };
1903
+ }
1904
+ const response = await this.client.request('/web/payment/record/create', {
1905
+ method: 'POST',
1906
+ headers: {
1907
+ 'Authorization': `Bearer ${token}`,
1908
+ 'Content-Type': 'application/json'
1909
+ },
1910
+ body: JSON.stringify(paymentData)
1911
+ });
1912
+ // 检查响应格式
1913
+ if (response && typeof response === 'object') {
1914
+ // 如果响应包含 code 字段,说明是标准格式
1915
+ if ('code' in response) {
1916
+ const responseData = response;
1917
+ return {
1918
+ success: responseData.code === 0,
1919
+ message: responseData.message || (responseData.code === 0 ? '支付申请已提交' : '提交失败'),
1920
+ code: responseData.code,
1921
+ data: responseData.data
1922
+ };
1923
+ }
1924
+ // 如果没有 code 字段,可能是其他格式
1925
+ return {
1926
+ success: true,
1927
+ message: '支付申请已提交',
1928
+ data: response
1929
+ };
1930
+ }
1931
+ return {
1932
+ success: false,
1933
+ message: '响应格式错误'
1934
+ };
1935
+ }
1936
+ catch (error) {
1937
+ // 如果是HTTP错误,尝试解析响应体
1938
+ if (error.statusCode && error.message) {
1939
+ // 对于401错误,返回认证失败信息
1940
+ if (error.statusCode === 401) {
1941
+ return {
1942
+ success: false,
1943
+ message: '认证失败,请重新登录'
1944
+ };
1945
+ }
1946
+ // 对于400错误,可能是数据有误
1947
+ if (error.statusCode === 400) {
1948
+ return {
1949
+ success: false,
1950
+ message: error.message || '支付数据有误,请检查输入'
1951
+ };
1952
+ }
1953
+ // 对于其他HTTP错误,返回状态码信息
1954
+ return {
1955
+ success: false,
1956
+ message: error.message || `HTTP ${error.statusCode} 错误`
1957
+ };
1958
+ }
1959
+ // 对于网络错误或其他错误
1960
+ return {
1961
+ success: false,
1962
+ message: error instanceof Error ? error.message : '创建支付记录失败'
1963
+ };
1964
+ }
1965
+ }
1889
1966
  }
1890
1967
 
1891
1968
  /**
@@ -2274,6 +2351,12 @@ class GT6SDK {
2274
2351
  async createRetailOrder(orderData) {
2275
2352
  return this.transactions.createRetailOrder(orderData);
2276
2353
  }
2354
+ /**
2355
+ * 便捷方法:创建支付记录
2356
+ */
2357
+ async createPaymentRecord(paymentData) {
2358
+ return this.transactions.createPaymentRecord(paymentData);
2359
+ }
2277
2360
  }
2278
2361
 
2279
2362
  export { ArticlesAPI, FormsAPI, GT6Client, GT6Error, GT6SDK, ProductsAPI, SettingsAPI, TransactionsAPI, UsersAPI, GT6SDK as default };