蛋蛋星球-制度模式
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

76 行
2.1 KiB

  1. package lakala
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/go-pay/gopay"
  7. )
  8. // 创建QRCode支付单
  9. // 文档:https://payjp.lakala.com/docs/cn/#api-QRCode-NewQRCode
  10. func (c *Client) CreateQRCodeOrder(ctx context.Context, orderId string, bm gopay.BodyMap) (rsp *PaymentRsp, err error) {
  11. if orderId == gopay.NULL {
  12. return nil, fmt.Errorf("orderId is empty")
  13. }
  14. if err = bm.CheckEmptyError("description", "price", "channel"); err != nil {
  15. return nil, err
  16. }
  17. url := fmt.Sprintf(newQrcodeOrder, c.PartnerCode, orderId)
  18. bs, err := c.doPut(ctx, url, bm)
  19. if err != nil {
  20. return nil, err
  21. }
  22. rsp = new(PaymentRsp)
  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. // 创建Native QRCode支付单
  30. // 文档:https://payjp.lakala.com/docs/cn/#api-QRCode-NativeQRCode
  31. func (c *Client) CreateNativeQRCodeOrder(ctx context.Context, orderId string, bm gopay.BodyMap) (rsp *PaymentRsp, err error) {
  32. if orderId == gopay.NULL {
  33. return nil, fmt.Errorf("orderId is empty")
  34. }
  35. if err = bm.CheckEmptyError("description", "price", "channel"); err != nil {
  36. return nil, err
  37. }
  38. url := fmt.Sprintf(newNativeQrcodeOrder, c.PartnerCode, orderId)
  39. bs, err := c.doPut(ctx, url, bm)
  40. if err != nil {
  41. return nil, err
  42. }
  43. rsp = new(PaymentRsp)
  44. err = json.Unmarshal(bs, rsp)
  45. if err != nil {
  46. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  47. }
  48. return rsp, nil
  49. }
  50. // QRCode支付跳转页
  51. // 文档:https://payjp.lakala.com/docs/cn/#api-QRCode-QRCodePay
  52. func (c *Client) QRCodePay(ctx context.Context, orderId, redirect string) (rsp *ErrorCode, err error) {
  53. if orderId == gopay.NULL {
  54. return nil, fmt.Errorf("orderId is empty")
  55. }
  56. if redirect == gopay.NULL {
  57. return nil, fmt.Errorf("redirect is empty")
  58. }
  59. url := fmt.Sprintf(qrcodePay, c.PartnerCode, orderId)
  60. bs, err := c.doGet(ctx, url, "redirect="+redirect)
  61. if err != nil {
  62. return nil, err
  63. }
  64. rsp = new(ErrorCode)
  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. }