use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.
the class TransactionResource method getPaymentByTransactionId.
@TimedResource(name = "getPaymentByTransactionId")
@GET
@Path("/{transactionId:" + UUID_PATTERN + "}/")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Retrieve a payment by transaction id", response = PaymentJson.class)
@ApiResponses(value = { @ApiResponse(code = 404, message = "Payment not found") })
public Response getPaymentByTransactionId(@PathParam("transactionId") final String transactionIdStr, @QueryParam(QUERY_WITH_PLUGIN_INFO) @DefaultValue("false") final Boolean withPluginInfo, @QueryParam(QUERY_WITH_ATTEMPTS) @DefaultValue("false") final Boolean withAttempts, @QueryParam(QUERY_PLUGIN_PROPERTY) final List<String> pluginPropertiesString, @QueryParam(QUERY_AUDIT) @DefaultValue("NONE") final AuditMode auditMode, @javax.ws.rs.core.Context final HttpServletRequest request) throws PaymentApiException {
final Iterable<PluginProperty> pluginProperties = extractPluginProperties(pluginPropertiesString);
final UUID transactionIdId = UUID.fromString(transactionIdStr);
final TenantContext tenantContext = context.createContext(request);
final Payment payment = paymentApi.getPaymentByTransactionId(transactionIdId, withPluginInfo, withAttempts, pluginProperties, tenantContext);
final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(payment.getAccountId(), auditMode.getLevel(), tenantContext);
final PaymentJson result = new PaymentJson(payment, accountAuditLogs);
return Response.status(Response.Status.OK).entity(result).build();
}
use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.
the class DefaultEntitlementService method processEntitlementNotification.
private void processEntitlementNotification(final EntitlementNotificationKey key, final InternalCallContext internalCallContext, final CallContext callContext) {
final Entitlement entitlement;
try {
entitlement = entitlementInternalApi.getEntitlementForId(key.getEntitlementId(), internalCallContext);
} catch (final EntitlementApiException e) {
log.error("Error retrieving entitlementId='{}'", key.getEntitlementId(), e);
return;
}
if (!(entitlement instanceof DefaultEntitlement)) {
log.error("Error retrieving entitlementId='{}', unexpected entitlement className='{}'", key.getEntitlementId(), entitlement.getClass().getName());
return;
}
final EntitlementNotificationKeyAction entitlementNotificationKeyAction = key.getEntitlementNotificationKeyAction();
try {
if (EntitlementNotificationKeyAction.CHANGE.equals(entitlementNotificationKeyAction) || EntitlementNotificationKeyAction.CANCEL.equals(entitlementNotificationKeyAction)) {
blockAddOnsIfRequired(key, (DefaultEntitlement) entitlement, callContext, internalCallContext);
} else if (EntitlementNotificationKeyAction.PAUSE.equals(entitlementNotificationKeyAction)) {
entitlementInternalApi.pause(key.getBundleId(), internalCallContext.toLocalDate(key.getEffectiveDate()), ImmutableList.<PluginProperty>of(), internalCallContext);
} else if (EntitlementNotificationKeyAction.RESUME.equals(entitlementNotificationKeyAction)) {
entitlementInternalApi.resume(key.getBundleId(), internalCallContext.toLocalDate(key.getEffectiveDate()), ImmutableList.<PluginProperty>of(), internalCallContext);
}
} catch (final EntitlementApiException e) {
log.error("Error processing event for entitlementId='{}'", entitlement.getId(), e);
}
}
use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.
the class TestWithTimeZones method testCancellationFrom_PST_to_PDT.
// Same test as previous test but this time going from PST -> PDT (somehow not too interesting in that direction because we start with
// an offset of 8 hours and then go through 7 hours so anyway we would stay in the same day.
@Test(groups = "slow")
public void testCancellationFrom_PST_to_PDT() throws Exception {
clock.setTime(new DateTime("2015-02-01T08:01:01.000Z"));
final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUID.randomUUID().toString().substring(1, 8)).phone(UUID.randomUUID().toString().substring(1, 8)).migrated(false).isNotifiedForInvoices(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).timeZone(tz).build();
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, "Something", ImmutableList.<PlanPhasePriceOverride>of(), null, null, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Cancel the next month specifying just a LocalDate
final LocalDate cancellationDate = new LocalDate("2015-03-01", tz);
entitlement = entitlement.cancelEntitlementWithDate(cancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
// Verify first entitlement is correctly cancelled on the right date
Assert.assertEquals(entitlement.getEffectiveEndDate(), cancellationDate);
// We now move the clock to the date of the cancellation which match the cancellation day from the client point of view
busHandler.pushExpectedEvents(NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.NULL_INVOICE, NextEvent.NULL_INVOICE);
clock.setTime(new DateTime("2015-03-01T08:01:02"));
assertListenerStatus();
// Verify second that there was no repair (so the cancellation did correctly happen on the "2015-12-01"
final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
Assert.assertEquals(invoices.size(), 1);
}
use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.
the class TestWithTimeZones method testCancellationFrom_PDT_to_PST.
// Verify cancellation logic when we exit daylight saving period
@Test(groups = "slow")
public void testCancellationFrom_PDT_to_PST() throws Exception {
// Start with a date in daylight saving period (PDT) and make sure we use a time of 7 hour so that we we reach standard time (PST)
// the next month where the difference is 8 hours, a transformation from DateTime to LocalDate with the account time zone would bring us a day earlier
// (e.g new LocalDate("2015-12-01T07:01:01.000Z", tz) -> "2015-11-30.
clock.setTime(new DateTime("2015-11-01T07:01:01.000Z"));
final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
final AccountData accountData = new MockAccountBuilder().name(UUID.randomUUID().toString().substring(1, 8)).firstNameLength(6).email(UUID.randomUUID().toString().substring(1, 8)).phone(UUID.randomUUID().toString().substring(1, 8)).migrated(false).isNotifiedForInvoices(false).externalKey(UUID.randomUUID().toString().substring(1, 8)).billingCycleDayLocal(1).currency(Currency.USD).paymentMethodId(UUID.randomUUID()).timeZone(tz).build();
final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
accountChecker.checkAccount(account.getId(), accountData, callContext);
busHandler.pushExpectedEvents(NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
final PlanPhaseSpecifier spec = new PlanPhaseSpecifier("Blowdart", BillingPeriod.MONTHLY, "notrial", null);
Entitlement entitlement = entitlementApi.createBaseEntitlement(account.getId(), spec, "Something", ImmutableList.<PlanPhasePriceOverride>of(), null, null, false, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Cancel the next month specifying just a LocalDate
final LocalDate cancellationDate = new LocalDate("2015-12-01", tz);
entitlement = entitlement.cancelEntitlementWithDate(cancellationDate, true, ImmutableList.<PluginProperty>of(), callContext);
assertListenerStatus();
// Verify first entitlement is correctly cancelled on the right date
Assert.assertEquals(entitlement.getEffectiveEndDate(), cancellationDate);
// We now move the clock to the date of the cancellation, which match the cancellation day from the client point of view
busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE, NextEvent.CANCEL, NextEvent.BLOCK, NextEvent.NULL_INVOICE);
clock.setTime(new DateTime("2015-12-01T07:01:02Z"));
assertListenerStatus();
// Verify second that there was no repair (so the cancellation did correctly happen on the "2015-12-01")
final List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
Assert.assertEquals(invoices.size(), 1);
}
use of org.killbill.billing.payment.api.PluginProperty in project killbill by killbill.
the class PaymentMethodJson method toPaymentMethodJson.
public static PaymentMethodJson toPaymentMethodJson(final Account account, final PaymentMethod in, @Nullable final AccountAuditLogs accountAuditLogs) {
final boolean isDefault = account.getPaymentMethodId() != null && account.getPaymentMethodId().equals(in.getId());
final PaymentMethodPlugin pluginDetail = in.getPluginDetail();
PaymentMethodPluginDetailJson pluginDetailJson = null;
if (pluginDetail != null) {
List<PluginPropertyJson> properties = null;
if (pluginDetail.getProperties() != null) {
properties = new ArrayList<PluginPropertyJson>(Collections2.transform(pluginDetail.getProperties(), new Function<PluginProperty, PluginPropertyJson>() {
@Override
public PluginPropertyJson apply(final PluginProperty input) {
return new PluginPropertyJson(input.getKey(), input.getValue() == null ? null : input.getValue().toString(), input.getIsUpdatable());
}
}));
}
pluginDetailJson = new PaymentMethodPluginDetailJson(pluginDetail.getExternalPaymentMethodId(), pluginDetail.isDefaultPaymentMethod(), properties);
}
return new PaymentMethodJson(in.getId().toString(), in.getExternalKey(), account.getId().toString(), isDefault, in.getPluginName(), pluginDetailJson, toAuditLogJson(accountAuditLogs == null ? null : accountAuditLogs.getAuditLogsForPaymentMethod(in.getId())));
}
Aggregations