pay_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package pendant
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strconv"
  6. "testing"
  7. "github.com/smartystreets/goconvey/convey"
  8. "gopkg.in/h2non/gock.v1"
  9. )
  10. func TestPendantPayBcoin(t *testing.T) {
  11. convey.Convey("PayBcoin", t, func(ctx convey.C) {
  12. var (
  13. params = url.Values{}
  14. ip = ""
  15. _subject = "头像挂件"
  16. )
  17. params.Set("mid", "109228")
  18. params.Set("out_trade_no", "2016050614625209018624230766")
  19. params.Set("money", strconv.FormatFloat(2, 'f', 2, 64))
  20. params.Set("subject", _subject)
  21. params.Set("remark", fmt.Sprintf(_subject+" - %s(%s个月)", strconv.FormatInt(4, 10), strconv.FormatInt(1234, 10)))
  22. params.Set("merchant_id", d.c.PayInfo.MerchantID)
  23. params.Set("merchant_product_id", d.c.PayInfo.MerchantProductID)
  24. params.Set("platform_type", "3")
  25. params.Set("iap_pay_type", "0")
  26. params.Set("notify_url", d.c.PayInfo.CallBackURL)
  27. ctx.Convey("When everything goes positive", func(ctx convey.C) {
  28. defer gock.OffAll()
  29. httpMock("Post", d.payURL).Reply(0).JSON(`{"code":0}`)
  30. orderNo, casherURL, err := d.PayBcoin(c, params, ip)
  31. ctx.Convey("Then err should be nil.orderNo,casherURL should not be nil.", func(ctx convey.C) {
  32. ctx.So(err, convey.ShouldBeNil)
  33. ctx.So(casherURL, convey.ShouldNotBeNil)
  34. ctx.So(orderNo, convey.ShouldNotBeNil)
  35. })
  36. })
  37. })
  38. }