Commit
…ymentTransactionTask A bit of renaming in the janitor tasks Fix MockPaymentProviderPlugin to keep track of PaymentTransactionInfoPlugin
- Loading branch information
There are no files selected for viewing
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -30,18 +30,19 @@ | ||
import org.killbill.billing.invoice.api.InvoiceApiException; | import org.killbill.billing.invoice.api.InvoiceApiException; | ||
import org.killbill.billing.invoice.api.InvoiceItem; | import org.killbill.billing.invoice.api.InvoiceItem; | ||
import org.killbill.billing.payment.api.Payment; | import org.killbill.billing.payment.api.Payment; | ||
import org.killbill.billing.payment.api.PaymentTransaction; | |||
import org.killbill.billing.payment.api.PaymentApiException; | import org.killbill.billing.payment.api.PaymentApiException; | ||
import org.killbill.billing.payment.api.PaymentOptions; | import org.killbill.billing.payment.api.PaymentOptions; | ||
import org.killbill.billing.payment.api.PaymentTransaction; | |||
import org.killbill.billing.payment.api.PluginProperty; | import org.killbill.billing.payment.api.PluginProperty; | ||
import org.killbill.billing.payment.api.TransactionStatus; | import org.killbill.billing.payment.api.TransactionStatus; | ||
import org.killbill.billing.payment.api.TransactionType; | import org.killbill.billing.payment.api.TransactionType; | ||
import org.killbill.billing.payment.invoice.InvoicePaymentRoutingPluginApi; | |||
import org.killbill.billing.payment.core.janitor.Janitor; | import org.killbill.billing.payment.core.janitor.Janitor; | ||
import org.killbill.billing.payment.dao.PaymentAttemptModelDao; | import org.killbill.billing.payment.dao.PaymentAttemptModelDao; | ||
import org.killbill.billing.payment.invoice.InvoicePaymentRoutingPluginApi; | |||
import org.killbill.billing.payment.provider.MockPaymentProviderPlugin; | import org.killbill.billing.payment.provider.MockPaymentProviderPlugin; | ||
import org.killbill.billing.platform.api.KillbillConfigSource; | import org.killbill.billing.platform.api.KillbillConfigSource; | ||
import org.killbill.bus.api.PersistentBus.EventBusException; | import org.killbill.bus.api.PersistentBus.EventBusException; | ||
import org.testng.Assert; | |||
import org.testng.annotations.AfterClass; | import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.AfterMethod; | import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeClass; | import org.testng.annotations.BeforeClass; | ||
|
@@ -68,7 +69,6 @@ public List<String> getPaymentControlPluginNames() { | ||
} | } | ||
}; | }; | ||
|
|
||
|
|||
@Inject | @Inject | ||
private Janitor janitor; | private Janitor janitor; | ||
|
|
||
|
@@ -94,7 +94,6 @@ protected void afterClass() throws Exception { | ||
janitor.stop(); | janitor.stop(); | ||
} | } | ||
|
|
||
|
|||
@BeforeMethod(groups = "slow") | @BeforeMethod(groups = "slow") | ||
public void beforeMethod() throws Exception { | public void beforeMethod() throws Exception { | ||
super.beforeMethod(); | super.beforeMethod(); | ||
|
@@ -131,7 +130,7 @@ public void testCreateSuccessPurchaseWithPaymentControl() throws PaymentApiExcep | ||
Currency.USD)); | Currency.USD)); | ||
|
|
||
final Payment payment = paymentApi.createPurchaseWithPaymentControl(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, paymentExternalKey, transactionExternalKey, | final Payment payment = paymentApi.createPurchaseWithPaymentControl(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, paymentExternalKey, transactionExternalKey, | ||
createPropertiesForInvoice(invoice), INVOICE_PAYMENT, callContext); | createPropertiesForInvoice(invoice), INVOICE_PAYMENT, callContext); | ||
assertEquals(payment.getTransactions().size(), 1); | assertEquals(payment.getTransactions().size(), 1); | ||
assertEquals(payment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); | assertEquals(payment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); | ||
assertEquals(payment.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE); | assertEquals(payment.getTransactions().get(0).getTransactionType(), TransactionType.PURCHASE); | ||
|
@@ -148,7 +147,11 @@ public void testCreateSuccessPurchaseWithPaymentControl() throws PaymentApiExcep | ||
assertEquals(attempt2.getStateName(), "INIT"); | assertEquals(attempt2.getStateName(), "INIT"); | ||
|
|
||
clock.addDays(1); | clock.addDays(1); | ||
try { Thread.sleep(1500); } catch (InterruptedException e) {}; | try { | ||
Thread.sleep(1500); | |||
} catch (InterruptedException e) { | |||
} | |||
; | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pierre
Member
|
|||
|
|
||
final PaymentAttemptModelDao attempt3 = paymentDao.getPaymentAttempt(attempt.getId(), internalCallContext); | final PaymentAttemptModelDao attempt3 = paymentDao.getPaymentAttempt(attempt.getId(), internalCallContext); | ||
assertEquals(attempt3.getStateName(), "SUCCESS"); | assertEquals(attempt3.getStateName(), "SUCCESS"); | ||
|
@@ -180,7 +183,7 @@ public void testCreateSuccessRefundPaymentControlWithItemAdjustments() throws Pa | ||
invoice.addInvoiceItem(invoiceItem); | invoice.addInvoiceItem(invoiceItem); | ||
|
|
||
final Payment payment = paymentApi.createPurchaseWithPaymentControl(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, paymentExternalKey, transactionExternalKey, | final Payment payment = paymentApi.createPurchaseWithPaymentControl(account, account.getPaymentMethodId(), null, requestedAmount, Currency.USD, paymentExternalKey, transactionExternalKey, | ||
createPropertiesForInvoice(invoice), INVOICE_PAYMENT, callContext); | createPropertiesForInvoice(invoice), INVOICE_PAYMENT, callContext); | ||
|
|
||
final List<PluginProperty> refundProperties = new ArrayList<PluginProperty>(); | final List<PluginProperty> refundProperties = new ArrayList<PluginProperty>(); | ||
final HashMap<UUID, BigDecimal> uuidBigDecimalHashMap = new HashMap<UUID, BigDecimal>(); | final HashMap<UUID, BigDecimal> uuidBigDecimalHashMap = new HashMap<UUID, BigDecimal>(); | ||
|
@@ -189,7 +192,7 @@ public void testCreateSuccessRefundPaymentControlWithItemAdjustments() throws Pa | ||
refundProperties.add(refundIdsProp); | refundProperties.add(refundIdsProp); | ||
|
|
||
final Payment payment2 = paymentApi.createRefundWithPaymentControl(account, payment.getId(), null, Currency.USD, transactionExternalKey2, | final Payment payment2 = paymentApi.createRefundWithPaymentControl(account, payment.getId(), null, Currency.USD, transactionExternalKey2, | ||
refundProperties, INVOICE_PAYMENT, callContext); | refundProperties, INVOICE_PAYMENT, callContext); | ||
|
|
||
assertEquals(payment2.getTransactions().size(), 2); | assertEquals(payment2.getTransactions().size(), 2); | ||
PaymentTransaction refundTransaction = payment2.getTransactions().get(1); | PaymentTransaction refundTransaction = payment2.getTransactions().get(1); | ||
|
@@ -207,15 +210,71 @@ public void testCreateSuccessRefundPaymentControlWithItemAdjustments() throws Pa | ||
assertEquals(attempt2.getStateName(), "INIT"); | assertEquals(attempt2.getStateName(), "INIT"); | ||
|
|
||
clock.addDays(1); | clock.addDays(1); | ||
try { Thread.sleep(1500); } catch (InterruptedException e) {}; | try { | ||
Thread.sleep(1500); | |||
} catch (InterruptedException e) { | |||
} | |||
; | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
|||
|
|
||
final PaymentAttemptModelDao attempt3 = paymentDao.getPaymentAttempt(refundAttempt.getId(), internalCallContext); | final PaymentAttemptModelDao attempt3 = paymentDao.getPaymentAttempt(refundAttempt.getId(), internalCallContext); | ||
assertEquals(attempt3.getStateName(), "SUCCESS"); | assertEquals(attempt3.getStateName(), "SUCCESS"); | ||
} | |||
|
|||
@Test(groups = "slow") | |||
public void testUnknownEntries() throws PaymentApiException, InvoiceApiException, EventBusException { | |||
|
|||
final BigDecimal requestedAmount = BigDecimal.TEN; | |||
final String paymentExternalKey = "qwru"; | |||
final String transactionExternalKey = "lkjdsf"; | |||
|
|||
final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), paymentExternalKey, | |||
transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); | |||
|
|||
// Artificially move the transaction status to UNKNOWN | |||
final String paymentStateName = paymentSMHelper.getErroredStateForTransaction(TransactionType.AUTHORIZE).toString(); | |||
paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, | |||
payment.getTransactions().get(0).getId(), TransactionStatus.UNKNOWN, requestedAmount, account.getCurrency(), | |||
"foo", "bar", internalCallContext); | |||
// The UnknownPaymentTransactionTask will look for UNKNOWN payment that *just happened* (in the last SAFETY_DELAY_MS=3min delay), and that are not too old (less than 3 days) | |||
clock.addDays(1); | |||
try { | |||
Thread.sleep(1500); | |||
} catch (InterruptedException e) { | |||
} | |||
|
|||
final Payment updatedPayment = paymentApi.getPayment(payment.getId(), false, ImmutableList.<PluginProperty>of(), callContext); | |||
assertEquals(updatedPayment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.SUCCESS); | |||
|
|
||
} | } | ||
|
|
||
|
|
||
|
|
||
@Test(groups = "slow") | |||
public void testPendingEntries() throws PaymentApiException, InvoiceApiException, EventBusException { | |||
|
|||
final BigDecimal requestedAmount = BigDecimal.TEN; | |||
final String paymentExternalKey = "jhj44"; | |||
final String transactionExternalKey = "4jhjj2"; | |||
|
|||
final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), paymentExternalKey, | |||
transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext); | |||
|
|||
// Artificially move the transaction status to PENDING | |||
final String paymentStateName = paymentSMHelper.getPendingStateForTransaction(TransactionType.AUTHORIZE).toString(); | |||
paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, | |||
payment.getTransactions().get(0).getId(), TransactionStatus.PENDING, requestedAmount, account.getCurrency(), | |||
"loup", "chat", internalCallContext); | |||
clock.addDays(1); | |||
try { | |||
Thread.sleep(1500); | |||
} catch (InterruptedException e) { | |||
} | |||
|
|||
final Payment updatedPayment = paymentApi.getPayment(payment.getId(), false, ImmutableList.<PluginProperty>of(), callContext); | |||
Assert.assertEquals(updatedPayment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.PAYMENT_FAILURE); | |||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
|||
|
|||
} | |||
|
|||
private List<PluginProperty> createPropertiesForInvoice(final Invoice invoice) { | private List<PluginProperty> createPropertiesForInvoice(final Invoice invoice) { | ||
final List<PluginProperty> result = new ArrayList<PluginProperty>(); | final List<PluginProperty> result = new ArrayList<PluginProperty>(); | ||
result.add(new PluginProperty(InvoicePaymentRoutingPluginApi.PROP_IPCD_INVOICE_ID, invoice.getId().toString(), false)); | result.add(new PluginProperty(InvoicePaymentRoutingPluginApi.PROP_IPCD_INVOICE_ID, invoice.getId().toString(), false)); | ||
|
Nit: extra
;
.