Search in sources :

Example 21 with KillBillClientException

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

the class TestAccount method testAccountPaymentMethods.

@Test(groups = "slow", description = "Can CRUD payment methods")
public void testAccountPaymentMethods() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(getPaymentMethodCCProperties());
    PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), true, PLUGIN_NAME, info);
    final PaymentMethod paymentMethodCC = killBillClient.createPaymentMethod(paymentMethodJson, requestOptions);
    assertTrue(paymentMethodCC.getIsDefault());
    //
    // Add another payment method
    //
    final PaymentMethodPluginDetail info2 = new PaymentMethodPluginDetail();
    info2.setProperties(getPaymentMethodPaypalProperties());
    paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), false, PLUGIN_NAME, info2);
    final PaymentMethod paymentMethodPP = killBillClient.createPaymentMethod(paymentMethodJson, requestOptions);
    assertFalse(paymentMethodPP.getIsDefault());
    //
    // FETCH ALL PAYMENT METHODS
    //
    List<PaymentMethod> paymentMethods = killBillClient.getPaymentMethodsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(paymentMethods.size(), 2);
    //
    // CHANGE DEFAULT
    //
    assertTrue(killBillClient.getPaymentMethod(paymentMethodCC.getPaymentMethodId(), requestOptions).getIsDefault());
    assertFalse(killBillClient.getPaymentMethod(paymentMethodPP.getPaymentMethodId(), requestOptions).getIsDefault());
    killBillClient.updateDefaultPaymentMethod(accountJson.getAccountId(), paymentMethodPP.getPaymentMethodId(), requestOptions);
    assertTrue(killBillClient.getPaymentMethod(paymentMethodPP.getPaymentMethodId(), requestOptions).getIsDefault());
    assertFalse(killBillClient.getPaymentMethod(paymentMethodCC.getPaymentMethodId(), requestOptions).getIsDefault());
    //
    // DELETE NON DEFAULT PM
    //
    killBillClient.deletePaymentMethod(paymentMethodCC.getPaymentMethodId(), false, false, requestOptions);
    //
    // FETCH ALL PAYMENT METHODS
    //
    paymentMethods = killBillClient.getPaymentMethodsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(paymentMethods.size(), 1);
    //
    try {
        killBillClient.deletePaymentMethod(paymentMethodPP.getPaymentMethodId(), false, false, requestOptions);
        fail();
    } catch (final KillBillClientException e) {
    }
    //
    // RETRY TO DELETE DEFAULT PAYMENT METHOD (with special flag this time)
    //
    killBillClient.deletePaymentMethod(paymentMethodPP.getPaymentMethodId(), true, false, requestOptions);
    // CHECK ACCOUNT IS NOW AUTO_PAY_OFF
    final List<Tag> tagsJson = killBillClient.getAccountTags(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(tagsJson.size(), 1);
    final Tag tagJson = tagsJson.get(0);
    Assert.assertEquals(tagJson.getTagDefinitionName(), "AUTO_PAY_OFF");
    Assert.assertEquals(tagJson.getTagDefinitionId(), new UUID(0, 1));
    // FETCH ACCOUNT AGAIN AND CHECK THERE IS NO DEFAULT PAYMENT METHOD SET
    final Account updatedAccount = killBillClient.getAccount(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(updatedAccount.getAccountId(), accountJson.getAccountId());
    Assert.assertNull(updatedAccount.getPaymentMethodId());
    //
    try {
        killBillClient.deleteAccountTag(accountJson.getAccountId(), new UUID(0, 1), requestOptions);
    } catch (final KillBillClientException e) {
    }
}
Also used : Account(org.killbill.billing.client.model.Account) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) KillBillClientException(org.killbill.billing.client.KillBillClientException) Tag(org.killbill.billing.client.model.Tag) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

KillBillClientException (org.killbill.billing.client.KillBillClientException)21 Test (org.testng.annotations.Test)20 Account (org.killbill.billing.client.model.Account)13 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)7 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)6 UUID (java.util.UUID)5 Payment (org.killbill.billing.client.model.Payment)5 BigDecimal (java.math.BigDecimal)3 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)3 TransactionType (org.killbill.billing.payment.api.TransactionType)3 Response (com.ning.http.client.Response)2 RequestOptions (org.killbill.billing.client.RequestOptions)2 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)2 RoleDefinition (org.killbill.billing.client.model.RoleDefinition)2 Tenant (org.killbill.billing.client.model.Tenant)2 UserRoles (org.killbill.billing.client.model.UserRoles)2 Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Bundle (org.killbill.billing.client.model.Bundle)1