Search in sources :

Example 1 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestAdmin method triggerInvoiceGenerationForParkedAccounts.

private Response triggerInvoiceGenerationForParkedAccounts(final int limit) throws KillBillClientException {
    final String uri = "/1.0/kb/admin/invoices";
    final RequestOptions requestOptions = RequestOptions.builder().withQueryParams(ImmutableMultimap.<String, String>of(JaxrsResource.QUERY_SEARCH_LIMIT, String.valueOf(limit))).withCreatedBy(createdBy).withReason(reason).withComment(comment).build();
    for (int i = 0; i < limit; i++) {
        callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_DELETION, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    }
    final Response response = killBillHttpClient.doPost(uri, null, requestOptions);
    callbackServlet.assertListenerStatus();
    return response;
}
Also used : Response(org.asynchttpclient.Response) RequestOptions(org.killbill.billing.client.RequestOptions)

Example 2 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestPayment method testDeletePaymentMethodWithAutoPayOff.

@Test(groups = "slow")
public void testDeletePaymentMethodWithAutoPayOff() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).build();
    paymentMethodApi.deletePaymentMethod(paymentMethodId, true, false, NULL_PLUGIN_PROPERTIES, inputOptions);
    Tags accountTags = accountApi.getAccountTags(account.getAccountId(), inputOptions);
    Assert.assertNotNull(accountTags);
    Assert.assertEquals(accountTags.get(0).getTagDefinitionName(), "AUTO_PAY_OFF");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) RequestOptions(org.killbill.billing.client.RequestOptions) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 3 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
    // Getting Invoice #2 (first after Trial period)
    UUID failedInvoiceId = accountApi.getInvoicesForAccount(account.getAccountId(), null, null, null, RequestOptions.empty()).get(1).getInvoiceId();
    HashMultimap<String, String> queryParams = HashMultimap.create();
    queryParams.put("withAttempts", "true");
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
    InvoicePayments invoicePayments = invoiceApi.getPaymentsForInvoice(failedInvoiceId, inputOptions);
    Assert.assertEquals(invoicePayments.get(0).getTargetInvoiceId(), failedInvoiceId);
    Assert.assertNotNull(invoicePayments.get(0).getPaymentAttempts());
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().size(), 2);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
    // Remove the future notification and check SCHEDULED does not appear any longer
    paymentApi.cancelScheduledPaymentTransactionByExternalKey(invoicePayments.get(0).getPaymentAttempts().get(1).getTransactionExternalKey(), inputOptions);
    invoicePayments = invoiceApi.getPaymentsForInvoice(failedInvoiceId, inputOptions);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().size(), 1);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) RequestOptions(org.killbill.billing.client.RequestOptions) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 4 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetPayments.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPayments() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
    HashMultimap<String, String> queryParams = HashMultimap.create();
    queryParams.put("withAttempts", "true");
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
    Payments payments = paymentApi.getPayments(0L, 100L, null, false, true, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, inputOptions);
    Assert.assertNotNull(payments.get(0).getPaymentAttempts());
    Assert.assertEquals(payments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(payments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
}
Also used : RequestOptions(org.killbill.billing.client.RequestOptions) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Payments(org.killbill.billing.client.model.Payments) Test(org.testng.annotations.Test)

Example 5 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestPaymentPluginProperties method testInternal.

private void testInternal(final Map<String, String> queryProperties, final List<PluginProperty> bodyProperties, final List<org.killbill.billing.payment.api.PluginProperty> expectProperties) throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    TransactionType transactionType = TransactionType.AUTHORIZE;
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, amount, pluginProperties);
    mockPaymentControlProviderPlugin.setExpectPluginProperties(expectProperties);
    // Complete operation: first, only specify the payment id
    final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
    completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentId.setProperties(bodyProperties);
    final RequestOptions basicRequestOptions = requestOptions;
    final Multimap<String, String> params = LinkedListMultimap.create(basicRequestOptions.getQueryParams());
    params.putAll(KillBillHttpClient.CONTROL_PLUGIN_NAME, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME));
    final RequestOptions requestOptionsWithParams = basicRequestOptions.extend().withQueryParams(params).build();
    paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentId, NULL_PLUGIN_NAMES, queryProperties, requestOptionsWithParams);
    // Capture the payment
    final PaymentTransaction captureTransaction = new PaymentTransaction();
    captureTransaction.setPaymentId(initialPayment.getPaymentId());
    captureTransaction.setProperties(bodyProperties);
    captureTransaction.setAmount(BigDecimal.TEN);
    captureTransaction.setCurrency(account.getCurrency());
    paymentApi.captureAuthorization(initialPayment.getPaymentId(), captureTransaction, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME), queryProperties, requestOptions);
    // Refund the payment
    final PaymentTransaction refundTransaction = new PaymentTransaction();
    refundTransaction.setPaymentId(initialPayment.getPaymentId());
    refundTransaction.setProperties(bodyProperties);
    refundTransaction.setAmount(BigDecimal.TEN);
    refundTransaction.setCurrency(account.getCurrency());
    paymentApi.refundPayment(initialPayment.getPaymentId(), refundTransaction, ImmutableList.<String>of(PluginPropertiesVerificator.PLUGIN_NAME), queryProperties, requestOptions);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.gen.Payment) RequestOptions(org.killbill.billing.client.RequestOptions) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal)

Aggregations

RequestOptions (org.killbill.billing.client.RequestOptions)12 Test (org.testng.annotations.Test)10 Account (org.killbill.billing.client.model.gen.Account)8 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)5 Payments (org.killbill.billing.client.model.Payments)4 UUID (java.util.UUID)3 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)3 KillBillClientException (org.killbill.billing.client.KillBillClientException)2 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)2 Payment (org.killbill.billing.client.model.gen.Payment)2 BigDecimal (java.math.BigDecimal)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Response (org.asynchttpclient.Response)1 Invoices (org.killbill.billing.client.model.Invoices)1 Tags (org.killbill.billing.client.model.Tags)1 AuditLog (org.killbill.billing.client.model.gen.AuditLog)1 Invoice (org.killbill.billing.client.model.gen.Invoice)1 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)1 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)1 Tag (org.killbill.billing.client.model.gen.Tag)1