Search in sources :

Example 31 with Payment

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

the class TestPayment method testAuthorizeCompletionUsingExternalKey.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingExternalKey() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pendingPluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.of();
    TransactionType transactionType = TransactionType.AUTHORIZE;
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.PENDING, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
    completeTransactionWithTypeAndKey.setPaymentExternalKey(paymentExternalKey);
    completeTransactionWithTypeAndKey.setTransactionExternalKey(authTransactionExternalKey);
    paymentApi.completeTransactionByExternalKey(completeTransactionWithTypeAndKey, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByPaymentId = paymentApi.getPayment(initialPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.SUCCESS, amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 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) TransactionType(org.killbill.billing.payment.api.TransactionType) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 32 with Payment

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

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetPaymentById.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPaymentById() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
    Payments payments = paymentApi.searchPayments("", 0L, 100L, false, true, null, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
    Assert.assertNotNull(payments.get(0));
    Payment payment = paymentApi.getPayment(payments.get(0).getPaymentId(), false, true, NULL_PLUGIN_PROPERTIES, AuditLevel.NONE, requestOptions);
    Assert.assertNotNull(payment.getPaymentAttempts());
    Assert.assertEquals(payment.getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(payment.getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Payments(org.killbill.billing.client.model.Payments) Test(org.testng.annotations.Test)

Example 33 with Payment

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

the class TestPayment method testComboAuthorization.

@Test(groups = "slow")
public void testComboAuthorization() throws Exception {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final ComboPaymentTransaction comboPaymentTransaction = createComboPaymentTransaction(accountJson, paymentExternalKey);
    final Payment payment = paymentApi.createComboPayment(comboPaymentTransaction, NULL_PLUGIN_NAMES, requestOptions);
    verifyComboPayment(payment, paymentExternalKey, BigDecimal.TEN, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
    // Void payment using externalKey
    final String voidTransactionExternalKey = UUID.randomUUID().toString();
    PaymentTransaction voidTransaction = new PaymentTransaction();
    voidTransaction.setTransactionExternalKey(voidTransactionExternalKey);
    voidTransaction.setPaymentExternalKey(paymentExternalKey);
    paymentApi.voidPaymentByExternalKey(voidTransaction, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment voidPayment = paymentApi.getPayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPaymentTransaction(accountJson, voidPayment.getPaymentId(), paymentExternalKey, voidPayment.getTransactions().get(1), voidTransactionExternalKey, null, TransactionType.VOID, TransactionStatus.SUCCESS);
}
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) Test(org.testng.annotations.Test)

Example 34 with Payment

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

the class TestPayment method testPaymentAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testPaymentAuditLogsWithHistory() 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 List<AuditLog> paymentAuditLogWithHistory = paymentApi.getPaymentAuditLogsWithHistory(paymentId, requestOptions);
    assertEquals(paymentAuditLogWithHistory.size(), 8);
    assertEquals(paymentAuditLogWithHistory.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(paymentAuditLogWithHistory.get(0).getObjectType(), ObjectType.PAYMENT);
    assertEquals(paymentAuditLogWithHistory.get(0).getObjectId(), paymentId);
    final LinkedHashMap history1 = (LinkedHashMap) paymentAuditLogWithHistory.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("stateName"), null);
    final LinkedHashMap history2 = (LinkedHashMap) paymentAuditLogWithHistory.get(1).getHistory();
    assertNotNull(history2);
    assertEquals(history2.get("stateName"), "AUTH_SUCCESS");
    final LinkedHashMap history3 = (LinkedHashMap) paymentAuditLogWithHistory.get(2).getHistory();
    assertNotNull(history3);
    assertEquals(history3.get("stateName"), "AUTH_SUCCESS");
    final LinkedHashMap history4 = (LinkedHashMap) paymentAuditLogWithHistory.get(3).getHistory();
    assertNotNull(history4);
    assertEquals(history4.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history5 = (LinkedHashMap) paymentAuditLogWithHistory.get(4).getHistory();
    assertNotNull(history5);
    assertEquals(history5.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history6 = (LinkedHashMap) paymentAuditLogWithHistory.get(5).getHistory();
    assertNotNull(history6);
    assertEquals(history6.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history7 = (LinkedHashMap) paymentAuditLogWithHistory.get(6).getHistory();
    assertNotNull(history7);
    assertEquals(history7.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history8 = (LinkedHashMap) paymentAuditLogWithHistory.get(7).getHistory();
    assertNotNull(history8);
    assertEquals(history8.get("stateName"), "REFUND_SUCCESS");
}
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) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 35 with Payment

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

the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionType.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionType() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pendingPluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.of();
    TransactionType transactionType = TransactionType.AUTHORIZE;
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.PENDING, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    final PaymentTransaction completeTransactionByPaymentIdAndInvalidTransactionType = new PaymentTransaction();
    completeTransactionByPaymentIdAndInvalidTransactionType.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndInvalidTransactionType.setTransactionType(TransactionType.CAPTURE);
    try {
        paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentIdAndInvalidTransactionType, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
        fail("Payment completion should fail when invalid transaction type has been provided");
    } catch (final KillBillClientException expected) {
    }
    final PaymentTransaction completeTransactionByPaymentIdAndTransactionType = new PaymentTransaction();
    completeTransactionByPaymentIdAndTransactionType.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndTransactionType.setTransactionType(transactionType);
    paymentApi.completeTransaction(initialPayment.getPaymentId(), completeTransactionByPaymentIdAndTransactionType, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByPaymentId = paymentApi.getPayment(initialPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType, TransactionStatus.SUCCESS, amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 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) TransactionType(org.killbill.billing.payment.api.TransactionType) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) KillBillClientException(org.killbill.billing.client.KillBillClientException) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Payment (org.killbill.billing.client.model.gen.Payment)41 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)36 Test (org.testng.annotations.Test)34 Account (org.killbill.billing.client.model.gen.Account)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)23 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)18 BigDecimal (java.math.BigDecimal)16 UUID (java.util.UUID)14 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)13 TransactionType (org.killbill.billing.payment.api.TransactionType)8 DateTime (org.joda.time.DateTime)7 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)7 Payments (org.killbill.billing.client.model.Payments)7 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)7 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)5 KillBillClientException (org.killbill.billing.client.KillBillClientException)4 Invoices (org.killbill.billing.client.model.Invoices)4 Invoice (org.killbill.billing.client.model.gen.Invoice)4 PaymentMethodPluginDetail (org.killbill.billing.client.model.gen.PaymentMethodPluginDetail)4 RequestOptions (org.killbill.billing.client.RequestOptions)2