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: str, data_transmitter: str, data_recipient: str, date: Optional[datetime.date] = None, assignments: List[Assignment] = 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: Optional[str] = None, number: str, account: str, date: Optional[datetime.date] = None) → netsgiro.objects.Assignment[source]

Add an assignment to the transmission.

classmethod from_records(records: List[R]) → 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() → Iterable[Record][source]

Convert the transmission to a list of records.

assignments

List of assignments.

data_recipient

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

data_transmitter

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

date

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

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

Assignment class

class netsgiro.Assignment(service_code: Union[netsgiro.enums.ServiceCode, int, str], type: Union[netsgiro.enums.AssignmentType, int, str], number: str, account: str, agreement_id: Optional[str] = None, date: Optional[datetime.date] = None, transactions: List[Union[Transaction, Agreement, PaymentRequest]] = 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: Optional[str] = None, payer_name: Optional[str] = None, bank_notification: Union[bool, str] = False) → netsgiro.objects.PaymentRequest[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: Optional[str] = None, payer_name: Optional[str] = None, bank_notification: Union[bool, str] = False, validate_due_date: bool = False) → netsgiro.objects.PaymentRequest[source]

Add an AvtaleGiro payment request to the assignment.

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

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

Build an Assignment object from a list of record objects.

get_earliest_transaction_date() → Optional[datetime.date][source]

Get earliest date from the assignment’s transactions.

get_latest_transaction_date() → Optional[datetime.date][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() → Iterable[Union[netsgiro.records.AssignmentStart, netsgiro.records.TransactionAmountItem1, netsgiro.records.TransactionAmountItem2, netsgiro.records.TransactionAmountItem3, netsgiro.records.AssignmentEnd]][source]

Convert the assignment to a list of records.

account

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

agreement_id

Used for OCR Giro.

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

date

Used for OCR Giro.

The date the assignment was generated by Nets.

number

The assignment number. String of 7 digits.

service_code

The service code. One of ServiceCode.

transactions

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

type

The transaction type. One of TransactionType.

Transaction classes

class netsgiro.Agreement(service_code: Union[netsgiro.enums.ServiceCode, int, str], number: int, registration_type: Union[netsgiro.enums.AvtaleGiroRegistrationType, int, str], kid: Optional[str], notify: bool)[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: List[netsgiro.records.AvtaleGiroAgreement]) → netsgiro.objects.Agreement[source]

Build an Agreement object from a list of record objects.

to_records() → Iterable[netsgiro.records.AvtaleGiroAgreement][source]

Convert the agreement to a list of records.

TRANSACTION_TYPE = 94
kid

KID number to identify the customer and invoice.

notify

Whether the payer wants notification about payment requests.

number

Transaction number. Unique and ordered within an assignment.

registration_type

Type of agreement registration update. One of AvtaleGiroRegistrationType.

service_code

The service code. One of ServiceCode.

class netsgiro.PaymentRequest(service_code: Union[netsgiro.enums.ServiceCode, int, str], type: Union[netsgiro.enums.TransactionType, int, str], number: int, date: datetime.date, amount, kid: Optional[str], reference: Optional[str], text: Optional[str], payer_name: Optional[str])[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: List[TR]) → netsgiro.objects.PaymentRequest[source]

Build a Transaction object from a list of record objects.

to_records() → Iterable[Union[netsgiro.records.TransactionAmountItem1, netsgiro.records.TransactionAmountItem2, netsgiro.records.TransactionSpecification]][source]

Convert the transaction to a list of records.

amount

Transaction amount in NOK with two decimals.

amount_in_cents

Transaction amount in NOK cents.

date

The due date.

kid

KID number to identify the customer and invoice.

number

Transaction number. Unique and ordered within an assignment.

payer_name

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

reference

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

service_code

The service code. One of ServiceCode.

text

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

The transaction type. One of TransactionType.

class netsgiro.Transaction(service_code: Union[netsgiro.enums.ServiceCode, int, str], type: Union[netsgiro.enums.TransactionType, int, str], number: int, date: datetime.date, amount, kid: Optional[str], reference: Optional[str], text: Optional[str], centre_id: Optional[str], day_code: Optional[int], partial_settlement_number: Optional[int], partial_settlement_serial_number: Optional[str], sign: Optional[str], form_number: Optional[str], bank_date: Optional[datetime.date], debit_account: Optional[str], filler: Optional[str])[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: List[TR]) → netsgiro.objects.Transaction[source]

Build a Transaction object from a list of record objects.

to_records() → Iterable[Union[netsgiro.records.TransactionAmountItem1, netsgiro.records.TransactionAmountItem2, netsgiro.records.TransactionAmountItem3]][source]

Convert the transaction to a list of records.

amount

Transaction amount in NOK with two decimals.

amount_in_cents

Transaction amount in NOK cents.

bank_date

Used for OCR Giro.

centre_id

Used for OCR Giro.

date

Nets’ processing date.

day_code

Used for OCR Giro.

debit_account

Used for OCR Giro.

form_number

Used for OCR Giro.

kid

KID number to identify the customer and invoice.

number

Transaction number. Unique and ordered within an assignment.

partial_settlement_number

Used for OCR Giro.

partial_settlement_serial_number

Used for OCR Giro.

reference

The value depends on the payment method.

service_code

The service code. One of ServiceCode.

sign

Used for OCR Giro.

text

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

type

The transaction type. One of TransactionType.