Payment Upon IoT

Author: Accord Project

payment-upon-iot@0.7.0 Contract ^0.21.0 f791cc4a2f99989dbc42a14e4ce003a5329c52bd8111389ee5e51ae42a14161f

This is a payment contract that pays out a fixed amount each time a button is pressed.

Download Archive Download Compiled Archive Open in Template Studio Open in VSCode Web

Payment upon IoT Button Press

This is template pays out a fixed amount each time a button is pressed.

It responds to:

  • single press : increments a counter by 1
  • double press : decrements a counter by 1
  • long press : pays out based on the current counter and resets the counter to 0

Template Text

Upon long button press, "Dan" shall pay to "Grant" 10 USD for each short button press. A maximum of 5 payments may be made before this contract is COMPLETED.

Note: to undo a short button press the buyer may double-press the button.

Upon long button press, "Dan" shall pay to "Grant" 10 USD for each short button press. A maximum of 5 payments may be made before this contract is COMPLETED.

Note: to undo a short button press the buyer may double-press the button.
Upon long button press, {{buyer}} shall pay to {{seller}} {{amountPerUnit}} for each short button press. A maximum of {{paymentCount}} payments may be made before this contract is COMPLETED.

Note: to undo a short button press the buyer may double-press the button.
{
    "$class": "org.accordproject.payment.iot.PaymentUponButtonContract",
    "buyer": {
        "$class": "org.accordproject.cicero.contract.AccordParty",
        "partyId": "Dan"
    },
    "seller": {
        "$class": "org.accordproject.cicero.contract.AccordParty",
        "partyId": "Grant"
    },
    "amountPerUnit": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 10,
        "currencyCode": "USD"
    },
    "paymentCount": 5,
    "contractId": "4b79f63b-0b03-4e47-99eb-85b833a7dc8e"
}

Template Model

namespace org.accordproject.payment.iot

import org.accordproject.cicero.contract.* from https://models.accordproject.org/cicero/contract.cto
import org.accordproject.cicero.runtime.* from https://models.accordproject.org/cicero/runtime.cto
import org.accordproject.money.MonetaryAmount from https://models.accordproject.org/money.cto

import org.accordproject.payment.PaymentReceived from https://models.accordproject.org/payment/payment.cto
import org.accordproject.signature.ContractSigned from https://models.accordproject.org/signature/signature.cto

import org.accordproject.iot.SingleButtonPress from https://models.accordproject.org/iot/iot.cto
import org.accordproject.iot.DoubleButtonPress from https://models.accordproject.org/iot/iot.cto
import org.accordproject.iot.LongButtonPress from https://models.accordproject.org/iot/iot.cto

asset CounterState extends AccordContractState {
  o ContractLifecycleStatus status
  o Double counter
  o Double paymentCount
}

enum ContractLifecycleStatus {
  o INITIALIZED
  o RUNNING
  o COMPLETED
}

transaction CounterResponse extends Response {
  o Double counter
  o Double paymentCount
}

transaction MonetaryAmountPayment extends PaymentReceived {
  o MonetaryAmount amount
}

/**
 * The template model
 */
asset PaymentUponButtonContract extends AccordContract {
  o AccordParty buyer
  o AccordParty seller
  o MonetaryAmount amountPerUnit
  o Integer paymentCount
}

Model Dependencies

Template Logic

Find the full logic for this template on on GitHub.

State Types

Type Sample JSON
org.accordproject.payment.iot.CounterState
{
    "$class": "org.accordproject.payment.iot.CounterState",
    "status": "INITIALIZED",
    "counter": 173.832,
    "paymentCount": 14.656,
    "stateId": "8c203c90-cd1d-11ea-920c-ade26666d144"
}

Request Types

Type Sample JSON
org.accordproject.iot.DoubleButtonPress
{
    "$class": "org.accordproject.iot.DoubleButtonPress",
    "serialNumber": "Ex eu.",
    "batteryVoltage": "Eiusmod velit pariatur duis velit.",
    "transactionId": "8c1fc760-cd1d-11ea-920c-ade26666d144",
    "timestamp": "2020-07-23T15:48:57.686-04:00"
}
org.accordproject.iot.LongButtonPress
{
    "$class": "org.accordproject.iot.LongButtonPress",
    "serialNumber": "Laborum nisi occaecat consectetur ipsum.",
    "batteryVoltage": "Irure exercitation aliquip.",
    "transactionId": "8c1fc761-cd1d-11ea-920c-ade26666d144",
    "timestamp": "2020-07-23T15:48:57.686-04:00"
}
org.accordproject.iot.SingleButtonPress
{
    "$class": "org.accordproject.iot.SingleButtonPress",
    "serialNumber": "Consectetur.",
    "batteryVoltage": "Ea ut cupidatat quis.",
    "transactionId": "8c1fa051-cd1d-11ea-920c-ade26666d144",
    "timestamp": "2020-07-23T15:48:57.685-04:00"
}
org.accordproject.payment.iot.MonetaryAmountPayment
{
    "$class": "org.accordproject.payment.iot.MonetaryAmountPayment",
    "amount": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 90.558,
        "currencyCode": "ALL"
    },
    "transactionId": "8c1fc762-cd1d-11ea-920c-ade26666d144",
    "timestamp": "2020-07-23T15:48:57.686-04:00"
}
org.accordproject.signature.ContractSigned
{
    "$class": "org.accordproject.signature.ContractSigned",
    "contract": "resource:org.accordproject.payment.iot.PaymentUponButtonContract#2757",
    "transactionId": "8c1fa050-cd1d-11ea-920c-ade26666d144",
    "timestamp": "2020-07-23T15:48:57.685-04:00"
}

Response Types

Type Sample JSON
org.accordproject.cicero.runtime.Response
{
    "$class": "org.accordproject.cicero.runtime.Response",
    "transactionId": "8c1fee74-cd1d-11ea-920c-ade26666d144",
    "timestamp": "2020-07-23T15:48:57.687-04:00"
}

Events Types

Type Sample JSON
org.accordproject.base.Event
{
    "abstract": "this is an abstract type"
}
org.accordproject.cicero.runtime.PaymentObligation
{
    "$class": "org.accordproject.cicero.runtime.PaymentObligation",
    "amount": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 71.538,
        "currencyCode": "XDR"
    },
    "description": "Laborum ad.",
    "contract": "resource:org.accordproject.payment.iot.PaymentUponButtonContract#6339",
    "promisor": "resource:org.accordproject.cicero.contract.AccordParty#0512",
    "promisee": "resource:org.accordproject.cicero.contract.AccordParty#5239",
    "deadline": "2020-07-23T15:48:57.689-04:00",
    "eventId": "8c203c91-cd1d-11ea-920c-ade26666d144",
    "timestamp": "2020-07-23T15:48:57.689-04:00"
}

Technical Integration

Please refer to the Cicero documentation for details and examples of how to integrate a call to a Cicero template into your application.

View the Latest code for this template on GitHub.