BACKLOG-14: fix 3ds20 user interaction type, use github actions

This commit is contained in:
mr-impossibru 2022-01-11 16:50:00 +03:00 committed by Vasil Khramov
parent 66987df223
commit e59be63a8c
No known key found for this signature in database
GPG Key ID: 1B6B98F47B5EC1C1
15 changed files with 150 additions and 69 deletions

26
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,26 @@
name: Build Artifact
on:
pull_request:
branches:
- '*'
jobs:
build:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Checkout GitHub Action Repo
uses: actions/checkout@v2
with:
repository: valitydev/action-jdk-build
ref: v1.0.18
path: .github/actions/action-jdk-build
- name: Run Build Java
uses: ./.github/actions/action-jdk-build
with:
github-pat: '${{ secrets.GH_PACKAGES_RO_PAT }}'
github-user: 'strug'

46
.github/workflows/deploy.yml vendored Normal file
View File

@ -0,0 +1,46 @@
name: Deploy Docker Image
on:
push:
branches:
- 'master'
- 'main'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-deploy:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Checkout GitHub Action JDK Build Repo
uses: actions/checkout@v2
with:
repository: valitydev/action-jdk-build
ref: v1.0.18
path: .github/actions/action-jdk-build
- name: Checkout GitHub Action Deploy Docker Repo
uses: actions/checkout@v2
with:
repository: valitydev/action-deploy-docker
ref: v1.0.16
path: .github/actions/action-deploy-docker
- name: Run Build Java
uses: ./.github/actions/action-jdk-build
with:
github-pat: '${{ secrets.GH_PACKAGES_RO_PAT }}'
github-user: 'strug'
- name: Deploy image
uses: ./.github/actions/action-deploy-docker
with:
registry-username: ${{ github.actor }}
registry-access-token: ${{ secrets.GITHUB_TOKEN }}
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "build_utils"]
path = build_utils
url = git@github.com:rbkmoney/build_utils.git
branch = master

15
Jenkinsfile vendored
View File

@ -1,15 +0,0 @@
#!groovy
build('proxy-mocketbank', 'java-maven') {
checkoutRepo()
loadBuildUtils()
def javaServicePipeline
runStage('load JavaService pipeline') {
javaServicePipeline = load("build_utils/jenkins_lib/pipeJavaServiceInsideDocker.groovy")
}
def serviceName = env.REPO_NAME
def mvnArgs = '-DjvmArgs="-Xmx256m"'
javaServicePipeline(serviceName, mvnArgs)
}

View File

@ -1,7 +1,5 @@
# Адаптер для заглушек
[![Build Status](http://ci.rbkmoney.com/buildStatus/icon?job=rbkmoney_private/proxy-mocketbank/master)](http://ci.rbkmoney.com/job/rbkmoney_private/proxy-mocketbank/master)
Сервис предназначен для эмулирования запросов между различными системами

@ -1 +0,0 @@
Subproject commit a87ebf3ae5e56910dc6a0edcac7f90565368a3d1

View File

@ -9,7 +9,7 @@
**adapter-mock-bank.pathCallbackUrl** | Путь для URL адаптера на который будет возвращен ответ с результатом проверки 3DS со стороны банка | /mocketbank/term_url{?termination_uri}
**adapter-mock-bank.pathRecurrentCallbackUrl** | Путь для URL адаптера на который будет возвращен ответ с результатом проверки 3DS со стороны банка | /mocketbank/rec_term_url{?termination_uri}
**adapter-mock-bank.pathQpsCallbackUrl** | Путь для URL адаптера на который будет возвращен ответ при взаимодействии с qps | /mocketbank/qps
**adapter-mock-bank.finishInteraction** | Заглушка для чекаута | https://checkout.rbk.money/v1/finish-interaction.html
**adapter-mock-bank.finishInteraction** | Заглушка для чекаута | https://example.com/v1/finish-interaction.html
**adapter-mock-mpi.url** | url для взаимодействия с заглушкой mpi | http://127.0.0.1:8079
---

View File

@ -11,7 +11,7 @@
</parent>
<artifactId>proxy-mocketbank</artifactId>
<version>2.0.0-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>proxy-mocketbank</name>
@ -24,8 +24,8 @@
<exposed.ports>${server.port} ${server.rest.port} ${management.port}</exposed.ports>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.maintainer>Anatoly Cherkasov &lt;a.cherkasov@rbkmoney.com&gt;</project.maintainer>
<dockerfile.base.service.tag>c0612d6052ac049496b72a23a04acb142035f249</dockerfile.base.service.tag>
<dockerfile.registry>dr2.rbkmoney.com</dockerfile.registry>
<dockerfile.base.service.tag>7e0c98bb</dockerfile.base.service.tag>
<shared-resources.version>1.4.0</shared-resources.version>
<cds-proto.version>1.64-74a763b</cds-proto.version>
</properties>
@ -70,6 +70,7 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>shared-resources</artifactId>
<version>${shared-resources.version}</version>
</dependency>
<dependency>
<groupId>com.rbkmoney</groupId>

View File

@ -5,7 +5,6 @@ import com.rbkmoney.cds.client.storage.exception.CdsStorageExpDateException;
import com.rbkmoney.damsel.domain.*;
import com.rbkmoney.damsel.proxy_provider.*;
import com.rbkmoney.damsel.timeout_behaviour.TimeoutBehaviour;
import com.rbkmoney.damsel.user_interaction.UserInteraction;
import com.rbkmoney.error.mapping.ErrorMapping;
import com.rbkmoney.java.cds.utils.model.CardDataProxyModel;
import com.rbkmoney.java.damsel.constant.Error;
@ -20,6 +19,7 @@ import com.rbkmoney.proxy.mocketbank.service.mpi20.processor.Mpi20Processor;
import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils;
import com.rbkmoney.proxy.mocketbank.utils.ErrorBuilder;
import com.rbkmoney.proxy.mocketbank.utils.UrlUtils;
import com.rbkmoney.proxy.mocketbank.utils.UserInteractionUtils;
import com.rbkmoney.proxy.mocketbank.utils.model.Card;
import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import com.rbkmoney.proxy.mocketbank.utils.model.CardUtils;
@ -91,7 +91,7 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler {
if (CardAction.isCardEnrolled(card.get())) {
return prepareEnrolledPaymentProxyResult(context, intent, transactionInfo, cardData, action);
} else if (CardAction.isCardEnrolled20(card.get())) {
return mpi20Processor.processPrepare(context);
return mpi20Processor.processPrepare(context, action);
}
return prepareNotEnrolledPaymentProxyResult(intent, transactionInfo, action);
}
@ -147,20 +147,11 @@ public class ProcessedCommonPaymentHandler implements CommonPaymentHandler {
int timerRedirectTimeout = extractRedirectTimeout(options, timerProperties.getRedirectTimeout());
Intent intent = createIntentWithSuspendIntent(
tag, timerRedirectTimeout, prepareUserInteraction(url, params, action)
tag, timerRedirectTimeout, UserInteractionUtils.prepareUserInteraction(url, params, action)
);
Failure failure = errorMapping.mapFailure(DEFAULT_ERROR_CODE, THREE_DS_NOT_FINISHED);
intent.getSuspend().setTimeoutBehaviour(TimeoutBehaviour.operation_failure(OperationFailure.failure(failure)));
return intent;
}
private UserInteraction prepareUserInteraction(String url,
Map<String, String> params,
CardAction action) {
if (CardAction.isGetAcsCard(action)) {
return createGetUserInteraction(UrlUtils.prepareUrlWithParams(url, params));
}
return createPostUserInteraction(url, params);
}
}

View File

@ -11,6 +11,8 @@ import lombok.SneakyThrows;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;
import static com.rbkmoney.proxy.mocketbank.service.mpi20.constant.CallbackResponseFields.TERMINATION_URI;
@Component
@RequiredArgsConstructor
public class CtxToPreparationConverter implements Converter<PaymentContext, PreparationRequest> {
@ -26,9 +28,20 @@ public class CtxToPreparationConverter implements Converter<PaymentContext, Prep
return PreparationRequest.builder()
.pan(cardData.getPan())
.notificationUrl(UrlUtils.getCallbackUrl(
mpi20Properties.getCallbackUrl(),
mpi20Properties.getThreeDsMethodNotificationPath()))
.notificationUrl(getNotificationUrl(context))
.build();
}
private String getNotificationUrl(PaymentContext context) {
String terminationUri = UrlUtils.hasRedirectUrl(context.getPaymentInfo().getPayment())
? context.getPaymentInfo().getPayment().getPayerSessionInfo().getRedirectUrl()
: mpi20Properties.getReturnUrl();
return UrlUtils.getCallbackUrl(
mpi20Properties.getCallbackUrl(),
mpi20Properties.getThreeDsMethodNotificationPath(),
TERMINATION_URI,
terminationUri
);
}
}

View File

@ -9,7 +9,8 @@ import com.rbkmoney.proxy.mocketbank.service.mpi20.converter.*;
import com.rbkmoney.proxy.mocketbank.service.mpi20.model.Error;
import com.rbkmoney.proxy.mocketbank.service.mpi20.model.*;
import com.rbkmoney.proxy.mocketbank.utils.CreatorUtils;
import com.rbkmoney.proxy.mocketbank.utils.UrlUtils;
import com.rbkmoney.proxy.mocketbank.utils.UserInteractionUtils;
import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import com.rbkmoney.proxy.mocketbank.utils.state.constant.SuspendPrefix;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
@ -36,13 +37,14 @@ public class Mpi20Processor {
private final TimerProperties timerProperties;
@SneakyThrows
public PaymentProxyResult processPrepare(PaymentContext context) {
public PaymentProxyResult processPrepare(PaymentContext context, CardAction cardAction) {
PreparationRequest request = ctxToPreparationConverter.convert(context);
PreparationResponse response = mpi20Client.prepare(request);
Intent intent = buildPrepareIntent(
request,
response,
extractRedirectTimeout(context.getOptions(), timerProperties.getRedirectTimeout()));
extractRedirectTimeout(context.getOptions(), timerProperties.getRedirectTimeout()),
cardAction);
SessionState sessionState = null;
if (intent.isSetSuspend()) {
sessionState = new SessionState(
@ -95,13 +97,18 @@ public class Mpi20Processor {
private Intent buildPrepareIntent(PreparationRequest request,
PreparationResponse response,
int timerRedirectTimeout) {
int timerRedirectTimeout,
CardAction cardAction) {
if (isPreparationSuccess(response)) {
String tag = SuspendPrefix.PAYMENT.getPrefix() + response.getThreeDSServerTransID();
Map<String, String> params = Map.of(
THREE_DS_METHOD_DATA, response.getThreeDSMethodData(),
TERM_URL, request.getNotificationUrl());
UserInteraction interaction = createPostUserInteraction(response.getThreeDSMethodURL(), params);
UserInteraction interaction = UserInteractionUtils.prepareUserInteraction(
response.getThreeDSMethodURL(),
params,
cardAction
);
return createIntentWithSuspendIntent(tag, timerRedirectTimeout, interaction);
} else {
return createFinishIntentSuccess();

View File

@ -8,7 +8,6 @@ import freemarker.template.TemplateException;
import lombok.RequiredArgsConstructor;
import org.apache.commons.text.StringEscapeUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;
import java.io.IOException;
import java.util.Map;
@ -34,7 +33,7 @@ public class CallbackResponseWithTemplateCreator {
String terminationUri = UrlUtils.hasRedirectUrl(context.getPaymentInfo().getPayment())
? context.getPaymentInfo().getPayment().getPayerSessionInfo().getRedirectUrl()
: mpi20Properties.getReturnUrl();
String acsTermUrl = createCallbackUrlWithParam(
String acsTermUrl = UrlUtils.getCallbackUrl(
mpi20Properties.getCallbackUrl(),
mpi20Properties.getAcsNotificationPath(),
TERMINATION_URI,
@ -53,13 +52,4 @@ public class CallbackResponseWithTemplateCreator {
}
}
public static String createCallbackUrlWithParam(String callbackUrl, String path, String paramName,
String paramValue) {
return UriComponentsBuilder.fromUriString(callbackUrl)
.path(path)
.queryParam(paramName, paramValue)
.build()
.toUriString();
}
}

View File

@ -25,6 +25,20 @@ public class UrlUtils {
.toUriString();
}
public static String getCallbackUrl(String callbackUrl, String path, String paramName, String paramValue) {
return UriComponentsBuilder.fromUriString(callbackUrl)
.path(path)
.queryParam(paramName, paramValue)
.build()
.toUriString();
}
public static String getCallbackUrl(String url, Map<String, String> params) {
MultiValueMap<String, String> multiValueMapParams = new LinkedMultiValueMap<>();
multiValueMapParams.setAll(params);
return getCallbackUrl(url, null, multiValueMapParams);
}
public static String getCallbackUrl(String callbackUrl, String path, MultiValueMap<String, String> params) {
return UriComponentsBuilder.fromUriString(callbackUrl)
.path(path)
@ -51,15 +65,6 @@ public class UrlUtils {
return param;
}
public static String prepareUrlWithParams(String url, Map<String, String> params) {
MultiValueMap<String, String> multiValueMapParams = new LinkedMultiValueMap<>();
multiValueMapParams.setAll(params);
return UriComponentsBuilder.fromUriString(url)
.queryParams(multiValueMapParams)
.build()
.toUriString();
}
public static boolean hasRedirectUrl(InvoicePayment payment) {
return payment != null && payment.isSetPayerSessionInfo()
&& StringUtils.hasText(payment.getPayerSessionInfo().getRedirectUrl());

View File

@ -0,0 +1,24 @@
package com.rbkmoney.proxy.mocketbank.utils;
import com.rbkmoney.damsel.user_interaction.UserInteraction;
import com.rbkmoney.proxy.mocketbank.utils.model.CardAction;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import java.util.Map;
import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.createGetUserInteraction;
import static com.rbkmoney.java.damsel.utils.creators.ProxyProviderPackageCreators.createPostUserInteraction;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UserInteractionUtils {
public static UserInteraction prepareUserInteraction(String url,
Map<String, String> params,
CardAction action) {
if (CardAction.isGetAcsCard(action)) {
return createGetUserInteraction(UrlUtils.getCallbackUrl(url, params));
}
return createPostUserInteraction(url, params);
}
}

View File

@ -43,9 +43,9 @@ adapter-mock-mpi:
mpi20:
threeDsServerUrl: http://127.0.0.1:8018
callbackUrl: http://127.0.0.1:8019
threeDsMethodNotificationPath: /${server.rest.endpoint}/three_ds_method_notification{?termination_uri}
threeDsMethodNotificationPath: /${server.rest.endpoint}/three_ds_method_notification
acsNotificationPath: /${server.rest.endpoint}/acs_notification
returnUrl: https://checkout.rbk.money/v1/finish-interaction.html
returnUrl: https://example.com/v1/finish-interaction.html
---
adapter-mock-bank:
callbackUrl: http://127.0.0.1:8019
@ -53,7 +53,7 @@ adapter-mock-bank:
pathRecurrentCallbackUrl: /${server.rest.endpoint}/rec_term_url{?termination_uri}
pathQpsCallbackUrl: /${server.rest.endpoint}/qps
pathDigitalWalletCallbackUrl: /${server.rest.endpoint}/dw
finishInteraction: https://checkout.rbk.money/v1/finish-interaction.html
finishInteraction: https://example.com/v1/finish-interaction.html
---
cds:
client: