Paypal REST API SDK - 在 C# 中激活计费计划
Paypal REST API SDK - Activating a billing plan in C#
我有以下代码来创建计费计划
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);
我尝试使用以下代码激活计划
Patch xPatch = new Patch();
xPatch.op = "replace";
xPatch.path = "state";
xPatch.value = "ACTIVE";
PatchRequest yPatch = new PatchRequest();
yPatch.Add(xPatch);
cPLan.Update(apiContext, yPatch);
但是这给了我一个 (400) Bad Request。
{"name":"BUSINESS_VALIDATION_ERROR","details":[{"field":"validation_error","issue":"Invalid Path provided."}],"message":"Validation Error.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_VALIDATION_ERROR","debug_id":"01f0eb9aaaea0"}
谁能告诉我我在这方面做错了什么/
更新计划时,您需要将 Patch.value
属性 设置为包含您要替换的字段的新 Plan
对象(设置 [=在本例中为 13=] 到 ACTIVE
)。此外,您需要将 Patch.path
属性 设置为 "/"
.
在您的代码中,执行以下操作:
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
我有以下代码来创建计费计划
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);
我尝试使用以下代码激活计划
Patch xPatch = new Patch();
xPatch.op = "replace";
xPatch.path = "state";
xPatch.value = "ACTIVE";
PatchRequest yPatch = new PatchRequest();
yPatch.Add(xPatch);
cPLan.Update(apiContext, yPatch);
但是这给了我一个 (400) Bad Request。 {"name":"BUSINESS_VALIDATION_ERROR","details":[{"field":"validation_error","issue":"Invalid Path provided."}],"message":"Validation Error.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_VALIDATION_ERROR","debug_id":"01f0eb9aaaea0"}
谁能告诉我我在这方面做错了什么/
更新计划时,您需要将 Patch.value
属性 设置为包含您要替换的字段的新 Plan
对象(设置 [=在本例中为 13=] 到 ACTIVE
)。此外,您需要将 Patch.path
属性 设置为 "/"
.
在您的代码中,执行以下操作:
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