C# Paypal REST API SDK-在C中激活计费计划#

C# Paypal REST API SDK-在C中激活计费计划#,c#,paypal,paypal-sandbox,paypal-subscriptions,C#,Paypal,Paypal Sandbox,Paypal Subscriptions,我有以下代码来创建计费计划 string iClientID = "xxxxxx"; string iSecret = "yyyyyy"; Dictionary<string, string> sdkConfig = new Dictionary<string, string>(); sdkConfig.Add("mode", "sandbox"); string accessToken = new OA

我有以下代码来创建计费计划

 string iClientID = "xxxxxx";
        string iSecret = "yyyyyy";

        Dictionary<string, string> sdkConfig = new Dictionary<string, string>();
        sdkConfig.Add("mode", "sandbox");
        string accessToken = new OAuthTokenCredential(iClientID, iSecret, sdkConfig).GetAccessToken();
    APIContext apiContext = new APIContext(accessToken);
    apiContext.Config = sdkConfig;

    Plan xPlan = new Plan();
    xPlan.name = "Billing Plan OneA";
    xPlan.description = "Our first billing plan for testing";
    xPlan.type = "INFINITE";

    PaymentDefinition xPDef = new PaymentDefinition();
    xPDef.name = "Payment Def One";
    xPDef.type = "REGULAR";
    xPDef.frequency_interval = "1";
    xPDef.frequency = "MONTH";
    xPDef.cycles = "0";

    MerchantPreferences xPrefs = new MerchantPreferences();
    xPrefs.cancel_url = "http://learnoogle.com";
    xPrefs.return_url = "http://learnoogle.com?success";


    Currency xPCUrr = new Currency();
    xPCUrr.currency = "USD";
    xPCUrr.value = "25.00";

    xPDef.amount = xPCUrr;

    List<PaymentDefinition> xDeffs = new List<PaymentDefinition>();
    xDeffs.Add(xPDef);

    xPlan.payment_definitions = xDeffs;
    xPlan.merchant_preferences = xPrefs;
        Plan cPLan = xPlan.Create(apiContext);
然而,这给了我一个(400)糟糕的要求。 {“name”:“BUSINESS_VALIDATION_ERROR”,“details”:[{“field”:“VALIDATION_ERROR”,“issue”:“提供的路径无效”。}],“message”:“VALIDATION ERROR.”,“information_link”:“debug_id”:“01F0EB9AAEA0”}


有人能告诉我我在这方面做错了什么吗?

更新计划时,您需要将
Patch.value
属性设置为一个新的
计划
对象,该对象包含要替换的字段(在这种情况下,将
状态
设置为
活动
)。此外,还需要将
Patch.path
属性设置为just
“/”

在代码中,执行以下操作:

Patch xPatch = new Patch();
xPatch.op = "replace";
xPatch.path = "/";
xPatch.value = new Plan() { state = "ACTIVE" };

PatchRequest yPatch = new PatchRequest();
yPatch.Add(xPatch);

cPLan.Update(apiContext, yPatch);

自提交批准的答案后,代码似乎已更改。现在应该是这样的:

var client = new PayPalHttpClient(environment);
JsonPatch<Plan> xPatch = new JsonPatch<Plan>();
xPatch.op = "replace";
xPatch.path = "/";
xPatch.value = new Plan() { state = "ACTIVE" };

PlanUpdateRequest<Plan> yPatch = new PlanUpdateRequest<Plan>(planId);
yPatch.RequestBody(new List<JsonPatch<Plan>>() { patch });

BraintreeHttp.HttpResponse response = client.Execute(yPatch).Result; // or await this
var-client=新的PayPalHttpClient(环境);
JsonPatch xPatch=新的JsonPatch();
xPatch.op=“替换”;
xPatch.path=“/”;
xPatch.value=新计划(){state=“ACTIVE”};
PlanUpdateRequest yPatch=新的PlanUpdateRequest(planId);
RequestBody(新列表(){patch});
BraintreeHttp.HttpResponse response=client.Execute(yPatch.Result;//或者等待这个

谢谢-paypal dev docs没有明确说明这一点-我发现我可以使用Newtonsoft将json字符串解析为json对象,并执行相同的操作。
var client = new PayPalHttpClient(environment);
JsonPatch<Plan> xPatch = new JsonPatch<Plan>();
xPatch.op = "replace";
xPatch.path = "/";
xPatch.value = new Plan() { state = "ACTIVE" };

PlanUpdateRequest<Plan> yPatch = new PlanUpdateRequest<Plan>(planId);
yPatch.RequestBody(new List<JsonPatch<Plan>>() { patch });

BraintreeHttp.HttpResponse response = client.Execute(yPatch).Result; // or await this