@gt6/sdk 1.0.18 → 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.
@@ -1890,6 +1890,83 @@ class TransactionsAPI {
1890
1890
  }
1891
1891
  return null;
1892
1892
  }
1893
+ /**
1894
+ * 创建支付记录
1895
+ * @param paymentData 支付记录数据
1896
+ * @returns 创建支付记录响应
1897
+ */
1898
+ async createPaymentRecord(paymentData) {
1899
+ try {
1900
+ // 获取用户token
1901
+ const token = this.getToken();
1902
+ if (!token) {
1903
+ return {
1904
+ success: false,
1905
+ message: '用户未登录'
1906
+ };
1907
+ }
1908
+ const response = await this.client.request('/web/payment/record/create', {
1909
+ method: 'POST',
1910
+ headers: {
1911
+ 'Authorization': `Bearer ${token}`,
1912
+ 'Content-Type': 'application/json'
1913
+ },
1914
+ body: JSON.stringify(paymentData)
1915
+ });
1916
+ // 检查响应格式
1917
+ if (response && typeof response === 'object') {
1918
+ // 如果响应包含 code 字段,说明是标准格式
1919
+ if ('code' in response) {
1920
+ const responseData = response;
1921
+ return {
1922
+ success: responseData.code === 0,
1923
+ message: responseData.message || (responseData.code === 0 ? '支付申请已提交' : '提交失败'),
1924
+ code: responseData.code,
1925
+ data: responseData.data
1926
+ };
1927
+ }
1928
+ // 如果没有 code 字段,可能是其他格式
1929
+ return {
1930
+ success: true,
1931
+ message: '支付申请已提交',
1932
+ data: response
1933
+ };
1934
+ }
1935
+ return {
1936
+ success: false,
1937
+ message: '响应格式错误'
1938
+ };
1939
+ }
1940
+ catch (error) {
1941
+ // 如果是HTTP错误,尝试解析响应体
1942
+ if (error.statusCode && error.message) {
1943
+ // 对于401错误,返回认证失败信息
1944
+ if (error.statusCode === 401) {
1945
+ return {
1946
+ success: false,
1947
+ message: '认证失败,请重新登录'
1948
+ };
1949
+ }
1950
+ // 对于400错误,可能是数据有误
1951
+ if (error.statusCode === 400) {
1952
+ return {
1953
+ success: false,
1954
+ message: error.message || '支付数据有误,请检查输入'
1955
+ };
1956
+ }
1957
+ // 对于其他HTTP错误,返回状态码信息
1958
+ return {
1959
+ success: false,
1960
+ message: error.message || `HTTP ${error.statusCode} 错误`
1961
+ };
1962
+ }
1963
+ // 对于网络错误或其他错误
1964
+ return {
1965
+ success: false,
1966
+ message: error instanceof Error ? error.message : '创建支付记录失败'
1967
+ };
1968
+ }
1969
+ }
1893
1970
  }
1894
1971
 
1895
1972
  /**
@@ -2278,6 +2355,12 @@ class GT6SDK {
2278
2355
  async createRetailOrder(orderData) {
2279
2356
  return this.transactions.createRetailOrder(orderData);
2280
2357
  }
2358
+ /**
2359
+ * 便捷方法:创建支付记录
2360
+ */
2361
+ async createPaymentRecord(paymentData) {
2362
+ return this.transactions.createPaymentRecord(paymentData);
2363
+ }
2281
2364
  }
2282
2365
 
2283
2366
  exports.ArticlesAPI = ArticlesAPI;