Creating a Marketplace

You can set up an event rule, to start a workflow execution when you application send an event to the PutEvent API

{
  "type": "new_order",
  "buyer": "094353434343",
  "seller" : "1245643453234",
  "transaction_id": "3643346346345",
  "price": "100000",
  "currency": "IDR"
}
{
  "type": ["new_order"]
}

You can set the following as the rule action

@workflow-new_order(buyer=$event.buyer,seller=$event.seller, item=$event.item, amount=$event.price, currency=$event.currency)

Workflow Implementation

The following workflow, will first deduct the money from the PayMongo Wallet of the buyer to your master ledger.

Then it will wait for an event, when the seller sends the item and inputs the tracking number in your system, then using integration with the tracking company we can await for the item delivered event, which will then await for your application to send an order confirmation from the buyer end to forward the money to the seller.

version: 1
name: Start Escrow Transaction

inputs:
  seller:
    type: string
    required: true
  buyer:
    type: string
    required: true
  price:
    type: number
    required: true
  currency:
    type: string
    required: true

jobs:
  escrow_money_from_buyer_wallet:
    integration: "paymongo"
    account: $input.buyer
    steps:
      - uses: paymongo
        amount: $input.amount
        destination: $contacts.self
        notes: "Payment for transaction ID $input.transaction_id"
  await_for_events_and_transfer_to_seller:
    integration: "paymongo"
    account: "1234567890" # Use your master Paymongo Wallet ID
    steps:
      - uses: await_for_event
        name: "await_for_seller_confirmation_to_send_item"
        event_pattern: |
          {
            "type": ["product_sent"],
            "transaction_id": "$input.transaction_id",
          }
        timeout: "3d"
        on-failure: "@workflow-refund_buyer(destination=$input.buyer, amount=$input.amount, currency=$input.currency)"
  await_for_events_from_shipping_company:
    integration: "shipping_company"
    account: "shipping_company_account_id" # Replace with actual shipping company account ID
    steps:
      - uses: await_for_event
        name: "await for item delivery confirmation"
        event_pattern: |
          {
            "type": ["item_delivered"],
            "tracking_number": ["$output.await_for_seller_confirmation_to_send_item.tracking_number"],
          }
        timeout: "14d"
        on-failure: "@workflow_refund_buyer(destination=$input.buyer, amount=$input.amount, currency=$input.currency)"
  await_for_events_from_buyer:
    integration: "paymongo"
    account: "1234567890" # Use your master Paymongo Wallet ID
    steps:
      - uses: await_for_event
        name: "await_for_buyer_confirmation_of_item_received"
        event_pattern: |
          {
            "type": ["item_confirmed"],
            "transaction_id": "$input.transaction_id",
          }
        timeout: "2d"
        on-failure: "@workflow_refund_seller(destination=$input.seller, amount=$input.amount, currency=$input.currency)"
      - uses: paymongo
        name: "transfer_money_to_seller"
        amount: $input.amount
        destination: $input.seller
        notes: "Payment for transaction ID $input.transaction_id"