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);
}
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);
}
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);
}
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());
}
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);
}
Aggregations