Search in sources :

Example 6 with PaymentMethod

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

the class TestInvoice method testExternalPayment.

@Test(groups = "slow", description = "Can create an external payment")
public void testExternalPayment() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Verify we didn't get any invoicePayment
    final List<InvoicePayment> noPaymentsFromJson = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId());
    assertEquals(noPaymentsFromJson.size(), 0);
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final UUID invoiceId = invoices.get(1).getInvoiceId();
    // Post an external invoicePayment
    final InvoicePayment invoicePayment = new InvoicePayment();
    invoicePayment.setPurchasedAmount(BigDecimal.TEN);
    invoicePayment.setAccountId(accountJson.getAccountId());
    invoicePayment.setTargetInvoiceId(invoiceId);
    killBillClient.createInvoicePayment(invoicePayment, true, createdBy, reason, comment);
    // Verify we indeed got the invoicePayment
    final List<InvoicePayment> paymentsFromJson = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId());
    assertEquals(paymentsFromJson.size(), 1);
    assertEquals(paymentsFromJson.get(0).getPurchasedAmount().compareTo(BigDecimal.TEN), 0);
    assertEquals(paymentsFromJson.get(0).getTargetInvoiceId(), invoiceId);
    // Check the PaymentMethod from paymentMethodId returned in the Payment object
    final UUID paymentMethodId = paymentsFromJson.get(0).getPaymentMethodId();
    final PaymentMethod paymentMethodJson = killBillClient.getPaymentMethod(paymentMethodId);
    assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
    assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
    assertEquals(paymentMethodJson.getPluginName(), ExternalPaymentProviderPlugin.PLUGIN_NAME);
    assertNull(paymentMethodJson.getPluginInfo());
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 7 with PaymentMethod

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

the class TestExternalRefund method testAutomaticPaymentAndExternalRefundWithDifferentPM.

@Test(groups = "slow", description = "#255 - Scenario 2b - Can refund an automatic payment though another existing payment method")
public void testAutomaticPaymentAndExternalRefundWithDifferentPM() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // delete PM
    killBillClient.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, requestOptions);
    // create another PM
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), false, PLUGIN_NAME, info);
    final PaymentMethod otherPaymentMethod = killBillClient.createPaymentMethod(paymentMethodJson, requestOptions);
    final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true, requestOptions);
    final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
    // external refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency().toString());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    final InvoicePayment invoicePaymentExternalRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, true, otherPaymentMethod.getPaymentMethodId(), requestOptions);
    assertNotNull(invoicePaymentExternalRefund);
    assertEquals(invoicePaymentExternalRefund.getPaymentMethodId(), otherPaymentMethod.getPaymentMethodId());
    assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 8 with PaymentMethod

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

the class TestCache method createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoiceWithInputOptions.

private void createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoiceWithInputOptions(final RequestOptions inputOptions) throws Exception {
    Account account = killBillClient.createAccount(getAccount(), inputOptions);
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(null);
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), account.getAccountId(), true, PLUGIN_NAME, info);
    killBillClient.createPaymentMethod(paymentMethodJson, inputOptions);
    final Subscription subscription = new Subscription();
    subscription.setAccountId(account.getAccountId());
    subscription.setExternalKey(UUID.randomUUID().toString());
    subscription.setProductName("Sports");
    subscription.setProductCategory(ProductCategory.BASE);
    subscription.setBillingPeriod(BillingPeriod.MONTHLY);
    subscription.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    clock.resetDeltaFromReality();
    clock.setDay(new LocalDate(2013, 3, 1));
    final Subscription subscriptionJson = killBillClient.createSubscription(subscription, clock.getUTCToday(), DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, inputOptions);
    assertNotNull(subscriptionJson);
    clock.addDays(32);
    crappyWaitForLackOfProperSynchonization();
}
Also used : Account(org.killbill.billing.client.model.Account) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) Subscription(org.killbill.billing.client.model.Subscription) LocalDate(org.joda.time.LocalDate)

Example 9 with PaymentMethod

use of org.killbill.billing.client.model.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();
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(pmProperties);
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, externalkey, input.getAccountId(), true, PLUGIN_NAME, info);
    killBillClient.createPaymentMethod(paymentMethodJson, createdBy, reason, comment);
    return killBillClient.getAccount(input.getExternalKey());
}
Also used : Account(org.killbill.billing.client.model.Account) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.PaymentMethod)

Example 10 with PaymentMethod

use of org.killbill.billing.client.model.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);
    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

PaymentMethod (org.killbill.billing.client.model.PaymentMethod)14 Account (org.killbill.billing.client.model.Account)13 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)10 Test (org.testng.annotations.Test)8 UUID (java.util.UUID)5 Payment (org.killbill.billing.client.model.Payment)4 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)3 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)3 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)3 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)2 ArrayList (java.util.ArrayList)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 KillBillClientException (org.killbill.billing.client.KillBillClientException)1 ComboHostedPaymentPage (org.killbill.billing.client.model.ComboHostedPaymentPage)1 HostedPaymentPageFields (org.killbill.billing.client.model.HostedPaymentPageFields)1 HostedPaymentPageFormDescriptor (org.killbill.billing.client.model.HostedPaymentPageFormDescriptor)1 Invoice (org.killbill.billing.client.model.Invoice)1 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)1 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)1