Search in sources :

Example 6 with PaymentMethod

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

the class TestPaymentMethod method testGePaymentMethodsByKey.

@Test(groups = "slow", description = "Create/retrieve by externalKey")
public void testGePaymentMethodsByKey() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod("foo");
    final PaymentMethod paymentMethodJson1 = paymentMethodApi.getPaymentMethodByKey("foo", NULL_PLUGIN_PROPERTIES, requestOptions);
    final PaymentMethod paymentMethodJson2 = paymentMethodApi.getPaymentMethod(accountJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(paymentMethodJson1, paymentMethodJson2);
    final PaymentMethod paymentMethodJson3 = paymentMethodApi.getPaymentMethodByKey("doesnotexist", NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertNull(paymentMethodJson3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) Test(org.testng.annotations.Test)

Example 7 with PaymentMethod

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

the class TestInvoicePayment method setupScenarioWithPayment.

private InvoicePayment setupScenarioWithPayment(final boolean invoicePaymentSuccess) throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice("Shotgun", invoicePaymentSuccess, true);
    final List<InvoicePayment> paymentsForAccount = accountApi.getInvoicePayments(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(paymentsForAccount.size(), 1);
    final InvoicePayment paymentJson = paymentsForAccount.get(0);
    // Check the PaymentMethod from paymentMethodId returned in the Payment object
    final UUID paymentMethodId = paymentJson.getPaymentMethodId();
    final PaymentMethod paymentMethodJson = paymentMethodApi.getPaymentMethod(paymentMethodId, NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
    Assert.assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
    // Verify the refunds
    final List<PaymentTransaction> objRefundFromJson = getInvoicePaymentTransactions(paymentsForAccount, TransactionType.REFUND);
    Assert.assertEquals(objRefundFromJson.size(), 0);
    return paymentJson;
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) UUID(java.util.UUID)

Example 8 with PaymentMethod

use of org.killbill.billing.client.model.gen.PaymentMethod 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 9 with PaymentMethod

use of org.killbill.billing.client.model.gen.PaymentMethod 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 10 with PaymentMethod

use of org.killbill.billing.client.model.gen.PaymentMethod 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)14 Account (org.killbill.billing.client.model.gen.Account)12 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)9 Test (org.testng.annotations.Test)9 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)6 UUID (java.util.UUID)5 Payment (org.killbill.billing.client.model.gen.Payment)5 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)5 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)4 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)2 ArrayList (java.util.ArrayList)1 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 Invoice (org.killbill.billing.client.model.gen.Invoice)1