Payment Upon IoT

Author: Accord Project

payment-upon-iot@0.6.1 Contract ^0.20.10 a1868091686540693a3098b3ecdaf7d7916fc98fdcb755bf6008552de11c9b3c

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

Download Archive Open in Template Studio

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",
    "contractId": "ab41d655-93e0-4455-8417-da23e4a48c67",
    "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
}

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": "RUNNING",
    "counter": 28.608,
    "paymentCount": 119.672,
    "stateId": "0333c3f4-7b6c-11ea-b280-c173749a9e96"
}

Request Types

Type Sample JSON
org.accordproject.iot.DoubleButtonPress
{
    "$class": "org.accordproject.iot.DoubleButtonPress",
    "serialNumber": "In amet ullamco.",
    "batteryVoltage": "Non magna incididunt do laborum.",
    "transactionId": "033375d2-7b6c-11ea-b280-c173749a9e96",
    "timestamp": "2020-04-10T16:44:02.861-04:00"
}
org.accordproject.iot.LongButtonPress
{
    "$class": "org.accordproject.iot.LongButtonPress",
    "serialNumber": "Irure voluptate pariatur nulla.",
    "batteryVoltage": "Laborum cillum ex.",
    "transactionId": "033375d3-7b6c-11ea-b280-c173749a9e96",
    "timestamp": "2020-04-10T16:44:02.861-04:00"
}
org.accordproject.iot.SingleButtonPress
{
    "$class": "org.accordproject.iot.SingleButtonPress",
    "serialNumber": "Elit.",
    "batteryVoltage": "Ex ad.",
    "transactionId": "033375d1-7b6c-11ea-b280-c173749a9e96",
    "timestamp": "2020-04-10T16:44:02.861-04:00"
}
org.accordproject.payment.iot.MonetaryAmountPayment
{
    "$class": "org.accordproject.payment.iot.MonetaryAmountPayment",
    "amount": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 7.72,
        "currencyCode": "SHP"
    },
    "transactionId": "03339ce0-7b6c-11ea-b280-c173749a9e96",
    "timestamp": "2020-04-10T16:44:02.862-04:00"
}
org.accordproject.signature.ContractSigned
{
    "$class": "org.accordproject.signature.ContractSigned",
    "contract": "resource:org.accordproject.payment.iot.PaymentUponButtonContract#3276",
    "transactionId": "033375d0-7b6c-11ea-b280-c173749a9e96",
    "timestamp": "2020-04-10T16:44:02.861-04:00"
}

Response Types

Type Sample JSON
org.accordproject.cicero.runtime.Response
{
    "$class": "org.accordproject.cicero.runtime.Response",
    "transactionId": "03339ce5-7b6c-11ea-b280-c173749a9e96",
    "timestamp": "2020-04-10T16:44:02.862-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": 75.039,
        "currencyCode": "AFN"
    },
    "description": "Fugiat magna magna do.",
    "contract": "resource:org.accordproject.payment.iot.PaymentUponButtonContract#1280",
    "promisor": "resource:org.accordproject.cicero.contract.AccordParty#3718",
    "promisee": "resource:org.accordproject.cicero.contract.AccordParty#4119",
    "deadline": "2020-04-10T16:44:02.863-04:00",
    "eventId": "0333c3f5-7b6c-11ea-b280-c173749a9e96",
    "timestamp": "2020-04-10T16:44:02.863-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.