» Getting Started Templates

Getting Started Templates 

Overview

The Payment Module in the Exsited SDK provides a robust set of tools to handle payment-related operations within your application. It allows developers to streamline payment processing, apply payments to invoices, and retrieve detailed payment histories for auditing or reconciliation purposes. Designed for versatility, this module supports a wide range of payment processors and ensures accurate financial tracking.

Common Import Requirements

The following imports are required when working with any payment-related functions in both Python and PHP.

from exsited.exsited.exsited_sdk import ExsitedSDK
from exsited.common.ab_exception import ABException
from exsited.common.sdk_conf import SDKConfig
from config import CommonData

Function: createBasicPayment

Purpose

The createBasicPayment() function creates a payment for a specified invoice by submitting payment details, including the payment processor, amount, and reference. It also includes additional details such as the payment date and associated notes. The function validates the creation of the payment and returns the payment details upon success.

Parameters 

Parameter
Type
Description
invoice_id
String
The unique identifier for the invoice associated with the payment.
date
String (Date)
The date when the payment was made (format: YYYY-MM-DD).
note
String
A note or description related to the payment.
processor
String
The processor or method of payment (e.g., "Cash", "Credit").
amount
String (Decimal)
The amount of money applied in the payment (e.g., "20.00").
reference
String
A reference or identifier for the payment transaction.

Use Case

This function is used to process payments and apply them to invoices. It is useful when creating payments for outstanding invoices in the system, ensuring the correct amount is applied and reconciling the payment with the invoice.

def test_payment_create_basic():
    SDKConfig.PRINT_REQUEST_DATA = True
    SDKConfig.PRINT_RAW_RESPONSE = False
    exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())
    try:
        payment_applied = PaymentAppliedDTO(processor="PROCESSOR", amount="AMOUNT", reference="REFERENCE")
        payment_data = PaymentDataDTO(date="PAYMENT_DATE", paymentApplied=[payment_applied], note="PAYMENT_NOTE")
        request_data = PaymentCreateDTO(payment=payment_data)
        response = exsited_sdk.payment.create(invoice_id="INVOICE_ID", request_data=request_data)
        print(response)
    except ABException as ab:
        print(ab)
        print(ab.get_errors())
        print(ab.raw_response)

Response

The response contains the details of the created payment, including the payment status, ID, applied amount, payment processor, reference, and invoice details. It also includes reconciliation status, total applied, and timestamps for creation and updates. The response can be used to verify the successful application of the payment to the specified invoice.

ItemResponseDTO(
    item=ItemDataDTO(
        status='STATUS',
        id='ITEM_ID',
        name='ITEM_NAME',
        displayName='DISPLAY_NAME',
        description='DESCRIPTION',
        type='TYPE',
        baseUom='BASE_UOM',
        parentItemId=None,
        origin='ORIGIN',
        createdBy='CREATED_BY',
        createdOn='CREATED_ON',
        lastUpdatedBy='LAST_UPDATED_BY',
        lastUpdatedOn='LAST_UPDATED_ON',
        uuid='UUID',
        version='VERSION',
        imageUri='IMAGE_URI',
        group=None,
        manager=None,
        customForm=CustomFormDTO(
            name='CUSTOM_FORM_NAME',
            uuid='CUSTOM_FORM_UUID'
        ),
        customAttributes=[],
        customObjects=[],
        codes=[
            CodesDTO(name='CODE_NAME_1', value='CODE_VALUE_1'),
            CodesDTO(name='CODE_NAME_2', value='CODE_VALUE_2')
        ],
        uoms=[],
        currencies=[
            CurrenciesDTO(
                name='CURRENCY_NAME_1',
                usedForSale='USED_FOR_SALE',
                defaultForSale='DEFAULT_FOR_SALE',
                usedForPurchase='USED_FOR_PURCHASE',
                defaultForPurchase='DEFAULT_FOR_PURCHASE'
            ),
            CurrenciesDTO(
                name='CURRENCY_NAME_2',
                usedForSale='USED_FOR_SALE',
                defaultForSale='DEFAULT_FOR_SALE',
                usedForPurchase='USED_FOR_PURCHASE',
                defaultForPurchase='DEFAULT_FOR_PURCHASE'
            )
        ],
        sale=SaleDTO(
            enabled='SALE_ENABLED',
            invoiceNote='INVOICE_NOTE',
            accountingCode=AccountingCodeDTO(salesRevenue=None),
            defaultSalePrice='DEFAULT_SALE_PRICE',
            shippingProfile='SHIPPING_PROFILE',
            taxExemptWhenSold='TAX_EXEMPT_WHEN_SOLD',
            pricingMethod='PRICING_METHOD',
            taxConfiguration=SaleTaxConfigurationDTO(
                salePriceEnteredIsInclusiveOfTax='TAX_INCLUDED',
                salePriceIsBasedOn=None,
                taxCode=None
            ),
            pricingProfile=None,
            pricingSchedules=None,
            pricingLevels=[],
            charge=SaleChargeDTO(
                type='CHARGE_TYPE',
                pricePeriod=None,
                properties=[
                    SaleChargePropertiesDTO(name='PROPERTY_NAME_1', value='PROPERTY_VALUE_1'),
                    SaleChargePropertiesDTO(name='PROPERTY_NAME_2', value='PROPERTY_VALUE_2')
                ]
            ),
            paymentProperties=[
                SaleChargePropertiesDTO(name='PROPERTY_NAME_1', value='PROPERTY_VALUE_1'),
                SaleChargePropertiesDTO(name='PROPERTY_NAME_2', value='PROPERTY_VALUE_2')
            ],
            discountProfile={},
            pricing=PricingDTO(
                type='PRICING_TYPE',
                version='VERSION',
                latestUsedPricingVersion='LATEST_PRICING_VERSION',
                pricingModule=[]
            ),
            width=None,
            height=None,
            length=None,
            weight=None,
            useOnSalePrice=None,
            salePriceVariant=None,
            salePrice=None,
            startDate=None,
            endDate=None
        ),
        purchase=PurchaseDTO(
            enabled='PURCHASE_ENABLED',
            enableSupplierManagement='SUPPLIER_MANAGEMENT_ENABLED',
            accountingCode=AccountingCodeDTO(salesRevenue=None),
            purchaseOrderNote='PURCHASE_NOTE',
            defaultPurchasePrice='DEFAULT_PURCHASE_PRICE',
            taxExemptWhenPurchase='TAX_EXEMPT_WHEN_PURCHASED',
            taxConfiguration=PurchaseTaxConfigurationDTO(
                purchasePriceEnteredIsInclusiveOfTax='TAX_INCLUDED'
            ),
            pricingProfile=None,
            purchaseProperties=[
                PurchasePropertiesDTO(name='PROPERTY_NAME_1', value='PROPERTY_VALUE_1'),
                PurchasePropertiesDTO(name='PROPERTY_NAME_2', value='PROPERTY_VALUE_2')
            ],
            pricing=PricingDTO(
                type='PRICING_TYPE',
                version='VERSION',
                latestUsedPricingVersion='LATEST_PRICING_VERSION',
                pricingModule=[]
            ),
            suppliers=None
        ),
        inventories=InventoriesDTO(
            isEnabled='INVENTORY_ENABLED',
            preorderPeriod=None,
            warehouseIsEnabled='WAREHOUSE_ENABLED',
            warehouses=[
                InventoryWarehouseDTO(
                    name='WAREHOUSE_NAME',
                    uuid='WAREHOUSE_UUID',
                    link='WAREHOUSE_LINK',
                    quantityOnHand='QUANTITY_ON_HAND',
                    quantityOnHandValue='QUANTITY_ON_HAND_VALUE',
                    quantityPromised='QUANTITY_PROMISED',
                    quantityOnOrder='QUANTITY_ON_ORDER',
                    quantityOnReturn='QUANTITY_ON_RETURN',
                    quantityOnPurchaseReturn='QUANTITY_ON_PURCHASE_RETURN',
                    quantityAvailable='QUANTITY_AVAILABLE',
                    quantityAvailableValue='QUANTITY_AVAILABLE_VALUE',
                    uom='UOM'
                )
            ],
            inventoryProperties=InventoryPropertiesDTO(
                quantityAvailableForSaleDetermination=['DETERMINATION_METHOD'],
                quantityAvailableForSale='QUANTITY_AVAILABLE_FOR_SALE',
                enableLowStockNotification='ENABLE_LOW_STOCK_NOTIFICATION',
                lowStockThresholdIsBasedOn='LOW_STOCK_THRESHOLD',
                enableReordering='ENABLE_REORDERING',
                reorderingThresholdIsBasedOn='REORDERING_THRESHOLD'
            )
        ),
        kpis=KpisDTO(
            totalRevenue='TOTAL_REVENUE',
            totalCollected='TOTAL_COLLECTED',
            totalOutstanding='TOTAL_OUTSTANDING',
            totalOverdue='TOTAL_OVERDUE'
        )
    )
)

Function: readInvoicePaymentDetails

Purpose

The readInvoicePaymentDetails() function retrieves detailed payment information for a specified invoice. This function is useful for reviewing payment transactions, reconciling records, and ensuring the correct application of payments to the invoice.

Parameters

Parameter Type Description
id String The unique identifier of the invoice for which payment details are being retrieved.

Use Case

This function is used when detailed payment information is required for auditing, customer queries, or verifying payment records against a specific invoice. For example, it can be applied in financial systems to review applied payments and their statuses.

def read_invoice_payment_details():
    SDKConfig.PRINT_REQUEST_DATA = True
    SDKConfig.PRINT_RAW_RESPONSE = True

    exsited_sdk: ExsitedSDK = ExsitedSDK().init_sdk(request_token_dto=CommonData.get_request_token_dto())

    try:
        response = exsited_sdk.payment.invoice_details(id='INVOICE_ID')
        print(response)
    except ABException as ab:
        print(ab)
        print(ab.get_errors())
        print(ab.raw_response)

Response

The function returns detailed information about the payments associated with the specified invoice. This includes the unique payment ID, the amount applied to the invoice, the payment processor used (e.g., card or direct debit), a reference for the transaction, and the current status of the payment, such as successful, pending, or failed.

PaymentInvoiceResponseDTO(
    invoice=PaymentListDTO(
        payments=[
            PaymentDataDTO(
                id='PAYMENT_ID_1',
                date='PAYMENT_DATE_1',
                status='PAYMENT_STATUS_1',
                reconcileStatus='RECONCILE_STATUS_1',
                totalApplied='TOTAL_APPLIED_1',
                paymentApplied=[
                    PaymentAppliedDTO(
                        processor='PROCESSOR_1',
                        amount=AMOUNT_1,
                        reference='REFERENCE_1',
                        method='METHOD_1'
                    )
                ],
                note='NOTE_1',
                creditApplied=[],
                invoices=[
                    InvoiceDTO(
                        applied='APPLIED_AMOUNT_1',
                        code='INVOICE_CODE_1',
                        dueDate='DUE_DATE_1',
                        issueDate='ISSUE_DATE_1',
                        outstanding='OUTSTANDING_AMOUNT_1',
                        total='TOTAL_AMOUNT_1'
                    )
                ],
                createdBy='CREATED_BY_1',
                createdOn='CREATED_ON_1',
                lastUpdatedBy='LAST_UPDATED_BY_1',
                lastUpdatedOn='LAST_UPDATED_ON_1',
                uuid='UUID_1',
                version='VERSION_1',
                customAttributes=[],
                customObjects=[],
                giftCertificateApplied=[]
            ),
            PaymentDataDTO(
                id='PAYMENT_ID_2',
                date='PAYMENT_DATE_2',
                status='PAYMENT_STATUS_2',
                reconcileStatus='RECONCILE_STATUS_2',
                totalApplied='TOTAL_APPLIED_2',
                paymentApplied=[
                    PaymentAppliedDTO(
                        processor='PROCESSOR_2',
                        amount=AMOUNT_2,
                        reference='REFERENCE_2',
                        method='METHOD_2'
                    )
                ],
                note='NOTE_2',
                creditApplied=[],
                invoices=[
                    InvoiceDTO(
                        applied='APPLIED_AMOUNT_2',
                        code='INVOICE_CODE_2',
                        dueDate='DUE_DATE_2',
                        issueDate='ISSUE_DATE_2',
                        outstanding='OUTSTANDING_AMOUNT_2',
                        total='TOTAL_AMOUNT_2'
                    )
                ],
                createdBy='CREATED_BY_2',
                createdOn='CREATED_ON_2',
                lastUpdatedBy='LAST_UPDATED_BY_2',
                lastUpdatedOn='LAST_UPDATED_ON_2',
                uuid='UUID_2',
                version='VERSION_2',
                customAttributes=[],
                customObjects=[],
                giftCertificateApplied=[]
            ),
            PaymentDataDTO(
                id='PAYMENT_ID_3',
                date='PAYMENT_DATE_3',
                status='PAYMENT_STATUS_3',
                reconcileStatus='RECONCILE_STATUS_3',
                totalApplied='TOTAL_APPLIED_3',
                paymentApplied=[
                    PaymentAppliedDTO(
                        processor='PROCESSOR_3',
                        amount=AMOUNT_3,
                        reference='REFERENCE_3',
                        method='METHOD_3'
                    )
                ],
                note='NOTE_3',
                creditApplied=[],
                invoices=[
                    InvoiceDTO(
                        applied='APPLIED_AMOUNT_3',
                        code='INVOICE_CODE_3',
                        dueDate='DUE_DATE_3',
                        issueDate='ISSUE_DATE_3',
                        outstanding='OUTSTANDING_AMOUNT_3',
                        total='TOTAL_AMOUNT_3'
                    )
                ],
                createdBy='CREATED_BY_3',
                createdOn='CREATED_ON_3',
                lastUpdatedBy='LAST_UPDATED_BY_3',
                lastUpdatedOn='LAST_UPDATED_ON_3',
                uuid='UUID_3',
                version='VERSION_3',
                customAttributes=[],
                customObjects=[],
                giftCertificateApplied=[]
            )
        ],
        pagination=PaginationDTO(
            records='TOTAL_RECORDS',
            limit='LIMIT',
            offset='OFFSET',
            previousPage='PREVIOUS_PAGE',
            nextPage='NEXT_PAGE'
        )
    )
)

Configuration

Before using any of these functions, ensure that your API credentials are properly configured.

  • Python: The request token is retrieved from CommonData.get_request_token_dto().
  • PHP: Configuration is managed via ConfigManager and $this->paymentManager.

Language-Specific Features

Feature
Python Implementation
PHP Implementation
SDK Initialization
ExsitedSDK().init_sdk()
$this->paymentManager
Exception Handling
ABException handles errors and raw response
try-catch block for exceptions
Response Format
Prints response using print()
Outputs response using json_encode()
Configuration
Managed through SDKConfig
Managed via ConfigManager
Authentication Method
OAuth token via CommonData.get_request_token_dto()
API credentials via $this->paymentManager
Error Logging
Captures errors with ABException and prints raw response
Captures exceptions and prints error message
Data Parsing
JSON response parsed natively in Python
JSON encoded and displayed using PHP
Error Output
print(ab.get_errors()) and ab.raw_response
echo 'Error: ' . $e->getMessage()