bra*_*ice 2 c# paypal paypal-subscriptions paypal-sandbox
我有以下代码来创建结算方案
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);
Run Code Online (Sandbox Code Playgroud)
我尝试使用以下代码激活计划
Patch xPatch = new Patch();
xPatch.op = "replace";
xPatch.path = "state";
xPatch.value = "ACTIVE";
PatchRequest yPatch = new PatchRequest();
yPatch.Add(xPatch);
cPLan.Update(apiContext, yPatch);
Run Code Online (Sandbox Code Playgroud)
然而,这给了我一个(400)错误请求.{"name":"BUSINESS_VALIDATION_ERROR","details":[{"field":"validation_error","issue":"提供的路径无效."}],"message":"验证错误.","information_link": " https://developer.paypal.com/webapps/developer/docs/api/#BUSINESS_VALIDATION_ERROR","debug_id":"01f0eb9aaaea0 "}
任何人都可以教我如何做错我/
当更新计划,你需要将设置Patch.value属性为一个新的Plan包含您想更换领域(设置对象state要ACTIVE在这种情况下).此外,您需要将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);
Run Code Online (Sandbox Code Playgroud)