蛋蛋星球-制度模式
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

162 righe
4.3 KiB

  1. package paypal
  2. import (
  3. "testing"
  4. "github.com/go-pay/gopay"
  5. "github.com/go-pay/xlog"
  6. )
  7. func TestPaymentAuthorizeDetail(t *testing.T) {
  8. ppRsp, err := client.PaymentAuthorizeDetail(ctx, "4X223967G91314611")
  9. if err != nil {
  10. xlog.Error(err)
  11. return
  12. }
  13. if ppRsp.Code != Success {
  14. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  15. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  16. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  17. return
  18. }
  19. xlog.Debugf("ppRsp.Response: %+v", ppRsp.Response)
  20. for _, v := range ppRsp.Response.Links {
  21. xlog.Debugf("ppRsp.Response.Links: %+v", v)
  22. }
  23. }
  24. func TestPaymentReauthorize(t *testing.T) {
  25. bm := make(gopay.BodyMap)
  26. bm.SetBodyMap("amount", func(bm gopay.BodyMap) {
  27. bm.Set("currency_code", "USD").
  28. Set("value", "10.99")
  29. })
  30. xlog.Debug("bm:", bm.JsonBody())
  31. ppRsp, err := client.PaymentReauthorize(ctx, "4X223967G91314611", bm)
  32. if err != nil {
  33. xlog.Error(err)
  34. return
  35. }
  36. if ppRsp.Code != Success {
  37. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  38. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  39. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  40. return
  41. }
  42. xlog.Debugf("ppRsp.Response: %+v", ppRsp.Response)
  43. for _, v := range ppRsp.Response.Links {
  44. xlog.Debugf("ppRsp.Response.Links: %+v", v)
  45. }
  46. }
  47. func TestPaymentAuthorizeVoid(t *testing.T) {
  48. ppRsp, err := client.PaymentAuthorizeVoid(ctx, "4X223967G91314611")
  49. if err != nil {
  50. xlog.Error(err)
  51. return
  52. }
  53. if ppRsp.Code != Success {
  54. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  55. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  56. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  57. return
  58. }
  59. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  60. }
  61. func TestPaymentAuthorizeCapture(t *testing.T) {
  62. bm := make(gopay.BodyMap)
  63. bm.Set("invoice_id", "INVOICE-123").
  64. Set("final_capture", true).
  65. Set("note_to_payer", "If the ordered color is not available, we will substitute with a different color free of charge.").
  66. Set("soft_descriptor", "Bob's Custom Sweaters").
  67. SetBodyMap("amount", func(bm gopay.BodyMap) {
  68. bm.Set("currency_code", "USD").
  69. Set("value", "10.99")
  70. })
  71. xlog.Debug("bm:", bm.JsonBody())
  72. ppRsp, err := client.PaymentAuthorizeCapture(ctx, "4X223967G91314611", bm)
  73. if err != nil {
  74. xlog.Error(err)
  75. return
  76. }
  77. if ppRsp.Code != Success {
  78. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  79. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  80. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  81. return
  82. }
  83. xlog.Debugf("ppRsp.Response: %+v", ppRsp.Response)
  84. for _, v := range ppRsp.Response.Links {
  85. xlog.Debugf("ppRsp.Response.Links: %+v", v)
  86. }
  87. }
  88. func TestPaymentCaptureDetail(t *testing.T) {
  89. ppRsp, err := client.PaymentCaptureDetail(ctx, "4X223967G91314611")
  90. if err != nil {
  91. xlog.Error(err)
  92. return
  93. }
  94. if ppRsp.Code != Success {
  95. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  96. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  97. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  98. return
  99. }
  100. xlog.Debugf("ppRsp.Response: %+v", ppRsp.Response)
  101. for _, v := range ppRsp.Response.Links {
  102. xlog.Debugf("ppRsp.Response.Links: %+v", v)
  103. }
  104. }
  105. func TestPaymentCaptureRefund(t *testing.T) {
  106. bm := make(gopay.BodyMap)
  107. bm.Set("invoice_id", "INVOICE-123").
  108. Set("note_to_payer", "Defective product").
  109. SetBodyMap("amount", func(bm gopay.BodyMap) {
  110. bm.Set("currency_code", "USD").
  111. Set("value", "10.99")
  112. })
  113. xlog.Debug("bm:", bm.JsonBody())
  114. ppRsp, err := client.PaymentCaptureRefund(ctx, "4X223967G91314611", bm)
  115. if err != nil {
  116. xlog.Error(err)
  117. return
  118. }
  119. if ppRsp.Code != Success {
  120. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  121. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  122. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  123. return
  124. }
  125. xlog.Debugf("ppRsp.Response: %+v", ppRsp.Response)
  126. for _, v := range ppRsp.Response.Links {
  127. xlog.Debugf("ppRsp.Response.Links: %+v", v)
  128. }
  129. }
  130. func TestPaymentRefundDetail(t *testing.T) {
  131. ppRsp, err := client.PaymentRefundDetail(ctx, "4X223967G91314611")
  132. if err != nil {
  133. xlog.Error(err)
  134. return
  135. }
  136. if ppRsp.Code != Success {
  137. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  138. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  139. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  140. return
  141. }
  142. xlog.Debugf("ppRsp.Response: %+v", ppRsp.Response)
  143. for _, v := range ppRsp.Response.Links {
  144. xlog.Debugf("ppRsp.Response.Links: %+v", v)
  145. }
  146. }