Search in sources :

Example 6 with PaymentMethodPluginDetail

use of org.killbill.billing.client.model.gen.PaymentMethodPluginDetail 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, EMPTY_AUDIT_LOGS);
    final PaymentMethod paymentMethodCC = accountApi.createPaymentMethod(accountJson.getAccountId(), paymentMethodJson, true, false, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertTrue(paymentMethodCC.isDefault());
    // 
    // 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, EMPTY_AUDIT_LOGS);
    final PaymentMethod paymentMethodPP = accountApi.createPaymentMethod(accountJson.getAccountId(), paymentMethodJson, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertFalse(paymentMethodPP.isDefault());
    // 
    // FETCH ALL PAYMENT METHODS
    // 
    List<PaymentMethod> paymentMethods = accountApi.getPaymentMethodsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paymentMethods.size(), 2);
    // 
    // CHANGE DEFAULT
    // 
    assertTrue(paymentMethodApi.getPaymentMethod(paymentMethodCC.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions).isDefault());
    assertFalse(paymentMethodApi.getPaymentMethod(paymentMethodPP.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions).isDefault());
    accountApi.setDefaultPaymentMethod(accountJson.getAccountId(), paymentMethodPP.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertTrue(paymentMethodApi.getPaymentMethod(paymentMethodPP.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions).isDefault());
    assertFalse(paymentMethodApi.getPaymentMethod(paymentMethodCC.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions).isDefault());
    // 
    // DELETE NON DEFAULT PM
    // 
    paymentMethodApi.deletePaymentMethod(paymentMethodCC.getPaymentMethodId(), false, false, NULL_PLUGIN_PROPERTIES, requestOptions);
    // 
    // FETCH ALL PAYMENT METHODS
    // 
    paymentMethods = accountApi.getPaymentMethodsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paymentMethods.size(), 1);
    // 
    try {
        paymentMethodApi.deletePaymentMethod(paymentMethodPP.getPaymentMethodId(), false, false, NULL_PLUGIN_PROPERTIES, requestOptions);
        fail();
    } catch (final KillBillClientException e) {
    }
    // 
    // RETRY TO DELETE DEFAULT PAYMENT METHOD (with special flag this time)
    // 
    paymentMethodApi.deletePaymentMethod(paymentMethodPP.getPaymentMethodId(), true, false, NULL_PLUGIN_PROPERTIES, requestOptions);
    // CHECK ACCOUNT IS NOW AUTO_PAY_OFF
    final List<Tag> tagsJson = accountApi.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 = accountApi.getAccount(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(updatedAccount.getAccountId(), accountJson.getAccountId());
    Assert.assertNull(updatedAccount.getPaymentMethodId());
    // 
    try {
        accountApi.deleteAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(new UUID(0, 1)), requestOptions);
    } catch (final KillBillClientException e) {
        Assert.assertTrue(e.getBillingException().getCode() == ErrorCode.TAG_CANNOT_BE_REMOVED.getCode());
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) KillBillClientException(org.killbill.billing.client.KillBillClientException) Tag(org.killbill.billing.client.model.gen.Tag) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 7 with PaymentMethodPluginDetail

use of org.killbill.billing.client.model.gen.PaymentMethodPluginDetail in project killbill by killbill.

the class TestTenantKV method createComboPaymentTransaction.

private Payment createComboPaymentTransaction(final RequestOptions requestOptions) throws KillBillClientException {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(null);
    final String paymentMethodExternalKey = UUID.randomUUID().toString();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, paymentMethodExternalKey, null, true, PLUGIN_NAME, info, null);
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction authTransactionJson = new PaymentTransaction();
    authTransactionJson.setAmount(BigDecimal.TEN);
    authTransactionJson.setCurrency(accountJson.getCurrency());
    authTransactionJson.setPaymentExternalKey(UUID.randomUUID().toString());
    authTransactionJson.setTransactionExternalKey(authTransactionExternalKey);
    authTransactionJson.setTransactionType(TransactionType.AUTHORIZE);
    callbackServlet.pushExpectedEvents(ExtBusEventType.ACCOUNT_CREATION, ExtBusEventType.ACCOUNT_CHANGE, ExtBusEventType.PAYMENT_SUCCESS);
    final ComboPaymentTransaction comboAuthorization = new ComboPaymentTransaction(accountJson, paymentMethodJson, authTransactionJson, ImmutableList.<PluginProperty>of(), ImmutableList.<PluginProperty>of(), null);
    final Payment payment = paymentApi.createComboPayment(comboAuthorization, NULL_PLUGIN_NAMES, requestOptions);
    callbackServlet.assertListenerStatus();
    assertEquals(payment.getTransactions().get(0).getStatus(), TransactionStatus.SUCCESS);
    return payment;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) ComboPaymentTransaction(org.killbill.billing.client.model.gen.ComboPaymentTransaction) Payment(org.killbill.billing.client.model.gen.Payment) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod)

Example 8 with PaymentMethodPluginDetail

use of org.killbill.billing.client.model.gen.PaymentMethodPluginDetail in project killbill by killbill.

the class KillbillClient method createPaymentMethod.

protected PaymentMethod createPaymentMethod(final Account input, final boolean isDefault) throws KillBillClientException {
    if (isDefault) {
        callbackServlet.pushExpectedEvent(ExtBusEventType.ACCOUNT_CHANGE);
    }
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUIDs.randomUUID().toString(), input.getAccountId(), isDefault, ExternalPaymentProviderPlugin.PLUGIN_NAME, info, EMPTY_AUDIT_LOGS);
    final PaymentMethod paymentMethod = accountApi.createPaymentMethod(input.getAccountId(), paymentMethodJson, isDefault, false, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
    return paymentMethod;
}
Also used : PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod)

Example 9 with PaymentMethodPluginDetail

use of org.killbill.billing.client.model.gen.PaymentMethodPluginDetail in project killbill by killbill.

the class KillbillClient method createAccountWithDefaultPaymentMethod.

protected Account createAccountWithDefaultPaymentMethod(final String externalkey, @Nullable final List<PluginProperty> pmProperties) throws Exception {
    final Account input = createAccount();
    callbackServlet.pushExpectedEvent(ExtBusEventType.ACCOUNT_CHANGE);
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(pmProperties);
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, externalkey, input.getAccountId(), true, PLUGIN_NAME, info, EMPTY_AUDIT_LOGS);
    accountApi.createPaymentMethod(input.getAccountId(), paymentMethodJson, true, false, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    callbackServlet.assertListenerStatus();
    return accountApi.getAccount(input.getAccountId(), requestOptions);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod)

Aggregations

PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)9 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)9 Account (org.killbill.billing.client.model.gen.Account)7 Test (org.testng.annotations.Test)5 Payment (org.killbill.billing.client.model.gen.Payment)4 UUID (java.util.UUID)3 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)3 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)3 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)3 DateTime (org.joda.time.DateTime)1 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)1 Invoices (org.killbill.billing.client.model.Invoices)1 Payments (org.killbill.billing.client.model.Payments)1 ComboHostedPaymentPage (org.killbill.billing.client.model.gen.ComboHostedPaymentPage)1 HostedPaymentPageFields (org.killbill.billing.client.model.gen.HostedPaymentPageFields)1 HostedPaymentPageFormDescriptor (org.killbill.billing.client.model.gen.HostedPaymentPageFormDescriptor)1 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)1 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)1 Tag (org.killbill.billing.client.model.gen.Tag)1