蛋蛋星球-制度模式
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

77 líneas
2.1 KiB

  1. package lakala
  2. import (
  3. "context"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "github.com/go-pay/gopay"
  8. )
  9. // 创建H5支付单
  10. // 文档:https://payjp.lakala.com/docs/cn/#api-MobileH5-NewMobileH5Pay
  11. func (c *Client) CreateH5PayOrder(ctx context.Context, orderId string, bm gopay.BodyMap) (rsp *PaymentRsp, err error) {
  12. if orderId == gopay.NULL {
  13. return nil, fmt.Errorf("orderId is empty")
  14. }
  15. if err = bm.CheckEmptyError("description", "price", "channel"); err != nil {
  16. return nil, err
  17. }
  18. url := fmt.Sprintf(newH5Order, c.PartnerCode, orderId)
  19. bs, err := c.doPut(ctx, url, bm)
  20. if err != nil {
  21. return nil, err
  22. }
  23. rsp = new(PaymentRsp)
  24. err = json.Unmarshal(bs, rsp)
  25. if err != nil {
  26. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  27. }
  28. return rsp, nil
  29. }
  30. // H5支付跳转页
  31. // 文档:https://payjp.lakala.com/docs/cn/#api-MobileH5-MobileH5Pay
  32. func (c *Client) H5Pay(ctx context.Context, orderId, redirect string) (rsp *ErrorCode, err error) {
  33. if orderId == gopay.NULL {
  34. return nil, errors.New("order_id is empty")
  35. }
  36. if redirect == gopay.NULL {
  37. return nil, fmt.Errorf("redirect is empty")
  38. }
  39. url := fmt.Sprintf(h5Pay, c.PartnerCode, orderId)
  40. bs, err := c.doGet(ctx, url, "redirect="+redirect)
  41. if err != nil {
  42. return nil, err
  43. }
  44. rsp = new(ErrorCode)
  45. err = json.Unmarshal(bs, rsp)
  46. if err != nil {
  47. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  48. }
  49. return rsp, nil
  50. }
  51. // H5支付跳转页(Alipay+)
  52. // 文档:https://payjp.lakala.com/docs/cn/#api-MobileH5-MobileH5PayAlipayPlus
  53. func (c *Client) H5AlipayPlusPay(ctx context.Context, orderId, redirect string) (rsp *ErrorCode, err error) {
  54. if orderId == gopay.NULL {
  55. return nil, errors.New("order_id is empty")
  56. }
  57. if redirect == gopay.NULL {
  58. return nil, fmt.Errorf("redirect is empty")
  59. }
  60. url := fmt.Sprintf(alipayPlusH5Pay, c.PartnerCode, orderId)
  61. bs, err := c.doGet(ctx, url, "redirect="+redirect)
  62. if err != nil {
  63. return nil, err
  64. }
  65. rsp = new(ErrorCode)
  66. err = json.Unmarshal(bs, rsp)
  67. if err != nil {
  68. return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
  69. }
  70. return rsp, nil
  71. }