Search in sources :

Example 86 with Account

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

the class TestInvoicePayment method testWithFailedInvoicePayment.

@Test(groups = "slow")
public void testWithFailedInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    InvoicePayments invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoicePayments.size(), 1);
    final InvoicePayment invoicePayment = invoicePayments.get(0);
    // Verify targetInvoiceId is not Null. See #593
    assertNotNull(invoicePayment.getTargetInvoiceId());
    final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoices.size(), 2);
    final Invoice invoice = invoices.get(1);
    // Verify this is the correct value
    assertEquals(invoicePayment.getTargetInvoiceId(), invoice.getInvoiceId());
    // Make a payment and verify both invoice payment point to the same targetInvoiceId
    killBillClient.payAllInvoices(accountJson.getAccountId(), false, null, requestOptions);
    invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoicePayments.size(), 2);
    for (final InvoicePayment cur : invoicePayments) {
        assertEquals(cur.getTargetInvoiceId(), invoice.getInvoiceId());
    }
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) Invoices(org.killbill.billing.client.model.Invoices) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 87 with Account

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

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetPaymentsForAccount.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPaymentsForAccount() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    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 = killBillClient.getPaymentsForAccount(account.getAccountId(), 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 : Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Test(org.testng.annotations.Test)

Example 88 with Account

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

the class TestPayment method testCompletionForInitialTransaction.

@Test(groups = "slow")
public void testCompletionForInitialTransaction() 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);
    int paymentNb = 0;
    for (final TransactionType transactionType : ImmutableList.<TransactionType>of(TransactionType.AUTHORIZE, TransactionType.PURCHASE, TransactionType.CREDIT)) {
        final BigDecimal authAmount = BigDecimal.ZERO;
        final String paymentExternalKey = UUID.randomUUID().toString();
        final String authTransactionExternalKey = UUID.randomUUID().toString();
        paymentNb++;
        final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, pending, amount, authAmount, pluginProperties, paymentNb);
        final PaymentTransaction authPaymentTransaction = initialPayment.getTransactions().get(0);
        // Complete operation: first, only specify the payment id
        final PaymentTransaction completeTransactionByPaymentId = new PaymentTransaction();
        completeTransactionByPaymentId.setPaymentId(initialPayment.getPaymentId());
        final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentId, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
        // Second, only specify the payment external key
        final PaymentTransaction completeTransactionByPaymentExternalKey = new PaymentTransaction();
        completeTransactionByPaymentExternalKey.setPaymentExternalKey(initialPayment.getPaymentExternalKey());
        final Payment completedPaymentByExternalKey = killBillClient.completePayment(completeTransactionByPaymentExternalKey, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByExternalKey, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
        // Third, specify the payment id and transaction external key
        final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
        completeTransactionWithTypeAndKey.setPaymentId(initialPayment.getPaymentId());
        completeTransactionWithTypeAndKey.setTransactionExternalKey(authPaymentTransaction.getTransactionExternalKey());
        final Payment completedPaymentByTypeAndKey = killBillClient.completePayment(completeTransactionWithTypeAndKey, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByTypeAndKey, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
        // Finally, specify the payment id and transaction id
        final PaymentTransaction completeTransactionWithTypeAndId = new PaymentTransaction();
        completeTransactionWithTypeAndId.setPaymentId(initialPayment.getPaymentId());
        completeTransactionWithTypeAndId.setTransactionId(authPaymentTransaction.getTransactionId());
        final Payment completedPaymentByTypeAndId = killBillClient.completePayment(completeTransactionWithTypeAndId, pluginProperties, requestOptions);
        verifyPayment(account, paymentMethodId, completedPaymentByTypeAndId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), pending, amount, authAmount, BigDecimal.ZERO, BigDecimal.ZERO, 1, paymentNb);
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 89 with Account

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

the class TestPayment method testCreateTagForPaymentTransaction.

@Test(groups = "slow")
public void testCreateTagForPaymentTransaction() 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();
    final Tags paymentTransactionTag = killBillClient.createPaymentTransactionTag(paymentTransactionId, createdTagDefinition.getId(), requestOptions);
    Assert.assertNotNull(paymentTransactionTag);
    Assert.assertEquals(paymentTransactionTag.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 90 with Account

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

the class TestPayment method testWithFailedPaymentAndWithoutFollowLocation.

@Test(groups = "slow")
public void testWithFailedPaymentAndWithoutFollowLocation() 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 RequestOptions requestOptionsWithoutFollowLocation = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withFollowLocation(false).build();
    try {
        killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptionsWithoutFollowLocation);
        fail();
    } catch (final KillBillClientException e) {
        assertEquals(e.getResponse().getStatusCode(), 402);
        assertEquals(e.getBillingException().getMessage(), "Payment decline by gateway. Error message: gatewayError");
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) KillBillClientException(org.killbill.billing.client.KillBillClientException) 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