Payment Upon IoT

Author: Accord Project

payment-upon-iot@0.8.0 Contract ^0.22.0 6bedb841a54adef4874f6892455c8a553afcad42ac9871fd5fd07cd2fc4a99f8

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": "resource:org.accordproject.party.Party#Dan",
    "seller": "resource:org.accordproject.party.Party#Grant",
    "amountPerUnit": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 10,
        "currencyCode": "USD"
    },
    "paymentCount": 5,
    "contractId": "26e6ce86-69ee-4967-bc6f-ab422c382512",
    "$identifier": "26e6ce86-69ee-4967-bc6f-ab422c382512"
}

Template Model

namespace org.accordproject.payment.iot

import org.accordproject.contract.* from https://models.accordproject.org/accordproject/contract.cto
import org.accordproject.party.* from https://models.accordproject.org/accordproject/party.cto
import org.accordproject.runtime.* from https://models.accordproject.org/accordproject/runtime.cto
import org.accordproject.obligation.* from https://models.accordproject.org/accordproject/obligation.cto
import org.accordproject.money.MonetaryAmount from https://models.accordproject.org/money@0.2.0.cto

import org.accordproject.payment.PaymentReceived from https://models.accordproject.org/payment/payment@0.2.0.cto
import org.accordproject.signature.ContractSigned from https://models.accordproject.org/signature/signature@0.2.0.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 State {
  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 Contract {
  --> Party buyer
  --> Party 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": "COMPLETED",
    "counter": 187.215,
    "paymentCount": 208.916,
    "$identifier": "8a6a9974-a77b-11eb-9770-7ddd576a12c2"
}

Request Types

Type Sample JSON
org.accordproject.iot.DoubleButtonPress
{
    "$class": "org.accordproject.iot.DoubleButtonPress",
    "serialNumber": "Veniam elit voluptate culpa.",
    "batteryVoltage": "Fugiat cupidatat consequat ea nisi.",
    "$timestamp": "2021-04-27T13:11:00.998-04:00"
}
org.accordproject.iot.LongButtonPress
{
    "$class": "org.accordproject.iot.LongButtonPress",
    "serialNumber": "Ullamco ipsum qui cillum officia.",
    "batteryVoltage": "Reprehenderit culpa Lorem amet.",
    "$timestamp": "2021-04-27T13:11:00.998-04:00"
}
org.accordproject.iot.SingleButtonPress
{
    "$class": "org.accordproject.iot.SingleButtonPress",
    "serialNumber": "Ullamco ex anim.",
    "batteryVoltage": "Laborum tempor ea cillum.",
    "$timestamp": "2021-04-27T13:11:00.997-04:00"
}
org.accordproject.payment.iot.MonetaryAmountPayment
{
    "$class": "org.accordproject.payment.iot.MonetaryAmountPayment",
    "amount": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 208.464,
        "currencyCode": "PYG"
    },
    "$timestamp": "2021-04-27T13:11:00.998-04:00"
}
org.accordproject.signature.ContractSigned
{
    "$class": "org.accordproject.signature.ContractSigned",
    "contract": "resource:org.accordproject.payment.iot.PaymentUponButtonContract#2534",
    "$timestamp": "2021-04-27T13:11:00.997-04:00"
}

Response Types

Type Sample JSON
org.accordproject.runtime.Response
{
    "$class": "org.accordproject.runtime.Response",
    "$timestamp": "2021-04-27T13:11:00.998-04:00"
}

Events Types

Type Sample JSON
concerto.Event
{
    "abstract": "this is an abstract type"
}
org.accordproject.obligation.PaymentObligation
{
    "$class": "org.accordproject.obligation.PaymentObligation",
    "amount": {
        "$class": "org.accordproject.money.MonetaryAmount",
        "doubleValue": 145.401,
        "currencyCode": "KHR"
    },
    "description": "Nisi aute do tempor.",
    "$identifier": "8a6a9975-a77b-11eb-9770-7ddd576a12c2",
    "contract": "resource:org.accordproject.payment.iot.PaymentUponButtonContract#1742",
    "promisor": "resource:org.accordproject.party.Party#7756",
    "promisee": "resource:org.accordproject.party.Party#7710",
    "deadline": "2021-04-27T13:11:00.999-04:00",
    "$timestamp": "2021-04-27T13:11:00.999-04:00"
}

Technical Integration

Please refer to the Accord Project documentation for how to use a template or integrate it within your application.

View the Latest code for this template on GitHub.