蛋蛋星球-制度模式
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

  1. package paypal
  2. import (
  3. "testing"
  4. "github.com/go-pay/gopay"
  5. "github.com/go-pay/xlog"
  6. )
  7. func TestClient_CreateBillingPlan(t *testing.T) {
  8. var billingCycles []*BillingCycles
  9. var billingCycle = &BillingCycles{
  10. Frequency: &Frequency{
  11. IntervalUnit: "MONTH",
  12. IntervalCount: 1,
  13. },
  14. TenureType: "REGULAR",
  15. Sequence: 1,
  16. TotalCycles: 0,
  17. PricingScheme: &PricingScheme{
  18. FixedPrice: &FixedPrice{
  19. Value: "101",
  20. CurrencyCode: "USD",
  21. },
  22. },
  23. }
  24. billingCycles = append(billingCycles, billingCycle)
  25. // 创建 PayPal 支付订单
  26. bm := make(gopay.BodyMap)
  27. bm.Set("product_id", "PROD-9TH539347F0791830").
  28. Set("name", "gopay").
  29. Set("billing_cycles", billingCycles).
  30. Set("description", "Monthly subscription for premium users").
  31. Set("payment_preferences", &PaymentPreferences{
  32. AutoBillOutstanding: true,
  33. SetupFeeFailureAction: "CONTINUE",
  34. PaymentFailureThreshold: 3,
  35. })
  36. xlog.Debug("bm:", bm.JsonBody())
  37. ppRsp, err := client.CreateBillingPlan(ctx, bm)
  38. if err != nil {
  39. xlog.Error(err)
  40. return
  41. }
  42. if ppRsp.Code != Success {
  43. xlog.Debugf("ppRsp.Code: %+v", ppRsp.Code)
  44. xlog.Debugf("ppRsp.Error: %+v", ppRsp.Error)
  45. xlog.Debugf("ppRsp.ErrorResponse: %+v", ppRsp.ErrorResponse)
  46. return
  47. }
  48. xlog.Debugf("ppRsp.Response: %+v", ppRsp.Response)
  49. for _, v := range ppRsp.Response.Links {
  50. xlog.Debugf("ppRsp.Response.Links: %+v", v)
  51. }
  52. }