Search in sources :

Example 16 with Payment

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

the class TestPayment method testGetTagsForPaymentTransaction.

@Test(groups = "slow")
public void testGetTagsForPaymentTransaction() throws Exception {
    UUID tagDefinitionId = UUID.randomUUID();
    String tagDefinitionName = "payment-transaction";
    TagDefinition tagDefinition = new TagDefinition(tagDefinitionId, false, tagDefinitionName, "description", ImmutableList.<ObjectType>of(ObjectType.TRANSACTION), null);
    final TagDefinition createdTagDefinition = tagDefinitionApi.createTagDefinition(tagDefinition, requestOptions);
    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);
    UUID paymentTransactionId = payment.getTransactions().get(0).getTransactionId();
    paymentTransactionApi.createTransactionTags(paymentTransactionId, ImmutableList.<UUID>of(createdTagDefinition.getId()), requestOptions);
    final Tags paymentTransactionTags = paymentTransactionApi.getTransactionTags(paymentTransactionId, requestOptions);
    Assert.assertNotNull(paymentTransactionTags);
    Assert.assertEquals(paymentTransactionTags.get(0).getTagDefinitionName(), tagDefinitionName);
}
Also used : TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) 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) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 17 with Payment

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

the class TestPayment method testCompletionForSubsequentTransaction.

@Test(groups = "slow")
public void testCompletionForSubsequentTransaction() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String purchaseTransactionExternalKey = UUID.randomUUID().toString();
    final BigDecimal purchaseAmount = BigDecimal.TEN;
    // Create a successful purchase
    final Payment authPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, TransactionType.PURCHASE, TransactionStatus.SUCCESS, purchaseAmount, BigDecimal.ZERO, ImmutableMap.<String, String>of(), 1);
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    // Trigger a pending refund
    final String refundTransactionExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction refundTransaction = new PaymentTransaction();
    refundTransaction.setPaymentId(authPayment.getPaymentId());
    refundTransaction.setTransactionExternalKey(refundTransactionExternalKey);
    refundTransaction.setAmount(purchaseAmount);
    refundTransaction.setCurrency(authPayment.getCurrency());
    final Payment refundPayment = paymentApi.refundPayment(authPayment.getPaymentId(), refundTransaction, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, refundPayment);
    final PaymentTransaction completeTransactionWithTypeAndKey = new PaymentTransaction();
    completeTransactionWithTypeAndKey.setPaymentExternalKey(paymentExternalKey);
    completeTransactionWithTypeAndKey.setTransactionExternalKey(refundTransactionExternalKey);
    paymentApi.completeTransactionByExternalKey(completeTransactionWithTypeAndKey, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByTypeAndKey = paymentApi.getPayment(refundPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, completedPaymentByTypeAndKey);
    // Also, it should work if we specify the payment id and transaction id
    final PaymentTransaction completeTransactionWithTypeAndId = new PaymentTransaction();
    completeTransactionWithTypeAndId.setPaymentId(refundPayment.getPaymentId());
    completeTransactionWithTypeAndId.setTransactionId(refundPayment.getTransactions().get(1).getTransactionId());
    paymentApi.completeTransaction(refundPayment.getPaymentId(), completeTransactionWithTypeAndId, NULL_PLUGIN_NAMES, pluginProperties, requestOptions);
    final Payment completedPaymentByTypeAndId = paymentApi.getPayment(refundPayment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyPaymentWithPendingRefund(account, paymentMethodId, paymentExternalKey, purchaseTransactionExternalKey, purchaseAmount, refundTransactionExternalKey, completedPaymentByTypeAndId);
}
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) 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 18 with Payment

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

Example 19 with Payment

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

the class TestInvoicePayment method verifyRefund.

private void verifyRefund(final InvoicePayment paymentJson, final Payment paymentAfterRefund, final BigDecimal refundAmount) throws KillBillClientException {
    final List<PaymentTransaction> transactions = getPaymentTransactions(ImmutableList.of(paymentAfterRefund), TransactionType.REFUND);
    Assert.assertEquals(transactions.size(), 1);
    final PaymentTransaction refund = transactions.get(0);
    Assert.assertEquals(refund.getPaymentId(), paymentJson.getPaymentId());
    Assert.assertEquals(refund.getAmount().setScale(2, RoundingMode.HALF_UP), refundAmount.setScale(2, RoundingMode.HALF_UP));
    Assert.assertEquals(refund.getCurrency(), DEFAULT_CURRENCY);
    Assert.assertEquals(refund.getStatus(), TransactionStatus.SUCCESS);
    Assert.assertEquals(refund.getEffectiveDate().getYear(), clock.getUTCNow().getYear());
    Assert.assertEquals(refund.getEffectiveDate().getMonthOfYear(), clock.getUTCNow().getMonthOfYear());
    Assert.assertEquals(refund.getEffectiveDate().getDayOfMonth(), clock.getUTCNow().getDayOfMonth());
    // Verify the refund via the payment API
    final Payment retrievedPaymentJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(retrievedPaymentJson.getPaymentId(), paymentJson.getPaymentId());
    Assert.assertEquals(retrievedPaymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP), paymentJson.getPurchasedAmount().setScale(2, RoundingMode.HALF_UP));
    Assert.assertEquals(retrievedPaymentJson.getAccountId(), paymentJson.getAccountId());
    Assert.assertEquals(retrievedPaymentJson.getCurrency(), paymentJson.getCurrency());
    Assert.assertEquals(retrievedPaymentJson.getPaymentMethodId(), paymentJson.getPaymentMethodId());
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment)

Example 20 with Payment

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

the class TestInvoicePayment method testPartialRefundWithInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can create a partial refund with invoice item adjustment")
public void testPartialRefundWithInvoiceItemAdjustment() throws Exception {
    final InvoicePayment paymentJson = setupScenarioWithPayment(true);
    // Get the individual items for the invoice
    final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), false, AuditLevel.NONE, requestOptions);
    final InvoiceItem itemToAdjust = invoice.getItems().get(0);
    // Issue a refund for a fraction of the amount
    final BigDecimal refundAmount = getFractionOfAmount(itemToAdjust.getAmount());
    final BigDecimal expectedInvoiceBalance = BigDecimal.ZERO;
    // Post and verify the refund
    final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
    refund.setPaymentId(paymentJson.getPaymentId());
    refund.setIsAdjusted(true);
    final InvoiceItem adjustment = new InvoiceItem();
    adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
    adjustment.setAmount(refundAmount);
    refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
    invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
    // Verify the invoice balance
    verifyInvoice(paymentJson, expectedInvoiceBalance);
}
Also used : InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) 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