Search in sources :

Example 1 with HibernateMessageThreadStore

use of io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore in project tbdex-protocol by TBD54566975.

the class PaymentProcessor method process.

public void process(SettlementDetails settlementDetails, String threadToken) {
    // Get ASK from thread store
    // TODO: change to get conditional offer and also add source and target amounts in offer
    HibernateMessageThreadStore threadStore = new HibernateMessageThreadStore();
    MessageThread messageThread = threadStore.getThread(threadToken);
    Ask ask = messageThread.getAsk();
    Preconditions.checkNotNull(ask);
    String body = parser.toJson(settlementDetails.body);
    PaymentProcessorRequest request = parser.fromJson(body, PaymentProcessorRequest.class);
    // Register Bank Account with Circle.
    // TODO: Do not store bank account in our database
    BankAccount bankAccount = createBankAccount(request);
    System.out.println(bankAccount);
    Amount amount = new Amount.Builder().amount(ask.sourceAmount.toString()).currency(CurrencyCode.valueOf(ask.sourceCurrency)).build();
    // On-Ramp
    if (CurrencyCode.valueOf(ask.targetCurrency) == CurrencyCode.USDC) {
        CreateWirePaymentRequest createWirePaymentRequest = new CreateWirePaymentRequest.Builder().amount(amount).trackingRef(bankAccount.trackingRef).build();
        TransferRequest transferRequest = new TransferRequest.Builder().source(WALLET_SOURCE).destination(new Destination.Builder().type("blockchain").address(request.wallet_address).chain("ETH").build()).idempotencyKey(UUID.randomUUID().toString()).amount(amount).build();
        try {
            // Create a WIRE payment Request.
            circleClient.createWirePayment(createWirePaymentRequest);
            // Transfer USDC to external wallet address.
            circleClient.transfer(transferRequest);
        } catch (Exception e) {
            System.out.println("wire payment failed");
        }
    // Off-Ramp
    } else if (CurrencyCode.valueOf(ask.targetCurrency) == CurrencyCode.USD) {
        try {
            PayoutRequest payoutRequest = new PayoutRequest.Builder().source(WALLET_SOURCE).destination(new Destination.Builder().type("wire").id(bankAccount.id).build()).idempotencyKey(UUID.randomUUID().toString()).metadata(new Metadata.Builder().beneficiaryEmail(request.email_address).build()).amount(amount).build();
            circleClient.payout(payoutRequest);
        } catch (Exception e) {
            System.out.println("payout failed");
        }
    }
}
Also used : PayoutRequest(com.squareup.protos.tbd.pfi.PayoutRequest) Destination(com.squareup.protos.tbd.pfi.Destination) HibernateMessageThreadStore(io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore) Amount(com.squareup.protos.tbd.pfi.Amount) PaymentProcessorRequest(com.squareup.protos.tbd.pfi.PaymentProcessorRequest) MessageThread(io.tbd.tbdex.protocol.core.MessageThread) BankAccount(com.squareup.protos.tbd.pfi.BankAccount) CreateWirePaymentRequest(com.squareup.protos.tbd.pfi.CreateWirePaymentRequest) TransferRequest(com.squareup.protos.tbd.pfi.TransferRequest) Ask(io.tbd.tbdex.protocol.messages.Ask)

Example 2 with HibernateMessageThreadStore

use of io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore in project tbdex-protocol by TBD54566975.

the class ProcessorModule method configure.

@Override
protected void configure() {
    MessageThreadStore threadStore = new HibernateMessageThreadStore();
    CircleClient circleClient = new RealCircleClient();
    MessageThreadProcessor processor = new MessageThreadProcessor.Builder(threadStore).registerProcessor(MessageType.Ask, new AskProcessor()).registerProcessor(MessageType.Close, new CloseProcessor()).registerProcessor(MessageType.OfferAccept, new OfferAcceptProcessor()).registerProcessor(MessageType.SettlementDetails, new SettlementDetailsProcessor(new PaymentProcessor(circleClient))).build();
    bind(MessageThreadProcessor.class).toInstance(processor);
    bind(MessageThreadStore.class).toInstance(threadStore);
    bind(CircleClient.class).toInstance(circleClient);
}
Also used : RealCircleClient(io.tbd.tbdex.pfi_mock_impl.payments.circle.RealCircleClient) HibernateMessageThreadStore(io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore) PaymentProcessor(io.tbd.tbdex.pfi_mock_impl.payments.PaymentProcessor) RealCircleClient(io.tbd.tbdex.pfi_mock_impl.payments.circle.RealCircleClient) CircleClient(io.tbd.tbdex.pfi_mock_impl.payments.circle.CircleClient) MessageThreadProcessor(io.tbd.tbdex.protocol.core.MessageThreadProcessor) HibernateMessageThreadStore(io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore) MessageThreadStore(io.tbd.tbdex.protocol.core.MessageThreadStore)

Example 3 with HibernateMessageThreadStore

use of io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore in project tbdex-protocol by TBD54566975.

the class ProcessorTestModule method configure.

@Override
protected void configure() {
    MessageThreadStore threadStore = new HibernateMessageThreadStore();
    CircleClient circleClient = new MockCircleClient();
    MessageThreadProcessor processor = new MessageThreadProcessor.Builder(threadStore).registerProcessor(MessageType.Ask, new AskProcessor()).registerProcessor(MessageType.Close, new CloseProcessor()).registerProcessor(MessageType.OfferAccept, new OfferAcceptProcessor()).registerProcessor(MessageType.SettlementDetails, new SettlementDetailsProcessor(new PaymentProcessor(circleClient))).build();
    bind(MessageThreadProcessor.class).toInstance(processor);
    bind(MessageThreadStore.class).toInstance(threadStore);
    bind(CircleClient.class).toInstance(circleClient);
}
Also used : AskProcessor(io.tbd.tbdex.pfi_mock_impl.processors.AskProcessor) SettlementDetailsProcessor(io.tbd.tbdex.pfi_mock_impl.processors.SettlementDetailsProcessor) HibernateMessageThreadStore(io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore) PaymentProcessor(io.tbd.tbdex.pfi_mock_impl.payments.PaymentProcessor) MockCircleClient(io.tbd.tbdex.pfi_mock_impl.payments.circle.MockCircleClient) CircleClient(io.tbd.tbdex.pfi_mock_impl.payments.circle.CircleClient) MessageThreadProcessor(io.tbd.tbdex.protocol.core.MessageThreadProcessor) CloseProcessor(io.tbd.tbdex.pfi_mock_impl.processors.CloseProcessor) MockCircleClient(io.tbd.tbdex.pfi_mock_impl.payments.circle.MockCircleClient) HibernateMessageThreadStore(io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore) MessageThreadStore(io.tbd.tbdex.protocol.core.MessageThreadStore) OfferAcceptProcessor(io.tbd.tbdex.pfi_mock_impl.processors.OfferAcceptProcessor)

Aggregations

HibernateMessageThreadStore (io.tbd.tbdex.pfi_mock_impl.store.HibernateMessageThreadStore)3 PaymentProcessor (io.tbd.tbdex.pfi_mock_impl.payments.PaymentProcessor)2 CircleClient (io.tbd.tbdex.pfi_mock_impl.payments.circle.CircleClient)2 MessageThreadProcessor (io.tbd.tbdex.protocol.core.MessageThreadProcessor)2 MessageThreadStore (io.tbd.tbdex.protocol.core.MessageThreadStore)2 Amount (com.squareup.protos.tbd.pfi.Amount)1 BankAccount (com.squareup.protos.tbd.pfi.BankAccount)1 CreateWirePaymentRequest (com.squareup.protos.tbd.pfi.CreateWirePaymentRequest)1 Destination (com.squareup.protos.tbd.pfi.Destination)1 PaymentProcessorRequest (com.squareup.protos.tbd.pfi.PaymentProcessorRequest)1 PayoutRequest (com.squareup.protos.tbd.pfi.PayoutRequest)1 TransferRequest (com.squareup.protos.tbd.pfi.TransferRequest)1 MockCircleClient (io.tbd.tbdex.pfi_mock_impl.payments.circle.MockCircleClient)1 RealCircleClient (io.tbd.tbdex.pfi_mock_impl.payments.circle.RealCircleClient)1 AskProcessor (io.tbd.tbdex.pfi_mock_impl.processors.AskProcessor)1 CloseProcessor (io.tbd.tbdex.pfi_mock_impl.processors.CloseProcessor)1 OfferAcceptProcessor (io.tbd.tbdex.pfi_mock_impl.processors.OfferAcceptProcessor)1 SettlementDetailsProcessor (io.tbd.tbdex.pfi_mock_impl.processors.SettlementDetailsProcessor)1 MessageThread (io.tbd.tbdex.protocol.core.MessageThread)1 Ask (io.tbd.tbdex.protocol.messages.Ask)1