Search in sources :

Example 1 with Message

use of io.tbd.tbdex.protocol.core.Message in project tbdex-protocol by TBD54566975.

the class SettlementDetailsProcessor method process.

@Override
public Message process(Message message) {
    Preconditions.checkState(message.type() == MessageType.SettlementDetails);
    SettlementDetails settlementDetails = getBody(message);
    paymentProcessor.process(settlementDetails, message.threadID());
    String messageId = UUID.randomUUID().toString();
    return new Message.Builder(messageId, message.threadID(), message.to(), message.from()).build(new SettlementReceipt("receipt"));
}
Also used : SettlementReceipt(io.tbd.tbdex.protocol.messages.SettlementReceipt) Message(io.tbd.tbdex.protocol.core.Message) SettlementDetails(io.tbd.tbdex.protocol.messages.SettlementDetails)

Example 2 with Message

use of io.tbd.tbdex.protocol.core.Message in project tbdex-protocol by TBD54566975.

the class HibernateStoreTest method hibernateThreadStoreTest.

@Test
@DisplayName("create DbMessage")
void hibernateThreadStoreTest() {
    String threadToken = "thid";
    Message message1 = new Message.Builder("mid", threadToken, "pfi", "alice").build(new Ask("USD", BigDecimal.valueOf(100), "USDC"));
    threadStore.addMessageToThread(message1);
    Assertions.assertEquals(threadStore.getThread(threadToken).getSize(), 1);
    Message message2 = new Message.Builder("mid2", threadToken, "pfi2", "alice2").build(new Ask("USD", BigDecimal.valueOf(100), "USDC"));
    threadStore.addMessageToThread(message2);
    MessageThread messageThread = threadStore.getThread(threadToken);
    Assertions.assertEquals(messageThread.getSize(), 2);
    Assertions.assertEquals(messageThread.getLastMessage().id(), "mid2");
}
Also used : Message(io.tbd.tbdex.protocol.core.Message) Ask(io.tbd.tbdex.protocol.messages.Ask) MessageThread(io.tbd.tbdex.protocol.core.MessageThread) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Message

use of io.tbd.tbdex.protocol.core.Message in project tbdex-protocol by TBD54566975.

the class PaymentProcessorTest method happyPath.

@Test
@DisplayName("runs without error")
void happyPath() {
    String threadToken = "thid";
    Message message1 = new Message.Builder("mid", threadToken, "pfi", "alice").build(new Ask("USDC", BigDecimal.valueOf(100), "USDC"));
    threadStore.addMessageToThread(message1);
    PaymentProcessorRequest request = new PaymentProcessorRequest.Builder().account_number(TestHelper.PAYMENT_INSTRUMENT.account_number).routing_number(TestHelper.PAYMENT_INSTRUMENT.routing_number).bank_address(TestHelper.BANK_ADDRESS).billing_details(TestHelper.BILLING_DETAILS).wallet_address("123").email_address("123").build();
    String body = JsonParser.getParser().toJson(request);
    SettlementDetails settlementDetails = new SettlementDetails(JsonParser.getParser().toJsonTree(body));
    paymentProcessor.process(settlementDetails, threadToken);
}
Also used : Message(io.tbd.tbdex.protocol.core.Message) Ask(io.tbd.tbdex.protocol.messages.Ask) PaymentProcessorRequest(com.squareup.protos.tbd.pfi.PaymentProcessorRequest) SettlementDetails(io.tbd.tbdex.protocol.messages.SettlementDetails) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with Message

use of io.tbd.tbdex.protocol.core.Message in project tbdex-protocol by TBD54566975.

the class AskProcessorTest method testReturnsConditionalOffer.

@Test
@DisplayName("throws an exception response is not a conditional offer")
void testReturnsConditionalOffer() {
    Message message = new Message.Builder("mid", "thid", "pfi", "alice").build(new Ask("USD", BigDecimal.valueOf(100), "USDC"));
    Message response = processor.addMessage(message);
    Assertions.assertSame(response.type(), MessageType.ConditionalOffer);
    Assertions.assertSame(2, threadStore.getThread("thid").getSize());
}
Also used : Message(io.tbd.tbdex.protocol.core.Message) Ask(io.tbd.tbdex.protocol.messages.Ask) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Message

use of io.tbd.tbdex.protocol.core.Message in project tbdex-protocol by TBD54566975.

the class AskProcessor method process.

@Override
public Message process(Message message) {
    Ask ask = getBody(message);
    ConditionalOffer conditionalOffer = new ConditionalOffer(ask.sourceCurrency, // Stand in for real offer.
    ask.sourceAmount.multiply(BigDecimal.valueOf(0.98)), ask.targetCurrency);
    String messageId = UUID.randomUUID().toString();
    return new Message.Builder(messageId, message.threadID(), message.to(), message.from()).build(conditionalOffer);
}
Also used : ConditionalOffer(io.tbd.tbdex.protocol.messages.ConditionalOffer) Message(io.tbd.tbdex.protocol.core.Message) Ask(io.tbd.tbdex.protocol.messages.Ask)

Aggregations

Message (io.tbd.tbdex.protocol.core.Message)7 Ask (io.tbd.tbdex.protocol.messages.Ask)4 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 MessageThread (io.tbd.tbdex.protocol.core.MessageThread)2 SettlementDetails (io.tbd.tbdex.protocol.messages.SettlementDetails)2 PaymentProcessorRequest (com.squareup.protos.tbd.pfi.PaymentProcessorRequest)1 ConditionalOffer (io.tbd.tbdex.protocol.messages.ConditionalOffer)1 SettlementReceipt (io.tbd.tbdex.protocol.messages.SettlementReceipt)1 SettlementRequest (io.tbd.tbdex.protocol.messages.SettlementRequest)1 LinkedList (java.util.LinkedList)1 Session (org.hibernate.Session)1 Transaction (org.hibernate.Transaction)1 Query (org.hibernate.query.Query)1