paymentus-xotp 1.0.4
Paymentus Python XOTP SDK
Requires Python: >=3.9
Keywords: paymentus, xotp, payment, api, sdk, transaction

# Paymentus Server Python SDK

## What is the Paymentus Server SDK?
The Paymentus Server SDK is a comprehensive Python-based toolkit that simplifies integration with the Paymentus Server-side APIs. Designed for backend services, it enables secure, streamlined access to Paymentus' powerful XOTP platform—including payments, user management, autopay, account inquiries, and more. The SDK abstracts authentication flows, allowing developers to focus on building functionality without managing token lifecycles manually.

## Features

- **Modular Architecture**: Use individual packages or the unified SDK
- **Type Safety**: Full type hints and validation using Pydantic
- **Automatic Token Management**: Seamless JWT token handling (via paymentus-auth)
- **Error Handling**: Comprehensive error types and messages
- **Configuration Validation**: Runtime validation of configuration options
- **Granular Scope Support**: Targeted API access via granular access scopes
- **XOTP Integration**: Full support for payment API functionality

## Installation

```bash
# Install individual packages
pip install paymentus-auth
pip install paymentus-xotp

# Or install the core package that includes all modules
pip install paymentus-core
```

## Basic Usage

### Using Individual Packages

```python
import asyncio
from paymentus_auth import Auth, AuthConfig

async def main():
    # Create AuthConfig
    auth_config = AuthConfig(
        base_url='https://<environment>.paymentus.com',
        pre_shared_key='shared-256-bit-secret',
        scope=['xotp'],  # Base scopes
        tla='ABC'
    )

    # Initialize Auth SDK
    auth_client = Auth(auth_config)

    # Fetch token
    token = await auth_client.fetch_token()
    print(f"Token: {token}")
    is_token_expired = auth_client.is_token_expired()
    print(f"Token Expired: {is_token_expired}")
    current_token = auth_client.get_current_token()
    print(f"Current Token: {current_token}")

asyncio.run(main())
```

### Using the Unified SDK

```python
import asyncio
from paymentus_core import SDK, CoreConfig, AuthOptions

async def main():
    # Create AuthConfig first
    auth_options = AuthOptions(
        scope=['xotp']
    )

    # Create SDK configuration with authConfig
    config = CoreConfig(
        base_url='https://<environment>.paymentus.com',
        pre_shared_key='shared-256-bit-secret',
        tla='ABC',
        auth=auth_options
    )

    # Initialize SDK
    sdk = SDK(config)

    # Fetch token
    token = await sdk.auth.fetch_token()
    print(f"Token: {token}")
    is_token_expired = sdk.auth.is_token_expired()
    print(f"Token Expired: {is_token_expired}")
    current_token = sdk.auth.get_current_token()
    print(f"Current Token: {current_token}")

asyncio.run(main())
```

## Payment Examples

```python
# Example 1: Make Payment
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions, LoggingOptions
from paymentus_xotp.models import (
    Address, Customer, MakePayment, MakePaymentItem,
    PaymentHeader, PaymentMethod, PaymentMethodTypeEnum,
    CreditCardExpiryDate
)
from paymentus_xotp.logging import LogLevel, Logger, MaskingLevel

async def main():
    # Configure the SDK
    config = CoreConfig(
        base_url='https://<environment>.paymentus.com',
        pre_shared_key='shared-256-bit-secret',
        tla='ABC',
        auth=AuthOptions(
            scope=['xotp:payment']  # scope needed for payment
        ),
        logging=LoggingOptions(
            logger=Logger, # default logger
            level=LogLevel.VERBOSE, # maximum logging
            masking=MaskingLevel.ALL_PII # mask all sensistive data
        )
    )

    # Initialize SDK
    sdk = SDK(config)

    header1 = PaymentHeader(
        account_number='6759373',
        payment_amount=13.21,
        payment_type_code='UTILITY'
    )

    header2 = PaymentHeader(
        account_number='6759375',
        payment_amount=13.21,
        payment_type_code='WATER'
    )

    payment_method = PaymentMethod(
        type=PaymentMethodTypeEnum.VISA,
        account_number='4111111111111111',
        card_holder_name='John Doe',
        credit_card_expiry_date=CreditCardExpiryDate(
            month=12,
            year=2035
        )
    )

    address = Address(
        line1='10 Fifth Ave.',
        state='NY',
        zip_code='12345',
        city='New York',
        country='US'
    )

    customer = Customer(
        first_name='John',
        last_name='Doe',
        email='john@paymentus.com',
        day_phone_nr='9051112233',
        address=address
    )

    payment_item = MakePaymentItem(
        header=[header1, header2],
        payment_method=payment_method,
        customer=customer
    )

    payment_payload = MakePayment(
        payment=payment_item
    )

    try:
        result = await sdk.xotp.make_payment(payment_payload)
        print(result)

        # ----- Sample Output ------
        #payment_response=PaymentResponseList(response=[PaymentResponseItem(account_number='6759373', convenience_fee=1.5, convenience_fee_country='US', convenience_fee_state='OH', convenience_fee_category_code=None, convenience_fee_percent=None, errors=None, payment_amount=13.21, payment_component=None, payment_date='07192025002237', payment_status=<PaymentStatusTypeEnum.ACCEPTED: 'ACCEPTED'>, payment_status_description='Approved', payment_schedule_status=None, reference_number='734944', status=None, staged_id=None, total_amount=14.71, additional_properties={}), PaymentResponseItem(account_number='6759375', convenience_fee=1.5, convenience_fee_country='US', convenience_fee_state='VA', convenience_fee_category_code=None, convenience_fee_percent=None, errors=None, payment_amount=13.21, payment_component=None, payment_date='07192025002241', payment_status=<PaymentStatusTypeEnum.ACCEPTED: 'ACCEPTED'>, payment_status_description='Approved', payment_schedule_status=None, reference_number='734947', status=None, staged_id=None, total_amount=14.71, additional_properties={})], additional_properties={}) additional_properties={}

    
    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```

```python
# Example 2: Refund Payment
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    Address, Customer, Payment, PaymentHeader,
    PaymentMethod, PaymentMethodTypeEnum,
    CreditCardExpiryDate, PaymentRequest
)

async def main():
    try:
        # Configure the SDK
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            ),
            logging=LoggingOptions(
                level=LogLevel.MINIMAL # minimal logging
            )
        )

        sdk = SDK(config)

        header = PaymentHeader(
            account_number='6759370',
            payment_amount=11.22,
            payment_type_code='UTILITY'
        )

        payment_method = PaymentMethod(
            type=PaymentMethodTypeEnum.VISA_IREFUND,
            account_number='4111111111111111',
            card_holder_name='John Doe',
            credit_card_expiry_date=CreditCardExpiryDate(
                month=12,
                year=2035
            )
        )

        address = Address(
            line1='10 Fifth Ave.',
            state='NY',
            zip_code='12345',
            city='New York',
            country='US'
        )

        customer = Customer(
            first_name='John',
            last_name='Doe',
            email='john@paymentus.com',
            day_phone_nr='9051112233',
            address=address
        )

        payment = Payment(
            header=header,
            payment_method=payment_method,
            customer=customer
        )

        refund_payload = PaymentRequest(payment=payment)
        
        result = await sdk.xotp.refund_payment(refund_payload)
        print(result)
    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```

```python
# Example 3: Payment History
import asyncio
import json

from paymentus_core import SDK, CoreConfig, AuthOptions, LoggingOptions
from paymentus_xotp.models import PaymentSearchRequest
from paymentus_xotp.logging import LogLevel


async def main():
    config = CoreConfig(
        base_url='https://<environment>.paymentus.com',
        pre_shared_key='shared-256-bit-secret',
        tla='ABC',
        auth=AuthOptions(
            scope=['xotp:payment']
        ),
        logging=LoggingOptions(
            level=LogLevel.SILENT # no logging
        )
    )

    sdk = SDK(config)

    search_payload = PaymentSearchRequest(
        account_number='6759371',  # required
        date_from = "06182025",
        date_to = "06192025"
    )
    try:
        result = await sdk.xotp.get_payment_history(search_payload)
        print(result)

    except Exception as error:
        print(f"Error occurred: {error}")
        print(json.dumps(str(error), indent=2))

asyncio.run(main())
```
```python
# Example 4: Fetch Last Payment
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import PaymentSearchRequest

async def main():
    config = CoreConfig(
        base_url='https://<environment>.paymentus.com',
        pre_shared_key='shared-256-bit-secret',
        tla='ABC',
        auth=AuthOptions(
            scope=['xotp']
        )
    )

    sdk = SDK(config)

    payment_search_request = PaymentSearchRequest(
        account_number="6759370"
    )
    
    try:
        result = await sdk.xotp.fetch_last_payment(payment_search_request=payment_search_request)
        print(result)
    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```
```python
# Example 5: Conv Fee Calculation
import asyncio

from paymentus_core import SDK, AuthOptions, CoreConfig, LoggingOptions
from paymentus_xotp.exceptions import ApiException
from paymentus_xotp.models import (
    ConvenienceFeeCountryEnum,
    Payment,
    PaymentHeader,
    PaymentMethod,
    PaymentMethodCategoryEnum,
    PaymentMethodTypeEnum,
    PaymentRequest,
    PaymentFailedResponse
)
from paymentus_xotp.logging import LogLevel

async def main():
    core_config = CoreConfig(
        base_url='https://<environment>.paymentus.com',
        pre_shared_key='shared-256-bit-secret',
        tla='ABC',
        auth=AuthOptions(
            scope=['xotp:payment']
        ),
        logging=LoggingOptions(
            level=LogLevel.SILENT # no logging
        )
    )

    sdk = SDK(core_config)

    # Create payment header
    header = PaymentHeader(
        payment_amount=22.00,
        convenience_fee_state="NY",
        convenience_fee_country=ConvenienceFeeCountryEnum.US
    )

    # Create payment method
    method = PaymentMethod(
        type=PaymentMethodTypeEnum.MC
    )

    # Create payment
    payment = Payment(
        header=header,
        payment_method=method,
        payment_method_category=PaymentMethodCategoryEnum.CC
    )

    # Create payment request
    fee_payload = PaymentRequest(
        payment=payment
    )

    try:
        # Call the API
        result = await sdk.xotp.cnv_calculation(fee_payload)
        print(result)
    except ApiException as e:
        # 400 bad request
        if e.status == 400:
            error_response = PaymentFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```

```python
# Example 6: Stage Payment
import asyncio
import json

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    Customer, Payment, PaymentRequest,
    PaymentHeader
)

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        header = PaymentHeader(
            account_number='6759370',
            payment_amount=13.21,
            payment_type_code='UTILITY',
            auth_token1='12345'
        )

        customer = Customer(
            first_name='John',
            last_name='Doe',
            email='john@paymentus.com',
            day_phone_nr='9051112233'
        )

        payment = Payment(
            header=header,
            customer=customer
        )

        stage_payment_payload = PaymentRequest(
            payment=payment
        )

        result = await sdk.xotp.stage_payment(stage_payment_payload)
        print(result)

    except Exception as error:
        print(f"Error occurred: {error}")
        print(json.dumps(str(error), indent=2))

asyncio.run(main())
```

## Autopay Examples

```python
# Example 1: Create Autopay
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    AutopayRequest, Payment, PaymentHeader,
    PaymentMethod, Customer, ScheduleTypeCodeEnum, 
    AutopayFailedResponse
)
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:autopay']
            )
        )

        sdk = SDK(config)

        header = PaymentHeader(
            account_number='6759375',
            payment_type_code='UTILITY',
            schedule_type_code=ScheduleTypeCodeEnum.MONTHLY,
            schedule_day=26,
            payment_amount=21.21
        )

        payment_method = PaymentMethod(
            token='827BFC458708F0B442009C9C9836F7E4B65557FB'
        )

        customer = Customer(
            first_name='John',
            last_name='Doe',
            email='john@paymentus.com',
            day_phone_nr='9051112233'
        )

        payment_schedule = Payment(
            header=header,
            payment_method=payment_method,
            customer=customer
        )

        autopay_payload = AutopayRequest(
            payment_schedule=payment_schedule
        )

        result = await sdk.xotp.create_autopay(autopay_payload)
        print(result)

    except ApiException as e:
        # 400 bad request
        if e.status == 400:
            error_response = AutopayFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 2: Update Autopay
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    AutopayRequest, Payment, PaymentHeader,
    ScheduleTypeCodeEnum, AutopayFailedResponse
)
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:autopay']
            )
        )

        sdk = SDK(config)

        header = PaymentHeader(
            schedule_type_code=ScheduleTypeCodeEnum.MONTHLY,
            schedule_day=13,
            payment_amount=11.09
        )

        payment_schedule = Payment(
            header=header
        )

        autopay_payload = AutopayRequest(
            payment_schedule=payment_schedule
        )

        reference_number = '3420'

        result = await sdk.xotp.update_autopay(reference_number, autopay_payload)
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found
        if e.status == 400 or e.status == 404:
            error_response = AutopayFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 3: Get Autopay By Reference Number
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.exceptions import ApiException
from paymentus_xotp.models import AutopayFailedResponse

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:autopay']
            )
        )

        sdk = SDK(config)

        reference_number = '3420'

        result = await sdk.xotp.get_autopay(reference_number)
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found
        if e.status == 400 or e.status == 404:
            error_response = AutopayFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 4: List Autopay
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import AutopaySearchRequest

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:autopay']
            )
        )

        sdk = SDK(config)

        list_payload = AutopaySearchRequest(
            login_id='user@example.com',
            account_number='6759370'
        )

        result = await sdk.xotp.list_auto_pay(list_payload)
        print(result)

    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```
```python
# Example 5: Stage Autopay
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    Customer, Payment, PaymentRequest,
    PaymentHeader, ScheduleTypeCodeEnum
)

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        header = PaymentHeader(
            account_number='6759372',
            payment_amount=13.21,
            payment_type_code='UTILITY',
            schedule_type_code=ScheduleTypeCodeEnum.MONTHLY,
            schedule_start_date="20250909",
            schedule_day=11,
            auth_token1='12345'
        )

        customer = Customer(
            first_name='John',
            last_name='Doe',
            email='john@paymentus.com',
            day_phone_nr='9051112233'
        )

        payment = Payment(
            header=header,
            customer=customer
        )

        stage_autopay_payload = PaymentRequest(
            payment=payment
        )

        result = await sdk.xotp.stage_autopay(stage_autopay_payload)
        print(result)

    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```
```python
# Example 6: Delete Autopay
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.exceptions import ApiException
from paymentus_xotp.models import AutopayFailedResponse

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        reference_number = '3420'

        result = await sdk.xotp.delete_autopay(reference_number)
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found
        if e.status == 400 or e.status == 404:
            error_response = AutopayFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```



## Account Examples
```python
# Example 1: Account Inquiry
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions, LoggingOptions
from paymentus_xotp.models import AccountInquiryRequest
from paymentus_xotp.logging import LogLevel, MaskingLevel

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            ),
            logging=LoggingOptions(
                level=LogLevel.VERBOSE, # maximum logging
                masking=MaskingLevel.NONE # no masking
            ),
        )

        sdk = SDK(config)

        payload = AccountInquiryRequest(
            account_number='6759370',
            payment_type_code='UTILITY',
            auth_token1='12345',
            include_schedules=True,
            include_last_used_pm=True,
            detailed_info=True
        )

        result = await sdk.xotp.account_inquiry(payload)
        print(result)
    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```
```python
# Example 2: Account Info by Account Number
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        account_number = '6759370'

        result = await sdk.xotp.get_account_info_by_account_number(account_number)
        print(result)

    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```
```python
# Example 3: Account Info by Email
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        email = 'user@example.com'

        result = await sdk.xotp.get_account_info_by_email(email)
        print(result)

    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```
## User Examples
```python
# Example 1: Create User
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    UserRequest,
    UserProfileInfo,
    UserInfo,
    ClientAccountItem,
    UserRequestItem,
    UserFailedResponse
)
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        profile = UserProfileInfo(
            first_name = "Python",
            last_name = "User",
            email = "python-user@example.com" 
        )

        user_info = UserInfo(
            login_id = "python-user@example.com",
            password = "SecretPassword123",
            force_password_change = True,
            profile = profile
        )

        client_account = ClientAccountItem(
            account_number = "6759370",
            payment_type_code = "UTILITY",
            auth_token1 = "12345"
        )

        user_profile = UserRequestItem(
            user_info = user_info,
            client_account = [client_account]
        )

        user_request = UserRequest(
            user_profile = user_profile,
        )

        result = await sdk.xotp.create_user(user_request)
        print(result)
    except ApiException as e:
        # 400 bad request
        if e.status == 400:
            error_response = UserFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 2: Update User
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    UserUpdateRequest,
    UserUpdateRequestItem,
    UserInfo,
    UserProfileInfo,
    UserLoginId,
    UserFailedResponse
)
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        profile = UserProfileInfo(
            day_phone_nr="5559098888",
            zip_code="28202"
        )

        user_info = UserInfo(
            login_id="python-user@example.com",
            profile=profile
        )

        user_with_permission = UserLoginId(
            login_id="admin@example.com"
        )

        user_profile = UserUpdateRequestItem(
            user_info=user_info,
            user=user_with_permission
        )

        update_request = UserUpdateRequest(
            user_profile=user_profile
        )

        result = await sdk.xotp.update_user(update_request)
        print(result)
    except ApiException as e:
        # 400 bad request
        if e.status == 400:
            error_response = UserFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 3: Get User
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import UserFailedResponse
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        login_id = "python-user@example.com"
        
        include_contact_info = True

        result = await sdk.xotp.get_user(login_id, include_contact_info)        
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found error
        if e.status == 400 or e.status == 404:
            error_response = UserFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 4: Delete User
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    UserDeleteRequest,
    UserDeleteRequestItem,
    UserLoginId, 
    UserFailedResponse
)
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        user_to_delete = UserLoginId(
            login_id="python-user@example.com"
        )

        user_with_permission = UserLoginId(
            login_id="admin@example.com"
        )

        user = UserDeleteRequestItem(
            user_info=user_to_delete,
            user=user_with_permission
        )

        delete_request = UserDeleteRequest(
            user_profile=user
        )

        result = await sdk.xotp.delete_user(delete_request)        
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found error
        if e.status == 400 or e.status == 404:
            error_response = UserFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```

## Profile Examples

```python
# Example 1: Create Profile
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    ProfileRequest,
    ProfileRequestItem,
    ProfileUserInfo,
    ProfileCustomer,
    PaymentMethod,
    CreditCardExpiryDate,
    ProfileFailedResponse
)
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:profile']
            )
        )

        sdk = SDK(config)

        payment_method = PaymentMethod(
            type="VISA",
            account_number="4444444444444448",
            credit_card_expiry_date=CreditCardExpiryDate(
                month=12,
                year=2035
            ),
            card_holder_name="Python User"
        )

        user_info = ProfileUserInfo(
            login_id="user@example.com"
        )

        customer = ProfileCustomer(
            first_name="Python",
            last_name="User"
        )

        profile_item = ProfileRequestItem(
            payment_method=payment_method,
            customer=customer,
            user_info=user_info
        )

        profile_request = ProfileRequest(
            profile=profile_item
        )

        result = await sdk.xotp.create_profile(profile_request)
        print(result)

    except ApiException as e:
        # 400 bad request
        if e.status == 400 or e.status == 404:
            error_response = ProfileFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 2: Update Profile
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import ProfileUpdateRequest, ProfileUpdateItem, ProfileFailedResponse
from paymentus_xotp.exceptions import ApiException

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:profile']
            )
        )
        
        sdk = SDK(config)

        profile_item = ProfileUpdateItem(
            profile_description="Main Payment Profile",
            default_flag=True
        )

        update_request = ProfileUpdateRequest(
            profile=profile_item
        )

        profile_token = "some-token"

        result = await sdk.xotp.update_profile(profile_token, update_request)
        print(result)
    except ApiException as e:
        # 400 bad request or 404 not found error
        if e.status == 400 or e.status == 404:
            error_response = ProfileFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 3: Get Profile
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.exceptions import ApiException
from paymentus_xotp.models import ProfileFailedResponse

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:profile']
            )
        )

        sdk = SDK(config)

        profile_token = "some-token"

        result = await sdk.xotp.get_profile(profile_token)
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found error
        if e.status == 400 or e.status == 404:
            error_response = ProfileFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 4: List Profile
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.exceptions import ApiException
from paymentus_xotp.models import ProfileFailedResponse

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)

        login_id = "user@example.com"

        result = await sdk.xotp.get_profiles(login_id)
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found error
        if e.status == 400 or e.status == 404:
            if e.body != '':
                error_response = ProfileFailedResponse.from_json(e.body)
                print(f"Error: {error_response}")
            else:
                print(f"Error: No profiles found for login ID: {login_id}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 5: Delete Profile
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.exceptions import ApiException
from paymentus_xotp.models import ProfileFailedResponse

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp:profile', 'xotp:profile:delete']
            )
        )

        sdk = SDK(config)

        profile_token = "some-token"

        result = await sdk.xotp.delete_profile(profile_token)
        print(result)

    except ApiException as e:
        # 400 bad request or 404 not found error
        if e.status == 400 or e.status == 404:
            error_response = ProfileFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```

## Other Examples
```python
# Example 1: Get Bank Info
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.exceptions import ApiException
from paymentus_xotp.models import BankInfoFailedResponse

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)
        
        routing_number = "021000128"
        
        result = await sdk.xotp.get_bank_info(routing_number)
        print(result)
    except ApiException as e:
        # 404 invalid routing number
        if e.status == 404:
            error_response = BankInfoFailedResponse.from_json(e.body)
            print(f"Error: {error_response}")
        else:
            # Handle other API exceptions
            print(f"API Exception: {e.status} - {e.reason}")
            print(f"Response Body: {e.body}")
    except Exception as e:
        print(f"Exception: {str(e)}")

asyncio.run(main())
```
```python
# Example 2: Resend Email Confirmation
import asyncio

from paymentus_core import SDK, CoreConfig, AuthOptions
from paymentus_xotp.models import (
    ResendEmailRequest, 
    ResendEmailRequestItem, 
    ResendEmailRequestHeader
)

async def main():
    try:
        config = CoreConfig(
            base_url='https://<environment>.paymentus.com',
            pre_shared_key='shared-256-bit-secret',
            tla='ABC',
            auth=AuthOptions(
                scope=['xotp']
            )
        )

        sdk = SDK(config)
        
        header = ResendEmailRequestHeader(
            account_number="6759370",
            reference_number="731358"
        )
        
        payment = ResendEmailRequestItem(
            header=header
        )
        
        resend_request = ResendEmailRequest(
            payment=payment
        )

        result = await sdk.xotp.resend_email_confirmation(resend_request)
        print(result)
    except Exception as error:
        print(f"Error occurred: {error}")

asyncio.run(main())
```

## Custom Logging

You can customize logging by creating a class that extends Logger class:

```python
from paymentus_core import CoreConfig, AuthOptions, LoggingOptions, SDK
from paymentus_xotp.logging import Logger
from paymentus_xotp.middlewares.logging_middleware import LogLevel, MaskingLevel

class MyCustomLogger(Logger):
    """Custom logger implementation that formats log messages with custom prefixes."""

    def info(self, message, *args):
        formatted_message = message % args if args else message
        print(f"[[INFO]] -- {formatted_message}")

    def error(self, message, *args):
        formatted_message = message % args if args else message
        print(f"[[ERROR]] -- {formatted_message}")

    def warn(self, message, *args):
        formatted_message = message % args if args else message
        print