Paypal SDK将计费计划设置为活动



我是PayPal SDK的新手,我正在尝试创建一个计费计划并将其状态更改为ACTIVE。我已经尝试了SDK教程中的一些示例Java代码,但我无法使这些代码正常工作。状态保持为"已创建"。我尝试过的代码可以在下面找到。

缺少/错了什么?

运行代码的输出是

Created plan with id = P-1MT21723NA428154CRJGOTXQ
Plan state = CREATED
Plan state = CREATED

问候/套索

// Build Plan object
Plan plan = new Plan();
plan.setName("T-Shirt of the Month Club Plan");
plan.setDescription("Template creation.");
plan.setType("fixed");
// Payment_definitions
PaymentDefinition paymentDefinition = new PaymentDefinition();
paymentDefinition.setName("Regular Payments");
paymentDefinition.setType("REGULAR");
paymentDefinition.setFrequency("MONTH");
paymentDefinition.setFrequencyInterval("1");
paymentDefinition.setCycles("12");
// Currency
Currency currency = new Currency();
currency.setCurrency("USD");
currency.setValue("20");
paymentDefinition.setAmount(currency);
// Charge_models
ChargeModels chargeModels = new ChargeModels();
chargeModels.setType("SHIPPING");
chargeModels.setAmount(currency);
List<ChargeModels> chargeModelsList = new ArrayList<>();
chargeModelsList.add(chargeModels);
paymentDefinition.setChargeModels(chargeModelsList);
// Payment_definition
List<PaymentDefinition> paymentDefinitionList = new ArrayList<>();
paymentDefinitionList.add(paymentDefinition);
plan.setPaymentDefinitions(paymentDefinitionList);
// Merchant_preferences
MerchantPreferences merchantPreferences = new MerchantPreferences();
merchantPreferences.setSetupFee(currency);
merchantPreferences.setCancelUrl("https://example.com/cancel");
merchantPreferences.setReturnUrl("https://example.com/return");
merchantPreferences.setMaxFailAttempts("0");
merchantPreferences.setAutoBillAmount("YES");
merchantPreferences.setInitialFailAmountAction("CONTINUE");
plan.setMerchantPreferences(merchantPreferences);
// Create payment
Plan createdPlan = plan.create(apiContext);
System.out.println("Created plan with id = " + createdPlan.getId());
System.out.println("Plan state = " + createdPlan.getState());
// Set up plan activate PATCH request
List<Patch> patchRequestList = new ArrayList<>();
Map<String, String> value = new HashMap<>();
value.put("state", "ACTIVE");
// Create update object to activate plan
Patch patch = new Patch();
patch.setPath("/");
patch.setValue(value);
patch.setOp("replace");
patchRequestList.add(patch);
// Activate plan
createdPlan.update(apiContext, patchRequestList);
System.out.println("Plan state = " + createdPlan.getState());

明白了!

我不得不执行Plan.get(context,createdPlan.getId(((;了解计划的最新情况。