Search in sources :

Example 46 with Account

use of org.killbill.billing.client.model.Account in project killbill by killbill.

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Getting Invoice #2 (first after Trial period)
    UUID failedInvoiceId = killBillClient.getInvoicesForAccount(account.getAccountId(), false, false, 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 = killBillClient.getInvoicePayment(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
    killBillClient.cancelScheduledPaymentTransaction(null, invoicePayments.get(0).getPaymentAttempts().get(1).getTransactionExternalKey(), inputOptions);
    invoicePayments = killBillClient.getInvoicePayment(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.Account) RequestOptions(org.killbill.billing.client.RequestOptions) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 47 with Account

use of org.killbill.billing.client.model.Account in project killbill by killbill.

the class TestPayment method testWithFailedPayment.

@Test(groups = "slow")
public void testWithFailedPayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final PaymentTransaction authTransaction = new PaymentTransaction();
    authTransaction.setAmount(BigDecimal.ONE);
    authTransaction.setCurrency(account.getCurrency());
    authTransaction.setTransactionType(TransactionType.AUTHORIZE.name());
    final Payment payment = killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptions);
    final PaymentTransaction paymentTransaction = payment.getTransactions().get(0);
    assertEquals(paymentTransaction.getStatus(), TransactionStatus.PAYMENT_FAILURE.toString());
    assertEquals(paymentTransaction.getGatewayErrorCode(), MockPaymentProviderPlugin.GATEWAY_ERROR_CODE);
    assertEquals(paymentTransaction.getGatewayErrorMsg(), MockPaymentProviderPlugin.GATEWAY_ERROR);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) Test(org.testng.annotations.Test)

Example 48 with Account

use of org.killbill.billing.client.model.Account in project killbill by killbill.

the class TestPayment method testComboAuthorizationControlPluginException.

@Test(groups = "slow")
public void testComboAuthorizationControlPluginException() throws Exception {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final ComboPaymentTransaction comboPaymentTransaction = createComboPaymentTransaction(accountJson, paymentExternalKey);
    mockPaymentControlProviderPlugin.throwsException(new IllegalStateException());
    try {
        killBillClient.createPayment(comboPaymentTransaction, Arrays.asList(MockPaymentControlProviderPlugin.PLUGIN_NAME), ImmutableMap.<String, String>of(), requestOptions);
        fail();
    } catch (KillBillClientException e) {
        assertEquals(e.getResponse().getStatusCode(), 500);
    }
}
Also used : Account(org.killbill.billing.client.model.Account) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 49 with Account

use of org.killbill.billing.client.model.Account in project killbill by killbill.

the class TestPayment method testGetTagsForPaymentTransaction.

@Test(groups = "slow")
public void testGetTagsForPaymentTransaction() throws Exception {
    UUID tagDefinitionId = UUID.randomUUID();
    String tagDefinitionName = "payment-transaction";
    TagDefinition tagDefinition = new TagDefinition(tagDefinitionId, false, tagDefinitionName, "description", null);
    final TagDefinition createdTagDefinition = killBillClient.createTagDefinition(tagDefinition, requestOptions);
    final Account account = createAccountWithDefaultPaymentMethod();
    final String externalPaymentKey = UUID.randomUUID().toString();
    final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
    final Payment payment = killBillClient.getPaymentByExternalKey(externalPaymentKey, requestOptions);
    assertEquals(payment.getPaymentId(), paymentId);
    UUID paymentTransactionId = payment.getTransactions().get(0).getTransactionId();
    killBillClient.createPaymentTransactionTag(paymentTransactionId, createdTagDefinition.getId(), requestOptions);
    final Tags paymentTransactionTags = killBillClient.getPaymentTransactionTags(paymentTransactionId, requestOptions);
    Assert.assertNotNull(paymentTransactionTags);
    Assert.assertEquals(paymentTransactionTags.get(0).getTagDefinitionName(), tagDefinitionName);
}
Also used : TagDefinition(org.killbill.billing.client.model.TagDefinition) Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 50 with Account

use of org.killbill.billing.client.model.Account 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();
    killBillClient.deletePaymentMethod(paymentMethodId, true, false, inputOptions);
    Tags accountTags = killBillClient.getAccountTags(account.getAccountId(), inputOptions);
    Assert.assertNotNull(accountTags);
    Assert.assertEquals(accountTags.get(0).getTagDefinitionName(), "AUTO_PAY_OFF");
}
Also used : Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)123 Test (org.testng.annotations.Test)109 UUID (java.util.UUID)32 DateTime (org.joda.time.DateTime)32 Invoice (org.killbill.billing.client.model.Invoice)30 BigDecimal (java.math.BigDecimal)27 Payment (org.killbill.billing.client.model.Payment)24 Subscription (org.killbill.billing.client.model.Subscription)24 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)17 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)16 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)16 KillBillClientException (org.killbill.billing.client.KillBillClientException)14 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)14 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)13 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)10 Payments (org.killbill.billing.client.model.Payments)10 Tags (org.killbill.billing.client.model.Tags)10 Invoices (org.killbill.billing.client.model.Invoices)9 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)9