在 Zuora 用户界面中,我可以使用方便的“预览”按钮预览订阅。我想使用 Zuora SOAP API 执行相同的操作,以便我可以预览即将发出的发票并编写一些测试。
到目前为止,我的理论是创建一个空Amendment
的PreviewOptions.enablePreviewMode=true
来获取预览发票的结果。
相关 SOAP 文档:
这部分工作,但它返回了一个InvoiceData
对象,但预计会有两个。
public List<InvoiceData> getInvoicePreview(String subscriptionId){
ID id = new ID();
id.setID(subscriptionId);
PreviewOptions previewOptions = new PreviewOptions();
previewOptions.setEnablePreviewMode(true);
previewOptions.setPreviewThroughTermEnd(true);
Calendar forever = new DateTime().plusDays(1000).toCalendar(Locale.getDefault());
// A null amendment
Amendment amendment = new Amendment();
amendment.setName("Draft amendment for preview");
amendment.setStatus("Draft");
amendment.setContractEffectiveDate(forever);
amendment.setSubscriptionId(id);
amendment.setType("TermsAndConditions");
AmendOptions amendOptions = new AmendOptions();
AmendRequest amendRequest = new AmendRequest();
amendRequest.setAmendments(new Amendment[]{amendment});
amendRequest.setAmendOptions(amendOptions);
amendRequest.setPreviewOptions(previewOptions);
Amend amend = new Amend();
amend.setRequests(new AmendRequest[]{amendRequest});
AmendResponse amendResults;
try {
ZuoraCredentials creds = credentialProvider.get();
ZuoraServiceStub stub = new ZuoraServiceStub(creds.zuoraApiEndpoint);
Login login = new Login();
login.setUsername(creds.zuoraApiUser);
login.setPassword(creds.zuoraApiPassword);
LoginResponse loginResponse = stub.login(login);
String session = loginResponse.getResult().getSession();
SessionHeader sessionHeader = new SessionHeader();
sessionHeader.setSession(session);
amendResults = stub.amend(amend, sessionHeader);
} catch (RemoteException e) {
throw new RuntimeException("Error executing Zuora API.", e);
} catch (UnexpectedErrorFault e) {
throw new RuntimeException("Error executing Zuora API.", e);
} catch (LoginFault e) {
throw new RuntimeException("Error executing Zuora API.", e);
}
AmendResult[] amendResult = amendResults.getResults();
printOut(amendResult);
return new ArrayList<InvoiceData>(Arrays.asList(amendResult[0].getInvoiceDatas()));
}
这是来自 Zuora UI 的数据的样子