Skip to content

Commit

Permalink
Upgrading to beta version
Browse files Browse the repository at this point in the history
  • Loading branch information
alan10fm committed Oct 30, 2020
1 parent c9460de commit a27ba7c
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 79 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "com.netki"
version = "0.1.0-alpha16"
version = "1.0.0-beta1"
java.sourceCompatibility = JavaVersion.VERSION_1_8

repositories {
Expand All @@ -18,7 +18,7 @@ repositories {
}

dependencies {
implementation("com.netki:transactid:0.1.0-alpha16")
implementation("com.netki:transactid:1.0.0-beta1")

implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.netki.transactidlibraryjavademo.service

import com.netki.TransactId
import com.netki.model.EncryptionParameters
import com.netki.model.MessageInformation
import com.netki.model.RecipientParameters
import com.netki.model.SenderParameters
import com.netki.model.*
import com.netki.transactidlibraryjavademo.model.EncryptionKeys
import com.netki.transactidlibraryjavademo.util.TestData.Attestations.ATTESTATIONS_REQUESTED
import com.netki.transactidlibraryjavademo.util.TestData.InvoiceRequest.INVOICE_REQUEST_DATA
import com.netki.transactidlibraryjavademo.util.TestData.Owners.NO_PRIMARY_OWNER_PKI_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.Owners.PRIMARY_OWNER_PKI_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.Payment.PAYMENT_PARAMETERS
import com.netki.transactidlibraryjavademo.util.TestData.PaymentRequest.PAYMENT_REQUEST_PARAMETERS
import com.netki.transactidlibraryjavademo.util.TestData.Beneficiaries.NO_PRIMARY_BENEFICIARY_PKI_NONE
import com.netki.transactidlibraryjavademo.util.TestData.Beneficiaries.NO_PRIMARY_BENEFICIARY_PKI_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.Beneficiaries.PRIMARY_BENEFICIARY_PKI_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.Originators.NO_PRIMARY_ORIGINATOR_PKI_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.Originators.PRIMARY_ORIGINATOR_PKI_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.Output.OUTPUTS
import com.netki.transactidlibraryjavademo.util.TestData.Payment.PAYMENT
import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_SENDER_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.Senders.SENDER_PKI_X509SHA256
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.sql.Timestamp
import javax.annotation.PostConstruct

@Service
Expand All @@ -29,7 +29,6 @@ class TransactIdService {

private val logger = LoggerFactory.getLogger(this.javaClass)
private var transactId = TransactId.getInstance("src/main/resources/certificates")
val ownerParameters = listOf(PRIMARY_OWNER_PKI_X509SHA256, NO_PRIMARY_OWNER_PKI_X509SHA256)
val messageInformationEncrypted = MessageInformation(
encryptMessage = true
)
Expand Down Expand Up @@ -57,26 +56,53 @@ class TransactIdService {

fun getInitialInvoiceRequest(): ByteArray {
logger.info("Creating InvoiceRequest...")
val invoiceRequest = transactId.createInvoiceRequest(
INVOICE_REQUEST_DATA,
ownerParameters,
SENDER_PKI_X509SHA256,
ATTESTATIONS_REQUESTED
val originators = listOf(
PRIMARY_ORIGINATOR_PKI_X509SHA256,
NO_PRIMARY_ORIGINATOR_PKI_X509SHA256
)
val beneficiaries = listOf(
PRIMARY_BENEFICIARY_PKI_X509SHA256
)
val sender = SENDER_PKI_X509SHA256
val invoiceRequestParameters = InvoiceRequestParameters(
amount = 1000,
memo = "memo",
notificationUrl = "notificationUrl",
originatorsAddresses = OUTPUTS,
originatorParameters = originators,
beneficiaryParameters = beneficiaries,
senderParameters = sender,
attestationsRequested = ATTESTATIONS_REQUESTED
)

val invoiceRequest = transactId.createInvoiceRequest(invoiceRequestParameters)
logger.info("Returning InvoiceRequest...")
return invoiceRequest
}

fun getInitialInvoiceRequestEncrypted(): ByteArray {
logger.info("Creating InvoiceRequest encrypted...")
val invoiceRequest = transactId.createInvoiceRequest(
INVOICE_REQUEST_DATA,
ownerParameters,
senderParameters,
ATTESTATIONS_REQUESTED,
recipientParameters,
messageInformationEncrypted
val originators = listOf(
PRIMARY_ORIGINATOR_PKI_X509SHA256,
NO_PRIMARY_ORIGINATOR_PKI_X509SHA256
)
val beneficiaries = listOf(
PRIMARY_BENEFICIARY_PKI_X509SHA256
)
val invoiceRequestParameters = InvoiceRequestParameters(
amount = 1000,
memo = "memo",
notificationUrl = "notificationUrl",
originatorsAddresses = OUTPUTS,
originatorParameters = originators,
beneficiaryParameters = beneficiaries,
senderParameters = senderParameters,
attestationsRequested = ATTESTATIONS_REQUESTED,
recipientParameters = recipientParameters,
messageInformation = messageInformationEncrypted
)

val invoiceRequest = transactId.createInvoiceRequest(invoiceRequestParameters)
logger.info("Returning InvoiceRequest...")
return invoiceRequest
}
Expand All @@ -96,25 +122,46 @@ class TransactIdService {
return if (invoiceRequestModel.protocolMessageMetadata.encrypted) {
logger.info("Creating PaymentRequest Encrypted...")
logger.info("Returning PaymentRequest Encrypted...")
transactId.createPaymentRequest(
PAYMENT_REQUEST_PARAMETERS,
ownerParameters,
senderParameters,
ATTESTATIONS_REQUESTED,
1,
messageInformationEncrypted,
recipientParameters
val beneficiaries = listOf(
PRIMARY_BENEFICIARY_PKI_X509SHA256,
NO_PRIMARY_BENEFICIARY_PKI_X509SHA256
)
val paymentRequestParameters = PaymentRequestParameters(
network = "main",
beneficiariesAddresses = OUTPUTS,
time = Timestamp(System.currentTimeMillis()),
expires = Timestamp(System.currentTimeMillis()),
memo = "memo",
paymentUrl = "www.payment.url/test",
merchantData = "merchant data",
beneficiaryParameters = beneficiaries,
senderParameters = senderParameters,
attestationsRequested = ATTESTATIONS_REQUESTED,
messageInformation = messageInformationEncrypted,
recipientParameters = recipientParameters
)
transactId.createPaymentRequest(paymentRequestParameters)
} else {
logger.info("Creating PaymentRequest...")
logger.info("Returning PaymentRequest...")
transactId.createPaymentRequest(
PAYMENT_REQUEST_PARAMETERS,
ownerParameters,
SENDER_PKI_X509SHA256,
ATTESTATIONS_REQUESTED,
1
val beneficiaries = listOf(
PRIMARY_BENEFICIARY_PKI_X509SHA256,
NO_PRIMARY_BENEFICIARY_PKI_X509SHA256
)
val sender = SENDER_PKI_X509SHA256
val paymentRequestParameters = PaymentRequestParameters(
network = "main",
beneficiariesAddresses = OUTPUTS,
time = Timestamp(System.currentTimeMillis()),
expires = Timestamp(System.currentTimeMillis()),
memo = "memo",
paymentUrl = "www.payment.url/test",
merchantData = "merchant data",
beneficiaryParameters = beneficiaries,
senderParameters = sender,
attestationsRequested = ATTESTATIONS_REQUESTED
)
transactId.createPaymentRequest(paymentRequestParameters)
}
}

Expand All @@ -133,18 +180,51 @@ class TransactIdService {
return if (paymentRequestModel.protocolMessageMetadata.encrypted) {
logger.info("Creating Payment Encrypted...")
logger.info("Returning Payment Encrypted...")
transactId.createPayment(
PAYMENT_PARAMETERS,
ownerParameters,
messageInformationEncrypted,
senderParameters,
recipientParameters
val originators = listOf(
PRIMARY_ORIGINATOR_PKI_X509SHA256,
NO_PRIMARY_ORIGINATOR_PKI_X509SHA256
)
val beneficiaries = listOf(
PRIMARY_BENEFICIARY_PKI_X509SHA256
)
val paymentParameters = PaymentParameters(
merchantData = "merchant data",
transactions = arrayListOf(
"transaction1".toByteArray(),
"transaction2".toByteArray()
),
outputs = OUTPUTS,
memo = "memo",
originatorParameters = originators,
beneficiaryParameters = beneficiaries,
messageInformation = messageInformationEncrypted,
senderParameters = senderParameters,
recipientParameters = recipientParameters
)
transactId.createPayment(paymentParameters)

} else {
logger.info("Creating Payment...")
logger.info("Returning Payment...")
transactId.createPayment(PAYMENT_PARAMETERS, ownerParameters)
val originators = listOf(
PRIMARY_ORIGINATOR_PKI_X509SHA256,
NO_PRIMARY_ORIGINATOR_PKI_X509SHA256
)
val beneficiaries = listOf(
PRIMARY_BENEFICIARY_PKI_X509SHA256
)
val paymentParameters = PaymentParameters(
merchantData = "merchant data",
transactions = arrayListOf(
"transaction1".toByteArray(),
"transaction2".toByteArray()
),
outputs = OUTPUTS,
memo = "memo",
originatorParameters = originators,
beneficiaryParameters = beneficiaries
)
transactId.createPayment(paymentParameters)
}
}

Expand All @@ -157,17 +237,22 @@ class TransactIdService {
return if (paymentModel.protocolMessageMetadata!!.encrypted) {
logger.info("Creating PaymentAck Encrypted...")
logger.info("Returning PaymentAck Encrypted...")
transactId.createPaymentAck(
paymentModel,
"Payment successful",
messageInformationEncrypted,
senderParameters,
recipientParameters
val paymentAckParameters = PaymentAckParameters(
payment = PAYMENT,
memo = "memo ack",
messageInformation = messageInformationEncrypted,
senderParameters = senderParameters,
recipientParameters = recipientParameters
)
transactId.createPaymentAck(paymentAckParameters)
} else {
logger.info("Creating PaymentAck...")
logger.info("Returning PaymentAck...")
transactId.createPaymentAck(paymentModel, "Payment successful")
val paymentAckParameters = PaymentAckParameters(
payment = PAYMENT,
memo = "memo ack"
)
transactId.createPaymentAck(paymentAckParameters)
}
}
}
85 changes: 58 additions & 27 deletions src/main/java/com/netki/transactidlibraryjavademo/util/TestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.netki.transactidlibraryjavademo.util.TestData.Output.OUTPUTS
import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_ONE_OWNER_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_SENDER_X509SHA256
import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_TWO_OWNER_X509SHA256
import java.sql.Timestamp

object TestData {

Expand Down Expand Up @@ -111,36 +110,46 @@ object TestData {
"UM5JZTOfmyf5CwE2lNBZryI=\n" +
"-----END PRIVATE KEY-----\n"

object InvoiceRequest {
val INVOICE_REQUEST_DATA = InvoiceRequestParameters(
amount = 1000,
memo = "memo",
notificationUrl = "notificationUrl",
outputs = OUTPUTS
)
}

object PaymentRequest {
val PAYMENT_REQUEST_PARAMETERS = PaymentRequestParameters(
network = "main",
outputs = OUTPUTS,
time = Timestamp(System.currentTimeMillis()),
expires = Timestamp(System.currentTimeMillis()),
memo = "memo",
paymentUrl = "www.payment.url/test",
merchantData = "merchant data"
)
}

object Payment {
val PAYMENT_PARAMETERS = PaymentParameters(
val PAYMENT = Payment(
merchantData = "merchant data",
transactions = arrayListOf(
"transaction1".toByteArray(),
"transaction2".toByteArray()
),
outputs = OUTPUTS,
memo = "memo"
memo = "memo",
beneficiaries = listOf(
Beneficiary(
isPrimaryForTransaction = true,
pkiDataSet = listOf(
PkiData(
attestation = Attestation.ADDRESS_COUNTRY,
certificatePem = CLIENT_CERTIFICATE_CHAIN_ONE,
type = PkiType.X509SHA256
)
)
)
),
originators = listOf(
Originator(
isPrimaryForTransaction = true,
pkiDataSet = listOf(
PkiData(
attestation = Attestation.ADDRESS_COUNTRY,
certificatePem = CLIENT_CERTIFICATE_CHAIN_ONE,
type = PkiType.X509SHA256
)
)
)
),
protocolMessageMetadata = ProtocolMessageMetadata(
1,
StatusCode.OK,
MessageType.PAYMENT,
"",
"randomIdentifier"
)
)
}

Expand All @@ -151,13 +160,35 @@ object TestData {
)
}

object Owners {
val PRIMARY_OWNER_PKI_X509SHA256 = OwnerParameters(
object Beneficiaries {
val PRIMARY_BENEFICIARY_PKI_X509SHA256 = BeneficiaryParameters(
true,
listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256)
)

val NO_PRIMARY_OWNER_PKI_X509SHA256 = OwnerParameters(
val NO_PRIMARY_BENEFICIARY_PKI_X509SHA256 = BeneficiaryParameters(
false,
listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256)
)

val NO_PRIMARY_BENEFICIARY_PKI_NONE = BeneficiaryParameters(
false,
listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256)
)
}

object Originators {
val PRIMARY_ORIGINATOR_PKI_X509SHA256 = OriginatorParameters(
true,
listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256)
)

val NO_PRIMARY_ORIGINATOR_PKI_X509SHA256 = OriginatorParameters(
false,
listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256)
)

val NO_PRIMARY_ORIGINATOR_PKI_NONE = OriginatorParameters(
false,
listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256)
)
Expand Down

0 comments on commit a27ba7c

Please sign in to comment.