Objects API

The objects API is the higher level API. It parses the “OCR” file into an object structure that for most use cases is more pleasant to work with than the lower level records API.

See the quickstart guide for an introduction to how to use the API.

netsgiro.parse(data: str) → netsgiro.objects.Transmission[source]

Parse an OCR file into a Transmission object.

Transmission class

class netsgiro.Transmission(number, data_transmitter, data_recipient, date=None, assignments=NOTHING)[source]

Transmission is the top-level object.

An OCR file contains a single transmission. The transmission can contain multiple Assignment objects of various types.

add_assignment(*, service_code: netsgiro.enums.ServiceCode, assignment_type: netsgiro.enums.AssignmentType, agreement_id: typing.Union[str, NoneType] = None, number: str, account: str, date: typing.Union[datetime.date, NoneType] = None) → netsgiro.objects.Assignment[source]

Add an assignment to the tranmission.

classmethod from_records(records: typing.List[netsgiro.records.Record]) → netsgiro.objects.Transmission[source]

Build a Transmission object from a list of record objects.

get_num_records() → int[source]

Get number of records in the transmission.

Includes the transmission’s start and end record.

get_num_transactions() → int[source]

Get number of transactions in the transmission.

get_total_amount() → decimal.Decimal[source]

Get the total amount from all transactions in the transmission.

to_ocr() → str[source]

Convert the transmission to an OCR string.

to_records() → typing.Iterable[netsgiro.records.Record][source]

Convert the transmission to a list of records.

assignments = Attribute(name='assignments', default=Factory(factory=<class 'list'>, takes_self=False), validator=None, repr=False, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

List of assignments.

data_recipient = Attribute(name='data_recipient', default=NOTHING, validator=<function str_of_length.<locals>.validator>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Data recipient’s Nets ID. String of 8 digits.

data_transmitter = Attribute(name='data_transmitter', default=NOTHING, validator=<function str_of_length.<locals>.validator>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Data transmitter’s Nets ID. String of 8 digits.

date = Attribute(name='date', default=None, validator=<optional validator for <instance_of validator for type <class 'datetime.date'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

For OCR Giro files from Nets, this is Nets’ processing date.

For AvtaleGiro payment request, the earliest due date in the transmission is automatically used.

number = Attribute(name='number', default=NOTHING, validator=<function str_of_length.<locals>.validator>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Data transmitters unique enumeration of the transmission. String of 7 digits.

Assignment class

class netsgiro.Assignment(service_code, type, number, account, agreement_id=None, date=None, transactions=NOTHING)[source]

An Assignment groups multiple transactions within a transmission.

Use netsgiro.Transmission.add_assignment() to create assignments.

add_payment_cancellation(*, kid: str, due_date: datetime.date, amount: decimal.Decimal, reference: typing.Union[str, NoneType] = None, payer_name: typing.Union[str, NoneType] = None, bank_notification: typing.Union[bool, str] = False) → netsgiro.objects.Transaction[source]

Add an AvtaleGiro cancellation to the assignment.

The assignment must have service code AVTALEGIRO and assignment type AVTALEGIRO_CANCELLATIONS.

Otherwise, the cancellation must be identical to the payment request it is cancelling.

add_payment_request(*, kid: str, due_date: datetime.date, amount: decimal.Decimal, reference: typing.Union[str, NoneType] = None, payer_name: typing.Union[str, NoneType] = None, bank_notification: typing.Union[bool, str] = False) → netsgiro.objects.Transaction[source]

Add an AvtaleGiro payment request to the assignment.

The assignment must have service code AVTALEGIRO and assignment type TRANSACTIONS.

classmethod from_records(records: typing.List[netsgiro.records.Record]) → netsgiro.objects.Assignment[source]

Build an Assignment object from a list of record objects.

get_earliest_transaction_date() → typing.Union[datetime.date, NoneType][source]

Get earliest date from the assignment’s transactions.

get_latest_transaction_date() → typing.Union[datetime.date, NoneType][source]

Get latest date from the assignment’s transactions.

get_num_records() → int[source]

Get number of records in the assignment.

Includes the assignment’s start and end record.

get_num_transactions() → int[source]

Get number of transactions in the assignment.

get_total_amount() → decimal.Decimal[source]

Get the total amount from all transactions in the assignment.

to_records() → typing.Iterable[netsgiro.records.Record][source]

Convert the assignment to a list of records.

account = Attribute(name='account', default=NOTHING, validator=<function str_of_length.<locals>.validator>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

The payee’s bank account. String of 11 digits.

agreement_id = Attribute(name='agreement_id', default=None, validator=<optional validator for <function str_of_length.<locals>.validator> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

The payee’s agreement ID with Nets. String of 9 digits.

date = Attribute(name='date', default=None, validator=<optional validator for <instance_of validator for type <class 'datetime.date'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

The date the assignment was generated by Nets.

number = Attribute(name='number', default=NOTHING, validator=<function str_of_length.<locals>.validator>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

The assignment number. String of 7 digits.

service_code = Attribute(name='service_code', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'ServiceCode'>, metadata=mappingproxy({}))

The service code. One of ServiceCode.

transactions = Attribute(name='transactions', default=Factory(factory=<class 'list'>, takes_self=False), validator=None, repr=False, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

List of transaction objects, like Agreement, PaymentRequest, Transaction.

type = Attribute(name='type', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'AssignmentType'>, metadata=mappingproxy({}))

The transaction type. One of TransactionType.

Transaction classes

class netsgiro.Agreement(service_code, number, registration_type, kid, notify)[source]

Agreement contains an AvtaleGiro agreement update.

Agreements are only found in assignments of the AVTALEGIRO_AGREEMENTS type, which are only created by Nets.

classmethod from_records(records: typing.List[netsgiro.records.Record]) → netsgiro.objects.Agreement[source]

Build an Agreement object from a list of record objects.

to_records() → typing.Iterable[netsgiro.records.Record][source]

Convert the agreement to a list of records.

TRANSACTION_TYPE = 94
kid = Attribute(name='kid', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

KID number to identify the customer and invoice.

notify = Attribute(name='notify', default=NOTHING, validator=<instance_of validator for type <class 'bool'>>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Whether the payer wants notification about payment requests.

number = Attribute(name='number', default=NOTHING, validator=<instance_of validator for type <class 'int'>>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Transaction number. Unique and ordered within an assignment.

registration_type = Attribute(name='registration_type', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'AvtaleGiroRegistrationType'>, metadata=mappingproxy({}))

Type of agreement registration update. One of AvtaleGiroRegistrationType.

service_code = Attribute(name='service_code', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'ServiceCode'>, metadata=mappingproxy({}))

The service code. One of ServiceCode.

class netsgiro.PaymentRequest(service_code, type, number, date, amount, kid, reference, text, payer_name)[source]

PaymentRequest contains an AvtaleGiro payment request or cancellation.

To create a transaction, you will normally use the helper methods on Assignment: add_payment_request() and add_payment_cancellation().

classmethod from_records(records: typing.List[netsgiro.records.Record]) → netsgiro.objects.Transaction[source]

Build a Transaction object from a list of record objects.

to_records() → typing.Iterable[netsgiro.records.Record][source]

Convert the transaction to a list of records.

amount = Attribute(name='amount', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<class 'decimal.Decimal'>, metadata=mappingproxy({}))

Transaction amount in NOK with two decimals.

amount_in_cents

Transaction amount in NOK cents.

date = Attribute(name='date', default=NOTHING, validator=<instance_of validator for type <class 'datetime.date'>>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

The due date.

kid = Attribute(name='kid', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

KID number to identify the customer and invoice.

number = Attribute(name='number', default=NOTHING, validator=<instance_of validator for type <class 'int'>>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Transaction number. Unique and ordered within an assignment.

payer_name = Attribute(name='payer_name', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

The value is only used to help the payee cross-reference reports from Nets with their own records. It is not visible to the payer.

reference = Attribute(name='reference', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

This is a specification line that will, if set, be displayed on the payers account statement. Alphanumeric, max 25 chars.

service_code = Attribute(name='service_code', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'ServiceCode'>, metadata=mappingproxy({}))

The service code. One of ServiceCode.

text = Attribute(name='text', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

This is up to 42 lines of 80 chars each of free text used by the bank to notify the payer about the payment request. It is not used if the payee is responsible for notifying the payer.

type = Attribute(name='type', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'TransactionType'>, metadata=mappingproxy({}))

The transaction type. One of TransactionType.

class netsgiro.Transaction(service_code, type, number, date, amount, kid, reference, text, centre_id, day_code, partial_settlement_number, partial_settlement_serial_number, sign, form_number, bank_date, debit_account, filler)[source]

Transaction contains an OCR Giro transaction.

Transactions are found in assignments with the service code OCR_GIRO type, which are only created by Nets.

classmethod from_records(records: typing.List[netsgiro.records.Record]) → netsgiro.objects.Transaction[source]

Build a Transaction object from a list of record objects.

to_records() → typing.Iterable[netsgiro.records.Record][source]

Convert the transaction to a list of records.

amount = Attribute(name='amount', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<class 'decimal.Decimal'>, metadata=mappingproxy({}))

Transaction amount in NOK with two decimals.

amount_in_cents

Transaction amount in NOK cents.

bank_date = Attribute(name='bank_date', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'datetime.date'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

centre_id = Attribute(name='centre_id', default=NOTHING, validator=<optional validator for <function str_of_length.<locals>.validator> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

date = Attribute(name='date', default=NOTHING, validator=<instance_of validator for type <class 'datetime.date'>>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Nets’ processing date.

day_code = Attribute(name='day_code', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'int'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

debit_account = Attribute(name='debit_account', default=NOTHING, validator=<optional validator for <function str_of_length.<locals>.validator> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

form_number = Attribute(name='form_number', default=NOTHING, validator=<optional validator for <function str_of_length.<locals>.validator> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

kid = Attribute(name='kid', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

KID number to identify the customer and invoice.

number = Attribute(name='number', default=NOTHING, validator=<instance_of validator for type <class 'int'>>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Transaction number. Unique and ordered within an assignment.

partial_settlement_number = Attribute(name='partial_settlement_number', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'int'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

partial_settlement_serial_number = Attribute(name='partial_settlement_serial_number', default=NOTHING, validator=<optional validator for <function str_of_length.<locals>.validator> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

reference = Attribute(name='reference', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

The value depends on the payment method.

service_code = Attribute(name='service_code', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'ServiceCode'>, metadata=mappingproxy({}))

The service code. One of ServiceCode.

sign = Attribute(name='sign', default=NOTHING, validator=<optional validator for <function str_of_length.<locals>.validator> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Used for OCR Giro.

text = Attribute(name='text', default=NOTHING, validator=<optional validator for <instance_of validator for type <class 'str'>> or None>, repr=True, cmp=True, hash=None, init=True, convert=None, metadata=mappingproxy({}))

Up to 40 chars of free text from the payment terminal.

type = Attribute(name='type', default=NOTHING, validator=None, repr=True, cmp=True, hash=None, init=True, convert=<enum 'TransactionType'>, metadata=mappingproxy({}))

The transaction type. One of TransactionType.