资源在Go中创建Paypal订阅计划时未发现错误



我正在使用Paypal SDK for Go创建一个计划,我得到错误:

Request: GET https://api.sandbox.paypal.com/v1/payments/billing-plans?page=1&page_size=5&status=ACTIVE&total_required=no. Data: 
Response: HTTP/1.1 204 No Content
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Date: Mon, 01 Mar 2021 14:51:21 GMT
Paypal-Debug-Id: 5ff2ab4feb8b9

(0x133dee0,0xc0001000e0)Request: POST https://api.sandbox.paypal.com/v1/billing/plans. Data: 
Response: HTTP/1.1 404 Not Found
Content-Length: 329
Cache-Control: max-age=0, no-cache, no-store, must-revalidate
Content-Type: application/json
Date: Mon, 01 Mar 2021 14:51:21 GMT
Paypal-Debug-Id: 85f6b9f24b80f
{"name":"RESOURCE_NOT_FOUND","message":"The specified resource does not exist.","debug_id":"85f6b9f24b80f","details":[{"issue":"INVALID_RESOURCE_ID","description":"Invalid product id"}],"links":[{"href":"https://developer.paypal.com/docs/api/v1/billing/subscriptions#RESOURCE_NOT_FOUND","rel":"information_link","method":"GET"}]}

我使用的代码是:

package main
import (
"context"
"os"
"github.com/plutov/paypal/v4"
)
func main() {
c, err := paypal.NewClient(
"",
"",
paypal.APIBaseSandBox)
if err != nil {
print(err)
}
c.SetLog(os.Stdout) // Set log to terminal stdout
//print(c)
accessToken, err := c.GetAccessToken(context.Background())
print(accessToken)
print("n=======================================n")
listParams := paypal.ListParams{
Page:          "1",
PageSize:      "5",
TotalRequired: "no",
}
billingPlan := paypal.BillingPlanListParams{
ListParams: listParams,
Status:     "ACTIVE",
}
_, er := c.ListBillingPlans(context.Background(), billingPlan)
if er != nil {
print(er)
}
price := paypal.Money{
Currency: "USD",
Value:    "10",
}
scheme := paypal.PricingScheme{
FixedPrice: price,
}
frequency := paypal.Frequency{
IntervalUnit:  paypal.IntervalUnitMonth,
IntervalCount: 1,
}

newPlan := paypal.SubscriptionPlan{
ID:          "PayPal12949",
ProductId:   "AX12339",
Name:        "BEGINNERS_PLAN",
Status:      paypal.SubscriptionPlanStatusActive,
Description: "This plan is for beginners",
BillingCycles: []paypal.BillingCycle{
{
PricingScheme: scheme,
Frequency:     frequency,
TenureType:    paypal.TenureTypeRegular,
Sequence:      1,
TotalCycles:   3,
},
},
PaymentPreferences: &paypal.PaymentPreferences{
AutoBillOutstanding: false,
SetupFee: &paypal.Money{
Currency: "USD",
Value:    "5",
},
},
}
c.CreateSubscriptionPlan(context.Background(), newPlan)

}

该SDK与当前版本的PayPal订阅不兼容。

PayPal订阅不支持SDK;直接调用API

(你也可以尝试调整SDK函数来实现当前订阅API,如果你真的想)

相关内容