Search in sources :

Example 1 with StripePayout

use of uk.gov.pay.connector.gateway.stripe.json.StripePayout in project pay-connector by alphagov.

the class PayoutReconcileProcess method emitPayoutCreatedEvent.

private void emitPayoutCreatedEvent(PayoutReconcileMessage payoutReconcileMessage, BalanceTransaction balanceTransaction) {
    Payout payoutObject = (Payout) balanceTransaction.getSourceObject();
    StripePayout stripePayout = StripePayout.from(payoutObject);
    payoutEmitterService.emitPayoutEvent(PayoutCreated.class, stripePayout.getCreated(), payoutReconcileMessage.getConnectAccountId(), stripePayout);
    emitTerminalPayoutEvent(payoutReconcileMessage.getConnectAccountId(), stripePayout);
}
Also used : Payout(com.stripe.model.Payout) PaymentIncludedInPayout(uk.gov.pay.connector.events.model.charge.PaymentIncludedInPayout) StripePayout(uk.gov.pay.connector.gateway.stripe.json.StripePayout) RefundIncludedInPayout(uk.gov.pay.connector.events.model.refund.RefundIncludedInPayout) StripePayout(uk.gov.pay.connector.gateway.stripe.json.StripePayout)

Example 2 with StripePayout

use of uk.gov.pay.connector.gateway.stripe.json.StripePayout in project pay-connector by alphagov.

the class PayoutEmitterServiceTest method setUp.

@Before
public void setUp() {
    GatewayAccountEntity gatewayAccountEntity = GatewayAccountEntityFixture.aGatewayAccountEntity().withId(1234L).build();
    when(mockConnectorConfiguration.getEmitPayoutEvents()).thenReturn(true);
    when(mockGatewayAccountCredentialsService.findStripeGatewayAccountForCredentialKeyAndValue(STRIPE_ACCOUNT_ID_KEY, connectAccount)).thenReturn(gatewayAccountEntity);
    payoutEmitterService = new PayoutEmitterService(mockEventService, mockConnectorConfiguration, mockGatewayAccountCredentialsService);
    payout = new StripePayout("po_123", 1213L, 1589846400L, null, "pending", "card", null);
}
Also used : GatewayAccountEntity(uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity) StripePayout(uk.gov.pay.connector.gateway.stripe.json.StripePayout) Before(org.junit.Before)

Example 3 with StripePayout

use of uk.gov.pay.connector.gateway.stripe.json.StripePayout in project pay-connector by alphagov.

the class PayoutReconcileProcessTest method shouldEmitAdditionalPayoutFailedEventIfPayoutStatusIsFailed.

@Test
public void shouldEmitAdditionalPayoutFailedEventIfPayoutStatusIsFailed() throws Exception {
    PayoutReconcileMessage payoutReconcileMessage = setupQueueMessage();
    ArgumentCaptor<Class<? extends PayoutEvent>> captor = ArgumentCaptor.forClass(Class.class);
    ArgumentCaptor<StripePayout> captorForStripePayout = ArgumentCaptor.forClass(StripePayout.class);
    setupMockBalanceTransactions("failed");
    when(connectorConfiguration.getEmitPayoutEvents()).thenReturn(true);
    payoutReconcileProcess.processPayouts();
    verify(payoutEmitterService, times(2)).emitPayoutEvent(captor.capture(), any(), any(), captorForStripePayout.capture());
    StripePayout stripePayoutForFailedEvent = captorForStripePayout.getAllValues().get(1);
    assertThat(captor.getAllValues().get(0), is(PayoutCreated.class));
    assertThat(captor.getAllValues().get(1), is(PayoutFailed.class));
    assertThat(stripePayoutForFailedEvent.getFailureCode(), is("account_closed"));
    assertThat(stripePayoutForFailedEvent.getFailureMessage(), is("The bank account has been closed"));
    assertThat(stripePayoutForFailedEvent.getFailureBalanceTransaction(), is("ba_1GkZtqDv3CZEaFO2CQhLrluk"));
    verify(payoutReconcileQueue).markMessageAsProcessed(payoutReconcileMessage.getQueueMessage());
}
Also used : PayoutEvent(uk.gov.pay.connector.events.model.payout.PayoutEvent) PayoutFailed(uk.gov.pay.connector.events.model.payout.PayoutFailed) StripePayout(uk.gov.pay.connector.gateway.stripe.json.StripePayout) PayoutCreated(uk.gov.pay.connector.events.model.payout.PayoutCreated) PayoutReconcileMessage(uk.gov.pay.connector.queue.payout.PayoutReconcileMessage) Test(org.junit.Test)

Example 4 with StripePayout

use of uk.gov.pay.connector.gateway.stripe.json.StripePayout in project pay-connector by alphagov.

the class PayoutUpdatedTest method shouldSerializePayoutUpdatedEventWithCorrectEventDetails.

@Test
public void shouldSerializePayoutUpdatedEventWithCorrectEventDetails() throws JsonProcessingException {
    StripePayout payout = new StripePayout("po_123", 1000L, 1589395533L, 1589395500L, "pending", "card", "SERVICE NAME");
    String payoutEventJson = PayoutUpdated.from(parse("2020-05-13T18:45:33Z"), payout).toJsonString();
    assertThat(payoutEventJson, hasJsonPath("$.event_type", equalTo("PAYOUT_UPDATED")));
    assertThat(payoutEventJson, hasJsonPath("$.resource_type", equalTo("payout")));
    assertThat(payoutEventJson, hasJsonPath("$.resource_external_id", equalTo(payout.getId())));
    assertThat(payoutEventJson, hasJsonPath("$.timestamp", equalTo("2020-05-13T18:45:33.000000Z")));
    assertThat(payoutEventJson, hasJsonPath("$.event_details.gateway_status", equalTo(payout.getStatus())));
}
Also used : StripePayout(uk.gov.pay.connector.gateway.stripe.json.StripePayout) Test(org.junit.Test)

Example 5 with StripePayout

use of uk.gov.pay.connector.gateway.stripe.json.StripePayout in project pay-connector by alphagov.

the class QueueMessageContractTest method verifyPayoutFailedEvent.

@PactVerifyProvider("a payout failed message")
public String verifyPayoutFailedEvent() throws JsonProcessingException {
    StripePayout payout = new StripePayout("po_failed_1234567890", "failed", "account_closed", "The bank account has been closed", "ba_aaaaaaaaaa");
    PayoutFailed payoutFailed = PayoutFailed.from(parse("2020-05-13T18:50:00Z"), payout);
    return payoutFailed.toJsonString();
}
Also used : PayoutFailed(uk.gov.pay.connector.events.model.payout.PayoutFailed) StripePayout(uk.gov.pay.connector.gateway.stripe.json.StripePayout) PactVerifyProvider(au.com.dius.pact.provider.PactVerifyProvider)

Aggregations

StripePayout (uk.gov.pay.connector.gateway.stripe.json.StripePayout)15 Test (org.junit.Test)7 PactVerifyProvider (au.com.dius.pact.provider.PactVerifyProvider)4 PayoutFailed (uk.gov.pay.connector.events.model.payout.PayoutFailed)3 PaymentIncludedInPayout (uk.gov.pay.connector.events.model.charge.PaymentIncludedInPayout)2 PayoutCreated (uk.gov.pay.connector.events.model.payout.PayoutCreated)2 PayoutEvent (uk.gov.pay.connector.events.model.payout.PayoutEvent)2 RefundIncludedInPayout (uk.gov.pay.connector.events.model.refund.RefundIncludedInPayout)2 PayoutReconcileMessage (uk.gov.pay.connector.queue.payout.PayoutReconcileMessage)2 Payout (com.stripe.model.Payout)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Before (org.junit.Before)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 PayoutFailedEventDetails (uk.gov.pay.connector.events.eventdetails.payout.PayoutFailedEventDetails)1 PayoutPaid (uk.gov.pay.connector.events.model.payout.PayoutPaid)1 PayoutUpdated (uk.gov.pay.connector.events.model.payout.PayoutUpdated)1 GatewayAccountEntity (uk.gov.pay.connector.gatewayaccount.model.GatewayAccountEntity)1 Payout (uk.gov.pay.connector.queue.payout.Payout)1