Skip to content

Commit

Permalink
implements Stripe provider
Browse files Browse the repository at this point in the history
  • Loading branch information
fupelaqu committed Jul 31, 2024
1 parent 7b15367 commit ebaec7e
Show file tree
Hide file tree
Showing 94 changed files with 8,831 additions and 1,816 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ trait SoftPayApi[SD <: SessionData with SessionDataDecorator[SD]] extends SoftPa
override implicit def companion: SessionDataCompanion[SD] = self.companion
override val applicationVersion: String = systemVersion()
override val swaggerUIOptions: SwaggerUIOptions =
SwaggerUIOptions.default.pathPrefix(List("swagger", PaymentSettings.PaymentPath))
SwaggerUIOptions.default.pathPrefix(List("swagger", PaymentSettings.PaymentConfig.path))
}

def accountSwagger: ActorSystem[_] => SwaggerEndpoint = sys =>
Expand Down
8 changes: 7 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ThisBuild / organization := "app.softnetwork"

name := "payment"

ThisBuild / version := "0.6.1.1"
ThisBuild / version := "0.7.0-SNAPSHOT"

ThisBuild / scalaVersion := "2.12.18"

Expand Down Expand Up @@ -71,13 +71,19 @@ lazy val api = project.in(file("api"))
.dependsOn(
mangopay % "compile->compile;test->test;it->it"
)
.dependsOn(
stripe % "compile->compile;test->test;it->it"
)

lazy val testkit = project.in(file("testkit"))
.configs(IntegrationTest)
.settings(Defaults.itSettings)
.dependsOn(
mangopay % "compile->compile;test->test;it->it"
)
.dependsOn(
stripe % "compile->compile;test->test;it->it"
)

lazy val root = project.in(file("."))
.aggregate(client, common, core, mangopay, stripe, testkit, api)
Expand Down
16 changes: 16 additions & 0 deletions client/src/main/protobuf/api/payment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ service PaymentServiceApi {
rpc CancelMandate (CancelMandateRequest) returns (CancelMandateResponse) {}
rpc LoadBankAccountOwner (LoadBankAccountOwnerRequest) returns (LoadBankAccountOwnerResponse) {}
rpc LoadLegalUser(LoadLegalUserRequest) returns (LoadLegalUserResponse) {}
rpc LoadPayInTransaction(LoadPayInTransactionRequest) returns (TransactionResponse) {}
rpc LoadPayOutTransaction (LoadPayOutTransactionRequest) returns (TransactionResponse) {}
}

message CreateOrUpdatePaymentAccountRequest {
Expand All @@ -49,6 +51,7 @@ enum TransactionStatus{
TRANSACTION_FAILED = 2;
TRANSACTION_NOT_SPECIFIED = 4;
TRANSACTION_FAILED_FOR_TECHNICAL_REASON = 5;
TRANSACTION_CANCELED = 6;
}

message TransactionResponse {
Expand Down Expand Up @@ -85,6 +88,7 @@ message PayOutRequest {
string currency = 5;
google.protobuf.StringValue externalReference = 6;
string clientId = 7;
google.protobuf.StringValue payInTransactionId = 8;
}

message TransferRequest {
Expand Down Expand Up @@ -195,3 +199,15 @@ message LoadLegalUserResponse {
app.softnetwork.payment.model.Address legalRepresentativeAddress = 4;
app.softnetwork.payment.model.Address headQuartersAddress = 5;
}

message LoadPayInTransactionRequest {
string orderUuid = 1;
string payInTransactionId = 2;
string clientId = 3;
}

message LoadPayOutTransactionRequest {
string orderUuid = 1;
string payOutTransactionId = 2;
string clientId = 3;
}
2 changes: 2 additions & 0 deletions client/src/main/protobuf/model/payment/card.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ message Card {
required string alias = 5;
required string expirationDate = 6;
optional bool active = 7;
optional string holderName = 8;
optional string brand = 9;
}

message CardOwner {
Expand Down
8 changes: 8 additions & 0 deletions client/src/main/protobuf/model/payment/document.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ message KycDocument {
* proof of address
*/
KYC_ADDRESS_PROOF = 4;
/**
* additional requirement
*/
KYC_ADDITIONAL_REQUIREMENT = 5;
}
option (scalapb.message).extends = "ProtobufDomainObject";
option (scalapb.message).extends = "KycDocumentDecorator";
Expand All @@ -57,6 +61,7 @@ message KycDocument {
optional string refusedReasonMessage = 5;
optional google.protobuf.Timestamp createdDate = 6 [(scalapb.field).type = "java.util.Date"];
optional google.protobuf.Timestamp lastUpdated = 7 [(scalapb.field).type = "java.util.Date"];
optional string kycDocumentSubType = 8;
}

message UboDeclaration {
Expand All @@ -80,6 +85,9 @@ message UboDeclaration {
required string country = 10 [default = "FR"];
required BirthPlace birthPlace = 11;
required bool active = 12;
optional double percentOwnership = 13;
optional string email = 14;
optional string phone = 15;
}

enum UboDeclarationStatus {
Expand Down
21 changes: 21 additions & 0 deletions client/src/main/protobuf/model/payment/paymentUser.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ message BankAccount {
optional string mandateId = 12;
optional MandateStatus mandateStatus = 13;
optional MandateScheme mandateScheme = 14 [default = MANDATE_SEPA];
optional string countryCode = 15;
optional string currency = 16;
}

message NaturalUser {
Expand All @@ -76,6 +78,10 @@ message NaturalUser {
optional string profile = 10;
optional NaturalUserType naturalUserType = 11;
// optional string secondaryWalletId = 12;
optional Address address = 13;
optional string phone = 14;
optional Business business = 15;
optional string title = 16;
}

message LegalUser {
Expand All @@ -94,6 +100,9 @@ message LegalUser {
required Address headQuartersAddress = 6;
optional UboDeclaration uboDeclaration = 7;
optional google.protobuf.Timestamp lastAcceptedTermsOfPSP = 8 [(scalapb.field).type = "java.util.Date"];
optional string vatNumber = 9;
optional string phone = 10;
optional Business business = 11;
}

/**
Expand Down Expand Up @@ -125,6 +134,18 @@ message PaymentAccount {
optional string clientId = 12;
}

message Business {
required string merchantCategoryCode = 1;
required string website = 2;
optional BusinessSupport support = 3;
}

message BusinessSupport {
required string email = 1;
optional string phone = 2;
optional string url = 3;
}

message MandateResult{
required string id = 1;
required BankAccount.MandateStatus status = 2;
Expand Down
39 changes: 39 additions & 0 deletions client/src/main/protobuf/model/payment/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ message Transaction {
TRANSACTION_FAILED = 2;
TRANSACTION_NOT_SPECIFIED = 4;
TRANSACTION_FAILED_FOR_TECHNICAL_REASON = 5;
TRANSACTION_CANCELED = 6;
TRANSACTION_PENDING_PAYMENT = 7;
}

enum PaymentType {
Expand Down Expand Up @@ -85,6 +87,11 @@ message Transaction {
optional string payPalBuyerAccountEmail = 31;
optional string idempotencyKey = 32;
optional string clientId = 33;
optional string paymentClientSecret = 34;
optional string paymentClientData = 35;
optional string paymentClientReturnUrl = 36;
optional string sourceTransactionId = 37;
optional int32 transferAmount = 38;
}

message BrowserInfo {
Expand All @@ -101,6 +108,26 @@ message BrowserInfo {
}

message PayInTransaction {
option (scalapb.message).extends = "ProtobufDomainObject";
option (scalapb.message).extends = "PayInTransactionDecorator";
required string orderUuid = 1;
required int32 debitedAmount = 2;
required int32 feesAmount = 3 [default = 0];
required string currency = 4 [default = "EUR"];
required string creditedWalletId = 5;
required string authorId = 6;
required string statementDescriptor = 7;
required Transaction.PaymentType paymentType = 8 [default = CARD];
optional string cardId = 9;
optional string ipAddress = 10;
optional BrowserInfo browserInfo = 11;
optional bool registerCard = 12;
optional bool printReceipt = 13;
optional string cardPreAuthorizedTransactionId = 14;
optional int32 preAuthorizationDebitedAmount = 15;
}

message PayInWithCardTransaction {
option (scalapb.message).extends = "ProtobufDomainObject";
required string orderUuid = 1;
required int32 debitedAmount = 2;
Expand All @@ -127,6 +154,9 @@ message PayInWithPayPalTransaction {
optional string language = 7;
optional string statementDescriptor = 8;
optional bool printReceipt = 9;
optional string payPalWalletId = 10;
optional string ipAddress = 11;
optional BrowserInfo browserInfo = 12;
}

message RefundTransaction {
Expand All @@ -151,6 +181,8 @@ message TransferTransaction {
required string debitedWalletId = 7;
optional string orderUuid = 8;
optional string externalReference = 9;
optional string statementDescriptor = 10;
optional string payInTransactionId = 11;
}

message PayOutTransaction {
Expand All @@ -164,6 +196,8 @@ message PayOutTransaction {
required string authorId = 7;
required string debitedWalletId = 8;
optional string externalReference = 9;
optional string payInTransactionId = 10;
optional string statementDescriptor = 11;
}

message DirectDebitTransaction {
Expand All @@ -190,6 +224,9 @@ message PreAuthorizationTransaction {
optional BrowserInfo browserInfo = 7;
optional bool registerCard = 8;
optional bool printReceipt = 9;
optional string creditedUserId = 10;
optional int32 feesAmount = 11;
optional string statementDescriptor = 12;
}

message PayInWithCardPreAuthorizedTransaction {
Expand All @@ -201,6 +238,8 @@ message PayInWithCardPreAuthorizedTransaction {
required string authorId = 5;
required string cardPreAuthorizedTransactionId = 6;
required int32 preAuthorizationDebitedAmount = 7;
optional int32 feesAmount = 8;
optional string statementDescriptor = 9;
}

message CardPreRegistration{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ trait PaymentClient extends GrpcClient {
)
}

def loadPayInTransaction(
orderUuid: String,
payInTransactionId: String,
token: Option[String] = None
): Future[TransactionResponse] = {
withAuthorization(
grpcClient.loadPayInTransaction(),
token
)
.invoke(
LoadPayInTransactionRequest(orderUuid, payInTransactionId, settings.clientId)
)
}

def cancelPreAuthorization(
orderUuid: String,
cardPreAuthorizedTransactionId: String,
Expand Down Expand Up @@ -115,6 +129,7 @@ trait PaymentClient extends GrpcClient {
feesAmount: Int,
currency: String,
externalReference: Option[String],
payInTransactionId: Option[String],
token: Option[String] = None
): Future[TransactionResponse] = {
withAuthorization(
Expand All @@ -129,11 +144,26 @@ trait PaymentClient extends GrpcClient {
feesAmount,
currency,
externalReference,
settings.clientId
settings.clientId,
payInTransactionId
)
)
}

def loadPayOutTransaction(
orderUuid: String,
payOutTransactionId: String,
token: Option[String] = None
): Future[TransactionResponse] = {
withAuthorization(
grpcClient.loadPayOutTransaction(),
token
)
.invoke(
LoadPayOutTransactionRequest(orderUuid, payOutTransactionId, settings.clientId)
)
}

def transfer(
orderUuid: Option[String],
debitedAccount: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import java.nio.file.Paths
object ApiKeys {

private[this] lazy val filePath: String = {
val config = SoftPayClientSettings.SOFT_PAY_HOME + "/config"
Paths.get(config).toFile.mkdirs()
config + "/apiKeys.conf"
Paths.get(SoftPayClientSettings.SP_CONFIG).toFile.mkdirs()
SoftPayClientSettings.SP_CONFIG + "/apiKeys.conf"
}

private[this] def write(apiKeys: Map[String, String]): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ case class SoftPayClientSettings(clientId: String, apiKey: String) {
}

private[payment] def select(): Unit = {
val config = SoftPayClientSettings.SOFT_PAY_HOME + "/config"
val config = SoftPayClientSettings.SP_ROOT + "/config"
Paths.get(config).toFile.mkdirs()
val application = Paths.get(config + "/application.conf").toFile
application.createNewFile()
Expand All @@ -34,14 +34,18 @@ case class SoftPayClientSettings(clientId: String, apiKey: String) {
}

object SoftPayClientSettings {
lazy val SOFT_PAY_HOME: String =
lazy val SP_ROOT: String =
sys.env.getOrElse(
"SOFT_PAY_HOME",
"SP_ROOT",
Option(System.getProperty("user.home") + "/soft-pay").getOrElse(".")
)

lazy val SP_CONFIG: String = sys.env.getOrElse("SP_CONFIG", SP_ROOT + "/config")

lazy val SP_SECRETS: String = sys.env.getOrElse("SP_SECRETS", SP_ROOT + "/secrets")

def apply(system: ActorSystem[_]): SoftPayClientSettings = {
val clientConfigFile: Path = Paths.get(s"$SOFT_PAY_HOME/config/application.conf")
val clientConfigFile: Path = Paths.get(s"$SP_ROOT/config/application.conf")
val systemConfig = system.settings.config.getConfig("payment")
val clientConfig: Config = {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import app.softnetwork.validation.RegexValidator
import scala.util.matching.Regex

trait LegalUserDecorator { self: LegalUser =>
lazy val wrongSiret: Boolean = !SiretValidator.check(siret)
lazy val wrongSiret: Boolean = !SiretValidator.check(siret.split(" ").mkString)

lazy val wrongLegalRepresentativeAddress: Boolean = legalRepresentativeAddress.wrongAddress

Expand All @@ -18,6 +18,8 @@ trait LegalUserDecorator { self: LegalUser =>
uboDeclaration.exists(_.status.isUboDeclarationValidated)

lazy val view: LegalUserView = model.LegalUserView(self)

lazy val siren: String = siret.split(" ").mkString.take(9)
}

object SiretValidator extends RegexValidator {
Expand All @@ -28,6 +30,7 @@ case class LegalUserView(
legalUserType: LegalUser.LegalUserType,
legalName: String,
siret: String,
siren: String,
legalRepresentative: NaturalUserView,
legalRepresentativeAddress: AddressView,
headQuartersAddress: AddressView,
Expand All @@ -42,6 +45,7 @@ object LegalUserView {
legalUserType,
legalName,
siret,
siren,
legalRepresentative.view,
legalRepresentativeAddress.view,
headQuartersAddress.view,
Expand Down
Loading

0 comments on commit ebaec7e

Please sign in to comment.