Module diem.offchain.types.payment_types

Expand source code
# Copyright (c) The Diem Core Contributors
# SPDX-License-Identifier: Apache-2.0

import time
import typing

from dataclasses import dataclass, field as datafield

from .command_types import CommandType, UUID_REGEX


class KycDataObjectType:
    individual = "individual"
    entity = "entity"


class AbortCode:
    reject_kyc_data = "rejected"


class Status:
    # No status is yet set from this actor.
    none = "none"
    # KYC data about the subaddresses is required by this actor.
    needs_kyc_data = "needs_kyc_data"
    # Transaction is ready for settlement according to this actor
    ready_for_settlement = "ready_for_settlement"
    # Indicates the actor wishes to abort this payment, instead of settling it.
    abort = "abort"
    # KYC data resulted in a soft-match, request additional_kyc_data.
    soft_match = "soft_match"


@dataclass(frozen=True)
class StatusObject:
    # Status of the payment from the perspective of this actor. Required
    status: str = datafield(
        metadata={
            "valid-values": [
                Status.none,
                Status.needs_kyc_data,
                Status.ready_for_settlement,
                Status.abort,
                Status.soft_match,
            ]
        }
    )
    # In the case of an abort status, this field may be used to describe the reason for the abort.
    abort_code: typing.Optional[str] = datafield(default=None)
    # Additional details about this error. To be used only when code is populated
    abort_message: typing.Optional[str] = datafield(default=None)


@dataclass(frozen=True)
class NationalIdObject:
    # Indicates the national ID value - for example, a social security number
    id_value: str
    # Two-letter country code (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
    country: typing.Optional[str] = datafield(default=None)
    # Indicates the type of the ID
    type: typing.Optional[str] = datafield(default=None)


@dataclass(frozen=True)
class AddressObject:
    # The city, district, suburb, town, or village
    city: typing.Optional[str] = datafield(default=None)
    # Two-letter country code (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
    country: typing.Optional[str] = datafield(default=None)
    # Address line 1
    line1: typing.Optional[str] = datafield(default=None)
    # Address line 2 - apartment, unit, etc.
    line2: typing.Optional[str] = datafield(default=None)
    # ZIP or postal code
    postal_code: typing.Optional[str] = datafield(default=None)
    # State, county, province, region.
    state: typing.Optional[str] = datafield(default=None)


@dataclass(frozen=True)
class KycDataObject:
    # Must be either “individual” or “entity”. Required.
    type: str = datafield(metadata={"valid-values": [KycDataObjectType.individual, KycDataObjectType.entity]})
    # Version identifier to allow modifications to KYC data Object without needing to bump version of entire API set. Set to 1
    payload_version: int = datafield(default=1, metadata={"valid-values": [1]})
    # Legal given name of the user for which this KYC data Object applies.
    given_name: typing.Optional[str] = datafield(default=None)
    # Legal surname of the user for which this KYC data Object applies.
    surname: typing.Optional[str] = datafield(default=None)
    # Physical address data for this account
    address: typing.Optional[AddressObject] = datafield(default=None)
    # Date of birth for the holder of this account. Specified as an ISO 8601 calendar date format: https:#en.wikipedia.org/wiki/ISO_8601
    dob: typing.Optional[str] = datafield(default=None)
    # Place of birth for this user. line1 and line2 fields should not be populated for this usage of the address Object
    place_of_birth: typing.Optional[AddressObject] = datafield(default=None)
    # National ID information for the holder of this account
    national_id: typing.Optional[NationalIdObject] = datafield(default=None)
    # Name of the legal entity. Used when subaddress represents a legal entity rather than an individual. KycDataObject should only include one of legal_entity_name OR given_name/surname
    legal_entity_name: typing.Optional[str] = datafield(default=None)


@dataclass(frozen=True)
class PaymentActionObject:
    amount: int
    currency: str
    action: str = datafield(default="charge", metadata={"valid-values": ["charge"]})
    # Unix timestamp (seconds) indicating the time that the payment Command was created.
    timestamp: int = datafield(default_factory=lambda: int(time.time()))


@dataclass(frozen=True)
class PaymentActorObject:
    address: str = datafield(metadata={"write_once": True})
    status: StatusObject
    kyc_data: typing.Optional[KycDataObject] = datafield(default=None, metadata={"write_once": True})
    metadata: typing.Optional[typing.List[str]] = datafield(default=None)
    additional_kyc_data: typing.Optional[str] = datafield(default=None, metadata={"write_once": True})


@dataclass(frozen=True)
class PaymentObject:
    reference_id: str = datafield(metadata={"valid-values": UUID_REGEX})
    sender: PaymentActorObject
    receiver: PaymentActorObject
    action: PaymentActionObject = datafield(metadata={"write_once": True})
    original_payment_reference_id: typing.Optional[str] = datafield(
        default=None, metadata={"immutable": True, "valid-values": UUID_REGEX}
    )
    recipient_signature: typing.Optional[str] = datafield(default=None, metadata={"write_once": True})
    description: typing.Optional[str] = datafield(default=None, metadata={"write_once": True})


@dataclass(frozen=True)
class PaymentCommandObject:
    _ObjectType: str = datafield(metadata={"valid-values": [CommandType.PaymentCommand]})
    payment: PaymentObject

Classes

class AbortCode
Expand source code
class AbortCode:
    reject_kyc_data = "rejected"

Class variables

var reject_kyc_data
class AddressObject (city: Optional[str] = None, country: Optional[str] = None, line1: Optional[str] = None, line2: Optional[str] = None, postal_code: Optional[str] = None, state: Optional[str] = None)

AddressObject(city: Optional[str] = None, country: Optional[str] = None, line1: Optional[str] = None, line2: Optional[str] = None, postal_code: Optional[str] = None, state: Optional[str] = None)

Expand source code
@dataclass(frozen=True)
class AddressObject:
    # The city, district, suburb, town, or village
    city: typing.Optional[str] = datafield(default=None)
    # Two-letter country code (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
    country: typing.Optional[str] = datafield(default=None)
    # Address line 1
    line1: typing.Optional[str] = datafield(default=None)
    # Address line 2 - apartment, unit, etc.
    line2: typing.Optional[str] = datafield(default=None)
    # ZIP or postal code
    postal_code: typing.Optional[str] = datafield(default=None)
    # State, county, province, region.
    state: typing.Optional[str] = datafield(default=None)

Class variables

var city : Optional[str]
var country : Optional[str]
var line1 : Optional[str]
var line2 : Optional[str]
var postal_code : Optional[str]
var state : Optional[str]
class KycDataObject (type: str, payload_version: int = 1, given_name: Optional[str] = None, surname: Optional[str] = None, address: Optional[AddressObject] = None, dob: Optional[str] = None, place_of_birth: Optional[AddressObject] = None, national_id: Optional[NationalIdObject] = None, legal_entity_name: Optional[str] = None)

KycDataObject(type: str, payload_version: int = 1, given_name: Optional[str] = None, surname: Optional[str] = None, address: Optional[diem.offchain.types.payment_types.AddressObject] = None, dob: Optional[str] = None, place_of_birth: Optional[diem.offchain.types.payment_types.AddressObject] = None, national_id: Optional[diem.offchain.types.payment_types.NationalIdObject] = None, legal_entity_name: Optional[str] = None)

Expand source code
@dataclass(frozen=True)
class KycDataObject:
    # Must be either “individual” or “entity”. Required.
    type: str = datafield(metadata={"valid-values": [KycDataObjectType.individual, KycDataObjectType.entity]})
    # Version identifier to allow modifications to KYC data Object without needing to bump version of entire API set. Set to 1
    payload_version: int = datafield(default=1, metadata={"valid-values": [1]})
    # Legal given name of the user for which this KYC data Object applies.
    given_name: typing.Optional[str] = datafield(default=None)
    # Legal surname of the user for which this KYC data Object applies.
    surname: typing.Optional[str] = datafield(default=None)
    # Physical address data for this account
    address: typing.Optional[AddressObject] = datafield(default=None)
    # Date of birth for the holder of this account. Specified as an ISO 8601 calendar date format: https:#en.wikipedia.org/wiki/ISO_8601
    dob: typing.Optional[str] = datafield(default=None)
    # Place of birth for this user. line1 and line2 fields should not be populated for this usage of the address Object
    place_of_birth: typing.Optional[AddressObject] = datafield(default=None)
    # National ID information for the holder of this account
    national_id: typing.Optional[NationalIdObject] = datafield(default=None)
    # Name of the legal entity. Used when subaddress represents a legal entity rather than an individual. KycDataObject should only include one of legal_entity_name OR given_name/surname
    legal_entity_name: typing.Optional[str] = datafield(default=None)

Class variables

var address : Optional[AddressObject]
var dob : Optional[str]
var given_name : Optional[str]
var legal_entity_name : Optional[str]
var national_id : Optional[NationalIdObject]
var payload_version : int
var place_of_birth : Optional[AddressObject]
var surname : Optional[str]
var type : str
class KycDataObjectType
Expand source code
class KycDataObjectType:
    individual = "individual"
    entity = "entity"

Class variables

var entity
var individual
class NationalIdObject (id_value: str, country: Optional[str] = None, type: Optional[str] = None)

NationalIdObject(id_value: str, country: Optional[str] = None, type: Optional[str] = None)

Expand source code
@dataclass(frozen=True)
class NationalIdObject:
    # Indicates the national ID value - for example, a social security number
    id_value: str
    # Two-letter country code (https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)
    country: typing.Optional[str] = datafield(default=None)
    # Indicates the type of the ID
    type: typing.Optional[str] = datafield(default=None)

Class variables

var country : Optional[str]
var id_value : str
var type : Optional[str]
class PaymentActionObject (amount: int, currency: str, action: str = 'charge', timestamp: int = <factory>)

PaymentActionObject(amount: int, currency: str, action: str = 'charge', timestamp: int = )

Expand source code
@dataclass(frozen=True)
class PaymentActionObject:
    amount: int
    currency: str
    action: str = datafield(default="charge", metadata={"valid-values": ["charge"]})
    # Unix timestamp (seconds) indicating the time that the payment Command was created.
    timestamp: int = datafield(default_factory=lambda: int(time.time()))

Class variables

var action : str
var amount : int
var currency : str
var timestamp : int
class PaymentActorObject (address: str, status: StatusObject, kyc_data: Optional[KycDataObject] = None, metadata: Optional[List[str]] = None, additional_kyc_data: Optional[str] = None)

PaymentActorObject(address: str, status: diem.offchain.types.payment_types.StatusObject, kyc_data: Optional[diem.offchain.types.payment_types.KycDataObject] = None, metadata: Optional[List[str]] = None, additional_kyc_data: Optional[str] = None)

Expand source code
@dataclass(frozen=True)
class PaymentActorObject:
    address: str = datafield(metadata={"write_once": True})
    status: StatusObject
    kyc_data: typing.Optional[KycDataObject] = datafield(default=None, metadata={"write_once": True})
    metadata: typing.Optional[typing.List[str]] = datafield(default=None)
    additional_kyc_data: typing.Optional[str] = datafield(default=None, metadata={"write_once": True})

Class variables

var additional_kyc_data : Optional[str]
var address : str
var kyc_data : Optional[KycDataObject]
var metadata : Optional[List[str]]
var statusStatusObject
class PaymentCommandObject (_ObjectType: str, payment: PaymentObject)

PaymentCommandObject(_ObjectType: str, payment: diem.offchain.types.payment_types.PaymentObject)

Expand source code
@dataclass(frozen=True)
class PaymentCommandObject:
    _ObjectType: str = datafield(metadata={"valid-values": [CommandType.PaymentCommand]})
    payment: PaymentObject

Class variables

var paymentPaymentObject
class PaymentObject (reference_id: str, sender: PaymentActorObject, receiver: PaymentActorObject, action: PaymentActionObject, original_payment_reference_id: Optional[str] = None, recipient_signature: Optional[str] = None, description: Optional[str] = None)

PaymentObject(reference_id: str, sender: diem.offchain.types.payment_types.PaymentActorObject, receiver: diem.offchain.types.payment_types.PaymentActorObject, action: diem.offchain.types.payment_types.PaymentActionObject, original_payment_reference_id: Optional[str] = None, recipient_signature: Optional[str] = None, description: Optional[str] = None)

Expand source code
@dataclass(frozen=True)
class PaymentObject:
    reference_id: str = datafield(metadata={"valid-values": UUID_REGEX})
    sender: PaymentActorObject
    receiver: PaymentActorObject
    action: PaymentActionObject = datafield(metadata={"write_once": True})
    original_payment_reference_id: typing.Optional[str] = datafield(
        default=None, metadata={"immutable": True, "valid-values": UUID_REGEX}
    )
    recipient_signature: typing.Optional[str] = datafield(default=None, metadata={"write_once": True})
    description: typing.Optional[str] = datafield(default=None, metadata={"write_once": True})

Class variables

var actionPaymentActionObject
var description : Optional[str]
var original_payment_reference_id : Optional[str]
var receiverPaymentActorObject
var recipient_signature : Optional[str]
var reference_id : str
var senderPaymentActorObject
class Status
Expand source code
class Status:
    # No status is yet set from this actor.
    none = "none"
    # KYC data about the subaddresses is required by this actor.
    needs_kyc_data = "needs_kyc_data"
    # Transaction is ready for settlement according to this actor
    ready_for_settlement = "ready_for_settlement"
    # Indicates the actor wishes to abort this payment, instead of settling it.
    abort = "abort"
    # KYC data resulted in a soft-match, request additional_kyc_data.
    soft_match = "soft_match"

Class variables

var abort
var needs_kyc_data
var none
var ready_for_settlement
var soft_match
class StatusObject (status: str, abort_code: Optional[str] = None, abort_message: Optional[str] = None)

StatusObject(status: str, abort_code: Optional[str] = None, abort_message: Optional[str] = None)

Expand source code
@dataclass(frozen=True)
class StatusObject:
    # Status of the payment from the perspective of this actor. Required
    status: str = datafield(
        metadata={
            "valid-values": [
                Status.none,
                Status.needs_kyc_data,
                Status.ready_for_settlement,
                Status.abort,
                Status.soft_match,
            ]
        }
    )
    # In the case of an abort status, this field may be used to describe the reason for the abort.
    abort_code: typing.Optional[str] = datafield(default=None)
    # Additional details about this error. To be used only when code is populated
    abort_message: typing.Optional[str] = datafield(default=None)

Class variables

var abort_code : Optional[str]
var abort_message : Optional[str]
var status : str