蛋蛋星球-制度模式
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 regels
6.1 KiB

  1. package lakala
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/go-pay/gopay"
  7. )
  8. // 创建报关单(非拆单)
  9. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_report_single
  10. func (c *Client) CreateReportSingle(ctx context.Context, partnerReportId string, bm gopay.BodyMap) (rsp *ReportRsp, err error) {
  11. if partnerReportId == gopay.NULL {
  12. return nil, fmt.Errorf("partnerReportId is empty")
  13. }
  14. if err = bm.CheckEmptyError("partner_order_id", "customs", "mch_customs_id", "mch_customs_name"); err != nil {
  15. return nil, err
  16. }
  17. url := fmt.Sprintf(createReportSingle, c.PartnerCode, partnerReportId)
  18. bs, err := c.doPut(ctx, url, bm)
  19. if err != nil {
  20. return nil, err
  21. }
  22. rsp = new(ReportRsp)
  23. err = json.Unmarshal(bs, rsp)
  24. if err != nil {
  25. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  26. }
  27. return rsp, nil
  28. }
  29. // 创建报关单(拆单)
  30. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_report_separate
  31. func (c *Client) CreateReportSeparate(ctx context.Context, partnerReportId, partnerSubReportId string, bm gopay.BodyMap) (rsp *ReportRsp, err error) {
  32. if partnerReportId == gopay.NULL {
  33. return nil, fmt.Errorf("partnerReportId is empty")
  34. }
  35. if partnerSubReportId == gopay.NULL {
  36. return nil, fmt.Errorf("partnerSubReportId is empty")
  37. }
  38. if err = bm.CheckEmptyError("partner_order_id", "customs", "mch_customs_id", "mch_customs_name", "order_fee", "product_fee", "transport_fee"); err != nil {
  39. return nil, err
  40. }
  41. url := fmt.Sprintf(createReportSeparate, c.PartnerCode, partnerReportId, partnerSubReportId)
  42. bs, err := c.doPut(ctx, url, bm)
  43. if err != nil {
  44. return nil, err
  45. }
  46. rsp = new(ReportRsp)
  47. err = json.Unmarshal(bs, rsp)
  48. if err != nil {
  49. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  50. }
  51. return rsp, nil
  52. }
  53. // 报关状态查询
  54. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_query_single
  55. func (c *Client) ReportStatus(ctx context.Context, partnerReportId string) (rsp *ReportRsp, err error) {
  56. if partnerReportId == gopay.NULL {
  57. return nil, fmt.Errorf("partnerReportId is empty")
  58. }
  59. url := fmt.Sprintf(queryReportStatus, c.PartnerCode, partnerReportId)
  60. bs, err := c.doGet(ctx, url, "")
  61. if err != nil {
  62. return nil, err
  63. }
  64. rsp = new(ReportRsp)
  65. err = json.Unmarshal(bs, rsp)
  66. if err != nil {
  67. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  68. }
  69. return rsp, nil
  70. }
  71. // 报关子单状态查询
  72. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_query_separate
  73. func (c *Client) ReportSubStatus(ctx context.Context, partnerReportId, partnerSubReportId string) (rsp *ReportRsp, err error) {
  74. if partnerReportId == gopay.NULL {
  75. return nil, fmt.Errorf("partnerReportId is empty")
  76. }
  77. url := fmt.Sprintf(queryReportSubStatus, c.PartnerCode, partnerReportId, partnerSubReportId)
  78. bs, err := c.doGet(ctx, url, "")
  79. if err != nil {
  80. return nil, err
  81. }
  82. rsp = new(ReportRsp)
  83. err = json.Unmarshal(bs, rsp)
  84. if err != nil {
  85. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  86. }
  87. return rsp, nil
  88. }
  89. // 修改报关信息(非拆单)
  90. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_modify_single
  91. func (c *Client) ModifyReportSingle(ctx context.Context, partnerReportId string, bm gopay.BodyMap) (rsp *ReportRsp, err error) {
  92. if partnerReportId == gopay.NULL {
  93. return nil, fmt.Errorf("partnerReportId is empty")
  94. }
  95. if err = bm.CheckEmptyError("customs", "mch_customs_id", "mch_customs_name"); err != nil {
  96. return nil, err
  97. }
  98. url := fmt.Sprintf(modifyReportSingle, c.PartnerCode, partnerReportId)
  99. bs, err := c.doPut(ctx, url, bm)
  100. if err != nil {
  101. return nil, err
  102. }
  103. rsp = new(ReportRsp)
  104. err = json.Unmarshal(bs, rsp)
  105. if err != nil {
  106. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  107. }
  108. return rsp, nil
  109. }
  110. // 修改报关信息(拆单)
  111. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_modify_separate
  112. func (c *Client) ModifyReportSeparate(ctx context.Context, partnerReportId, partnerSubReportId string, bm gopay.BodyMap) (rsp *ReportRsp, err error) {
  113. if partnerReportId == gopay.NULL {
  114. return nil, fmt.Errorf("partnerReportId is empty")
  115. }
  116. if partnerSubReportId == gopay.NULL {
  117. return nil, fmt.Errorf("partnerSubReportId is empty")
  118. }
  119. if err = bm.CheckEmptyError("customs", "mch_customs_id", "mch_customs_name", "order_fee", "product_fee", "transport_fee"); err != nil {
  120. return nil, err
  121. }
  122. url := fmt.Sprintf(modifyReportSeparate, c.PartnerCode, partnerReportId, partnerSubReportId)
  123. bs, err := c.doPut(ctx, url, bm)
  124. if err != nil {
  125. return nil, err
  126. }
  127. rsp = new(ReportRsp)
  128. err = json.Unmarshal(bs, rsp)
  129. if err != nil {
  130. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  131. }
  132. return rsp, nil
  133. }
  134. // 重推报关(非拆单)
  135. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_resend_single
  136. func (c *Client) ResendReportSingle(ctx context.Context, partnerReportId string) (rsp *ReportRsp, err error) {
  137. if partnerReportId == gopay.NULL {
  138. return nil, fmt.Errorf("partnerReportId is empty")
  139. }
  140. url := fmt.Sprintf(reSendReportSingle, c.PartnerCode, partnerReportId)
  141. bs, err := c.doPut(ctx, url, nil)
  142. if err != nil {
  143. return nil, err
  144. }
  145. rsp = new(ReportRsp)
  146. err = json.Unmarshal(bs, rsp)
  147. if err != nil {
  148. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  149. }
  150. return rsp, nil
  151. }
  152. // 报关单子单重推
  153. // 文档:https://payjp.lakala.com/docs/cn/#api-Custom-declare_resend_separate
  154. func (c *Client) ResendReportSeparate(ctx context.Context, partnerReportId, partnerSubReportId string) (rsp *ReportRsp, err error) {
  155. if partnerReportId == gopay.NULL {
  156. return nil, fmt.Errorf("partnerReportId is empty")
  157. }
  158. if partnerSubReportId == gopay.NULL {
  159. return nil, fmt.Errorf("partnerSubReportId is empty")
  160. }
  161. url := fmt.Sprintf(modifyReportSeparate, c.PartnerCode, partnerReportId, partnerSubReportId)
  162. bs, err := c.doPut(ctx, url, nil)
  163. if err != nil {
  164. return nil, err
  165. }
  166. rsp = new(ReportRsp)
  167. err = json.Unmarshal(bs, rsp)
  168. if err != nil {
  169. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  170. }
  171. return rsp, nil
  172. }