Search in sources :

Example 6 with AccountReference

use of net.petafuel.styx.core.xs2a.entities.AccountReference in project styx by petafuel.

the class SparkassePISIntegrationTest method test_INIT_SCTSinglePayment_SCA_OAUTH.

@Category(IntegrationTest.class)
@ParameterizedTest
@ArgumentsSource(SparkassePSUProvider.class)
void test_INIT_SCTSinglePayment_SCA_OAUTH(String psuBic, String psuId, String creditorIban, String debtorIban) {
    Assume.assumeNotNull(PIS_TOKEN);
    SinglePayment singlePayment = new SinglePayment();
    singlePayment.setDebtorAccount(new AccountReference(debtorIban, AccountReference.Type.IBAN));
    singlePayment.setCreditorAccount(new AccountReference(creditorIban, AccountReference.Type.IBAN));
    singlePayment.setInstructedAmount(new Amount("0.01"));
    singlePayment.setCreditorName(psuId);
    singlePayment.setRemittanceInformationUnstructured("Styx PIS Test unixstamp: " + new Date().getTime());
    SinglePaymentInitiation singlePaymentInitiation = new SinglePaymentInitiation();
    singlePaymentInitiation.setPayments(Collections.singletonList(singlePayment));
    given().contentType(ContentType.JSON).header("token", PIS_TOKEN).header("psu-id", psuId).header("psu-bic", psuBic).header("redirectPreferred", "true").body(singlePaymentInitiation).post("/v1/payments/sepa-credit-transfers").then().assertThat().header("content-type", Matchers.containsString("application/json")).statusCode(201).body("transactionStatus", Matchers.is(TransactionStatus.RCVD.name())).body("paymentId", Matchers.notNullValue()).body("links.scaOAuth.href", Matchers.notNullValue());
}
Also used : SinglePaymentInitiation(net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation) Amount(net.petafuel.styx.core.xs2a.entities.Amount) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) Date(java.util.Date) Category(org.junit.experimental.categories.Category) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 7 with AccountReference

use of net.petafuel.styx.core.xs2a.entities.AccountReference in project styx by petafuel.

the class SparkassePISIntegrationTest method test_INIT_SCTSinglePayment_SCA_EMBEDDED.

@Category(IntegrationTest.class)
@ParameterizedTest
@ArgumentsSource(SparkassePSUProvider.class)
void test_INIT_SCTSinglePayment_SCA_EMBEDDED(String psuBic, String psuId, String creditorIban, String debtorIban) {
    Assume.assumeNotNull(PIS_TOKEN);
    SinglePayment singlePayment = new SinglePayment();
    singlePayment.setDebtorAccount(new AccountReference(debtorIban, AccountReference.Type.IBAN));
    singlePayment.setCreditorAccount(new AccountReference(creditorIban, AccountReference.Type.IBAN));
    singlePayment.setInstructedAmount(new Amount("0.01"));
    singlePayment.setCreditorName(psuId);
    singlePayment.setRemittanceInformationUnstructured("Styx PIS Test unixstamp: " + new Date().getTime());
    SinglePaymentInitiation singlePaymentInitiation = new SinglePaymentInitiation();
    singlePaymentInitiation.setPayments(Collections.singletonList(singlePayment));
    given().contentType(ContentType.JSON).header("token", PIS_TOKEN).header("psu-id", psuId).header("psu-bic", psuBic).header("redirectPreferred", "false").body(singlePaymentInitiation).post("/v1/payments/sepa-credit-transfers").then().assertThat().header("content-type", Matchers.containsString("application/json")).statusCode(201).body("transactionStatus", Matchers.is(TransactionStatus.RCVD.name())).body("paymentId", Matchers.notNullValue()).body("links.startAuthorisationWithPsuAuthentication.href", Matchers.notNullValue());
}
Also used : SinglePaymentInitiation(net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation) Amount(net.petafuel.styx.core.xs2a.entities.Amount) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) Date(java.util.Date) Category(org.junit.experimental.categories.Category) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 8 with AccountReference

use of net.petafuel.styx.core.xs2a.entities.AccountReference in project styx by petafuel.

the class PaymentInitiationResource method initiateBulkPayment.

/**
 * Initiate multiple payments as bulk
 *
 * @param paymentTypeBean contains which payment product is used
 * @param bulkPaymentBody contains the request body as parsed json
 * @return 201 if successful
 * @throws BankRequestFailedException in case the communication between styx and aspsp was not successful
 */
@POST
@Path("/bulk-payments/{paymentProduct}")
@RequiresMandatoryHeader
@AcceptsPreStepAuth
public Response initiateBulkPayment(@BeanParam PaymentTypeBean paymentTypeBean, @Valid BulkPaymentInitiation bulkPaymentBody) throws BankRequestFailedException {
    // Debtors should all be the same within the payments, we take one of them
    Optional<SinglePayment> singlePayment = bulkPaymentBody.getPayments().stream().findAny();
    if (!singlePayment.isPresent()) {
        throw new StyxException(new ResponseEntity("No valid payment object was found within the bulk payments array", ResponseConstant.BAD_REQUEST, ResponseCategory.ERROR, ResponseOrigin.CLIENT));
    }
    AccountReference debtor = bulkPaymentBody.getDebtorAccount();
    BulkPayment bulkPayment = new BulkPayment();
    bulkPayment.setBatchBookingPreferred(bulkPaymentBody.getBatchBookingPreferred());
    bulkPayment.setDebtorAccount(debtor);
    bulkPayment.setPayments(bulkPaymentBody.getPayments());
    bulkPayment.setRequestedExecutionDate(bulkPaymentBody.getRequestedExecutionDate());
    XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
    xs2AFactoryInput.setPayment(bulkPayment);
    xs2AFactoryInput.setPsu(getPsu());
    xs2AFactoryInput.setPaymentService(PaymentService.BULK_PAYMENTS);
    xs2AFactoryInput.setPaymentProduct(paymentTypeBean.getPaymentProduct());
    IOProcessor ioProcessor = new IOProcessor(getXS2AStandard());
    ioProcessor.modifyInput(xs2AFactoryInput);
    PISRequest bulkpaymentInitiationRequest = new PISRequestFactory().create(getXS2AStandard().getRequestClassProvider().paymentInitiation(), xs2AFactoryInput);
    bulkpaymentInitiationRequest.getHeaders().putAll(getAdditionalHeaders());
    ioProcessor.modifyRequest(bulkpaymentInitiationRequest, xs2AFactoryInput);
    bulkpaymentInitiationRequest.setTppRedirectPreferred(getRedirectPreferred());
    bulkpaymentInitiationRequest.setXrequestId(ThreadContext.get(RequestUUIDAdapter.REQUEST_UUID));
    InitiatedPayment initiatedPayment = getXS2AStandard().getPis().initiatePayment(bulkpaymentInitiationRequest);
    PaymentResponse paymentResponse = new PaymentResponse(initiatedPayment);
    SCAApproach approach = SCAHandler.decision(initiatedPayment);
    if (approach instanceof OAuth2) {
        paymentResponse.getLinks().getScaOAuth().setUrl(((OAuth2) approach).getAuthoriseLink());
    }
    LOG.info("Initiate bulk payment bic={} aspsp_name={} aspsp_id={} paymentId={}", getXS2AStandard().getAspsp().getBic(), getXS2AStandard().getAspsp().getName(), getXS2AStandard().getAspsp().getId(), paymentResponse.getPaymentId());
    AspspUrlMapper aspspUrlMapper = new AspspUrlMapper(PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct(), paymentResponse.getPaymentId(), null);
    paymentResponse.setLinks(aspspUrlMapper.map(paymentResponse.getLinks()));
    PersistentPayment.create(bulkpaymentInitiationRequest.getXrequestId(), paymentResponse.getPaymentId(), (String) getContainerRequestContext().getProperty(AbstractTokenFilter.class.getName()), getXS2AStandard().getAspsp().getBic(), paymentResponse.getTransactionStatus(), PaymentService.BULK_PAYMENTS, paymentTypeBean.getPaymentProduct());
    return Response.status(ResponseConstant.CREATED).entity(paymentResponse).build();
}
Also used : OAuth2(net.petafuel.styx.core.xs2a.sca.OAuth2) SCAApproach(net.petafuel.styx.core.xs2a.sca.SCAApproach) AspspUrlMapper(net.petafuel.styx.api.util.AspspUrlMapper) BulkPayment(net.petafuel.styx.core.xs2a.entities.BulkPayment) SinglePayment(net.petafuel.styx.core.xs2a.entities.SinglePayment) StyxException(net.petafuel.styx.api.exception.StyxException) PaymentResponse(net.petafuel.styx.api.v1.payment.entity.PaymentResponse) ResponseEntity(net.petafuel.styx.api.exception.ResponseEntity) PISRequest(net.petafuel.styx.core.xs2a.contracts.PISRequest) PISRequestFactory(net.petafuel.styx.core.xs2a.factory.PISRequestFactory) AbstractTokenFilter(net.petafuel.styx.api.filter.authentication.control.AbstractTokenFilter) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) InitiatedPayment(net.petafuel.styx.core.xs2a.entities.InitiatedPayment) AccountReference(net.petafuel.styx.core.xs2a.entities.AccountReference) IOProcessor(net.petafuel.styx.core.ioprocessing.IOProcessor) Path(javax.ws.rs.Path) AcceptsPreStepAuth(net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth) RequiresMandatoryHeader(net.petafuel.styx.api.filter.input.boundary.RequiresMandatoryHeader) POST(javax.ws.rs.POST)

Aggregations

AccountReference (net.petafuel.styx.core.xs2a.entities.AccountReference)8 Amount (net.petafuel.styx.core.xs2a.entities.Amount)6 SinglePayment (net.petafuel.styx.core.xs2a.entities.SinglePayment)5 Date (java.util.Date)4 SinglePaymentInitiation (net.petafuel.styx.api.v1.payment.entity.SinglePaymentInitiation)3 Category (org.junit.experimental.categories.Category)3 SimpleDateFormat (java.text.SimpleDateFormat)2 PaymentResponse (net.petafuel.styx.api.v1.payment.entity.PaymentResponse)2 BulkPayment (net.petafuel.styx.core.xs2a.entities.BulkPayment)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Jsonb (javax.json.bind.Jsonb)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Invocation (javax.ws.rs.client.Invocation)1 Response (javax.ws.rs.core.Response)1