蛋蛋星球-制度模式
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

112 rindas
3.4 KiB

  1. package saobei
  2. // 支付2.0接口
  3. import (
  4. "context"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/go-pay/gopay"
  8. )
  9. // MiniPay 小程序支付接口 https://help.lcsw.cn/xrmpic/tisnldchblgxohfl/rinsc3#title-node17
  10. func (c *Client) MiniPay(ctx context.Context, bm gopay.BodyMap) (rsp *MiniPayRsp, err error) {
  11. err = bm.CheckEmptyError("pay_type", "terminal_ip", "terminal_trace", "terminal_time", "total_fee", "sub_appid", "open_id")
  12. if err != nil {
  13. return nil, err
  14. }
  15. var bs []byte
  16. if bs, err = c.doPost(ctx, miniPayPath, bm); err != nil {
  17. return nil, err
  18. }
  19. rsp = new(MiniPayRsp)
  20. if err = json.Unmarshal(bs, rsp); err != nil {
  21. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  22. }
  23. if err := bizErrCheck(rsp.RspBase); err != nil {
  24. return nil, err
  25. }
  26. return rsp, c.verifySign(bs)
  27. }
  28. // BarcodePay 付款码支付(扫码支付) https://help.lcsw.cn/xrmpic/tisnldchblgxohfl/rinsc3#title-node14
  29. func (c *Client) BarcodePay(ctx context.Context, bm gopay.BodyMap) (rsp *BarcodePayRsp, err error) {
  30. err = bm.CheckEmptyError("pay_type", "terminal_ip", "terminal_trace", "terminal_time", "total_fee", "auth_no")
  31. if err != nil {
  32. return nil, err
  33. }
  34. var bs []byte
  35. if bs, err = c.doPost(ctx, barcodePayPath, bm); err != nil {
  36. return nil, err
  37. }
  38. rsp = new(BarcodePayRsp)
  39. if err = json.Unmarshal(bs, rsp); err != nil {
  40. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  41. }
  42. if err := bizErrCheck(rsp.RspBase); err != nil {
  43. return nil, err
  44. }
  45. return rsp, nil
  46. }
  47. // Query 支付查询 https://help.lcsw.cn/xrmpic/tisnldchblgxohfl/rinsc3#title-node18
  48. func (c *Client) Query(ctx context.Context, bm gopay.BodyMap) (rsp *QueryRsp, err error) {
  49. err = bm.CheckEmptyError("pay_type", "terminal_trace", "terminal_time")
  50. if err != nil {
  51. return nil, err
  52. }
  53. var bs []byte
  54. if bs, err = c.doPost(ctx, queryPath, bm); err != nil {
  55. return nil, err
  56. }
  57. rsp = new(QueryRsp)
  58. if err = json.Unmarshal(bs, rsp); err != nil {
  59. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  60. }
  61. if err := bizErrCheck(rsp.RspBase); err != nil {
  62. return nil, err
  63. }
  64. return rsp, c.verifySign(bs)
  65. }
  66. // Refund 退款申请 https://help.lcsw.cn/xrmpic/tisnldchblgxohfl/rinsc3#title-node19
  67. func (c *Client) Refund(ctx context.Context, bm gopay.BodyMap) (rsp *RefundRsp, err error) {
  68. err = bm.CheckEmptyError("pay_type", "terminal_trace", "terminal_time", "refund_fee")
  69. if err != nil {
  70. return nil, err
  71. }
  72. var bs []byte
  73. if bs, err = c.doPost(ctx, refundPath, bm); err != nil {
  74. return nil, err
  75. }
  76. rsp = new(RefundRsp)
  77. if err = json.Unmarshal(bs, rsp); err != nil {
  78. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  79. }
  80. if err := bizErrCheck(rsp.RspBase); err != nil {
  81. return nil, err
  82. }
  83. return rsp, c.verifySign(bs)
  84. }
  85. // QueryRefund 退款订单查询 https://help.lcsw.cn/xrmpic/tisnldchblgxohfl/rinsc3#title-node22
  86. func (c *Client) QueryRefund(ctx context.Context, bm gopay.BodyMap) (rsp *QueryRefundRsp, err error) {
  87. err = bm.CheckEmptyError("pay_type", "terminal_trace", "terminal_time")
  88. if err != nil {
  89. return nil, err
  90. }
  91. var bs []byte
  92. if bs, err = c.doPost(ctx, queryRefundPath, bm); err != nil {
  93. return nil, err
  94. }
  95. rsp = new(QueryRefundRsp)
  96. if err = json.Unmarshal(bs, rsp); err != nil {
  97. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  98. }
  99. if err := bizErrCheck(rsp.RspBase); err != nil {
  100. return nil, err
  101. }
  102. return rsp, c.verifySign(bs)
  103. }