public static void runExample( DfpServices dfpServices, DfpSession session, long rateCardId, long productTemplateId) throws Exception { // Get the BaseRateService. BaseRateServiceInterface baseRateService = dfpServices.get(session, BaseRateServiceInterface.class); // Create a base rate for a product template. ProductTemplateBaseRate productTemplateBaseRate = new ProductTemplateBaseRate(); // Set the rate card ID that the product template base rate belongs to. productTemplateBaseRate.setRateCardId(rateCardId); // Set the product template the base rate will be applied to. productTemplateBaseRate.setProductTemplateId(productTemplateId); // Create a rate worth $2 and set that on the product template base rate. Money rate = new Money(); rate.setCurrencyCode("USD"); rate.setMicroAmount(2000000L); productTemplateBaseRate.setRate(rate); // Create the product template base rate on the server. BaseRate[] baseRates = baseRateService.createBaseRates(new BaseRate[] {productTemplateBaseRate}); for (BaseRate createdBaseRate : baseRates) { System.out.printf( "A product template base rate with ID %d and rate %.4f %s " + "was created.%n", createdBaseRate.getId(), (((ProductTemplateBaseRate) createdBaseRate).getRate().getMicroAmount() / 1000000f), ((ProductTemplateBaseRate) createdBaseRate).getRate().getCurrencyCode()); } }
public static void runExample( DfpServices dfpServices, DfpSession session, long reconciliationReportId, long lineItemId) throws Exception { // Get the ReconciliationLineItemReportService. ReconciliationLineItemReportServiceInterface reconciliationLineItemReportService = dfpServices.get(session, ReconciliationLineItemReportServiceInterface.class); // Create a statement to select a reconciliation line item report. StatementBuilder statementBuilder = new StatementBuilder() .where("reconciliationReportId = :reconciliationReportId AND lineItemId = :lineItemId") .orderBy("lineItemId ASC") .limit(1) .withBindVariableValue("reconciliationReportId", reconciliationReportId) .withBindVariableValue("lineItemId", lineItemId); // Get reconciliation line item reports by statement. ReconciliationLineItemReportPage page = reconciliationLineItemReportService.getReconciliationLineItemReportsByStatement( statementBuilder.toStatement()); ReconciliationLineItemReport lineItemReport = Iterables.getOnlyElement(Arrays.asList(page.getResults())); // Add $10 to the computed billable revenue as an override. Money billableRevenue; if (PricingModel.NET.equals(lineItemReport.getPricingModel())) { billableRevenue = lineItemReport.getNetBillableRevenue(); } else { billableRevenue = lineItemReport.getGrossBillableRevenue(); } billableRevenue.setMicroAmount(billableRevenue.getMicroAmount() + 10000000L); BillableRevenueOverrides billableRevenueOverrides = new BillableRevenueOverrides(); billableRevenueOverrides.setBillableRevenueOverride(billableRevenue); lineItemReport.setBillableRevenueOverrides(billableRevenueOverrides); ReconciliationLineItemReport[] updatedLineItemReports = reconciliationLineItemReportService.updateReconciliationLineItemReports( new ReconciliationLineItemReport[] {lineItemReport}); for (ReconciliationLineItemReport updatedLineItemReport : updatedLineItemReports) { System.out.printf( "Reconciliation line item report for line item ID \"%d\" was " + "updated, with net billable revenue \"%.2f\" and reconciled volume \"%d\".%n", updatedLineItemReport.getLineItemId(), updatedLineItemReport.getNetBillableRevenue().getMicroAmount() / 1000000f, updatedLineItemReport.getReconciledVolume()); } }