Search in sources :

Example 1 with PaymentMethod

use of org.killbill.billing.client.model.gen.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 = accountApi.getInvoicePayments(accountJson.getAccountId(), null, requestOptions);
    assertEquals(noPaymentsFromJson.size(), 0);
    // Get the invoices
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    // 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);
    invoiceApi.createInstantPayment(invoiceId, invoicePayment, true, ImmutableList.of(), null, requestOptions);
    // Verify we indeed got the invoicePayment
    final List<InvoicePayment> paymentsFromJson = accountApi.getInvoicePayments(accountJson.getAccountId(), null, requestOptions);
    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 = paymentMethodApi.getPaymentMethod(paymentMethodId, null, requestOptions);
    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.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 2 with PaymentMethod

use of org.killbill.billing.client.model.gen.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
    paymentMethodApi.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    // create another PM
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), false, PLUGIN_NAME, info, null);
    final PaymentMethod otherPaymentMethod = accountApi.createPaymentMethod(accountJson.getAccountId(), paymentMethodJson, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, 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());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    final InvoicePayment invoicePaymentExternalRefund = invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, true, otherPaymentMethod.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, 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.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.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 3 with PaymentMethod

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

the class TestPayment method testCreateRetrievePayment.

@Test(groups = "slow")
public void testCreateRetrievePayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final String externalPaymentKey = UUID.randomUUID().toString();
    final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
    final Payment payment = paymentApi.getPaymentByExternalKey(externalPaymentKey, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(payment.getPaymentId(), paymentId);
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), account.getAccountId(), false, PLUGIN_NAME, new PaymentMethodPluginDetail(), null);
    final PaymentMethod nonDefaultPaymentMethod = accountApi.createPaymentMethod(account.getAccountId(), paymentMethodJson, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    testCreateRetrievePayment(account, nonDefaultPaymentMethod.getPaymentMethodId(), UUID.randomUUID().toString(), 2);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 4 with PaymentMethod

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

the class TestPayment method testComboAuthorizationInvalidPaymentMethod.

@Test(groups = "slow")
public void testComboAuthorizationInvalidPaymentMethod() throws Exception {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    info.setProperties(null);
    final UUID paymentMethodId = UUID.randomUUID();
    final PaymentMethod paymentMethodJson = new PaymentMethod();
    paymentMethodJson.setPluginName(PLUGIN_NAME);
    paymentMethodJson.setPluginInfo(info);
    paymentMethodJson.setIsDefault(true);
    paymentMethodJson.setPaymentMethodId(paymentMethodId);
    final ComboPaymentTransaction comboPaymentTransaction = new ComboPaymentTransaction(accountJson, paymentMethodJson, new PaymentTransaction(), ImmutableList.<PluginProperty>of(), ImmutableList.<PluginProperty>of(), null);
    final Payment payment = paymentApi.createComboPayment(comboPaymentTransaction, NULL_PLUGIN_NAMES, requestOptions);
    // Client returns null in case of a 404
    Assert.assertNull(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) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 5 with PaymentMethod

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

the class TestPayment method testComboAuthorizationControlWithNullPaymentMethodId.

@Test(groups = "slow")
public void testComboAuthorizationControlWithNullPaymentMethodId() throws Exception {
    final Account accountJson = createAccount();
    // Non-default payment method
    final PaymentMethod paymentMethod = createPaymentMethod(accountJson, false);
    mockPaymentControlProviderPlugin.setAdjustedPaymentMethodId(paymentMethod.getPaymentMethodId());
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction authTransactionJson = new PaymentTransaction();
    authTransactionJson.setPaymentExternalKey(paymentExternalKey);
    authTransactionJson.setAmount(BigDecimal.TEN);
    authTransactionJson.setTransactionType(TransactionType.AUTHORIZE);
    final ComboPaymentTransaction comboPaymentTransaction = new ComboPaymentTransaction();
    comboPaymentTransaction.setAccount(accountJson);
    comboPaymentTransaction.setTransaction(authTransactionJson);
    comboPaymentTransaction.setTransaction(authTransactionJson);
    final Payment payment = paymentApi.createComboPayment(comboPaymentTransaction, ImmutableList.<String>of(MockPaymentControlProviderPlugin.PLUGIN_NAME), requestOptions);
    verifyComboPayment(payment, paymentExternalKey, BigDecimal.TEN, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
    assertEquals(paymentApi.getPayment(payment.getPaymentId(), false, true, ImmutableMap.<String, String>of(), AuditLevel.NONE, requestOptions).getPaymentAttempts().size(), 1);
}
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) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) Test(org.testng.annotations.Test)

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