Paypal SDK将结算计划设置为有效

时间:2018-07-13 09:38:51

标签: java sdk paypal-sandbox billing

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

缺少/错了什么?

运行代码的输出是

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());

1 个答案:

答案 0 :(得分:0)

知道了!

我必须执行Plan.get(context,createdPlan.getId()); 以获得计划的最新状态。