# LudiaLudom API Client for Python

[![pipeline status](https://dev01.backbone.sk/darujme/ludialudom-python/badges/master/pipeline.svg)](https://dev01.backbone.sk/darujme/ludialudom-python/commits/master)
[![coverage report](https://dev01.backbone.sk/darujme/ludialudom-python/badges/master/coverage.svg)](https://dev01.backbone.sk/darujme/ludialudom-python/commits/master)

Simple API client based on [requests](https://requests.readthedocs.io/en/master/) library aimed for communication
with LudiaLudom (LULU) service. Documentation for API is in [LudiaLudom API.docx](docs/LudiaLudom API.docx).

## Installation

```bash
# Pip
pip install --extra-index-url https://pypi.backbone.sk ludialudom

# easy_install
easy_install -i https://pypi.backbone.sk/simple/ ludialudom

# Manual
python setup.py install
```

### Pipenv

Add backbone source to the top of yours `Pipfile`:

```toml
[[source]]
name = "backbone"
url = "https://{USER}:{PASSWORD}@pypi.backbone.sk/simple"
verify_ssl = true
```

Now you are able to install the package: `pipenv install ludialudom`

## Usage

```python
import ludialudom
import decimal
from datetime import datetime

configuration = ludialudom.Configuration(
	ludialudom.Environment.Sandbox, 'bHVkaWFsdWRvbTpEZXY0UGVvcGxl', 'Pj3$*4QkF{q7-c6BR8_b5%eE&K2fCw?9r/8WY7a!3+Xi}p4HG2=ym&N96d-MxS5!'
)
client = ludialudom.LudiaLudom(configuration)

# Activate a project with id 42
client.project.activate(42)

# Deactivate a project with id 42
client.project.deactivate(42)

# Is the project with id 42 active?
client.project.is_active(42)

# Create payment URL (which is suppose to be passed to user to redirect)
payment_url = client.payment.create_payment_url(
	payment_id=1234, # Unique numeric payment identificator
	project_code=42, # Project ID in LULU
	channel=3, # LULU payment method ID
	amount=decimal.Decimal(50), # Donation value
	name="Arthur", # Given name of donor
	surname="Dent", # Surname of donor
	email="arthur.dent@gmail.com", # E-mail of donor
	start_date=datetime.fromisoformat('2019-01-01'), # Start of periodic payment period (if periodic)
	end_date=datetime.fromisoformat('2020-10-01'), # End of periodic payment period (optional)
	is_mobile=True, # Optimize payment page for mobile devices (optional)
)

# Change amount of periodic payment id 1234
client.payment.change_amount(1234, decimal.Decimal(40))

# Change state of payment id 1234
client.payment.change_state(1234, client.payment.PaymentState.SUSPENDED)

# Get state of payment id 1234
state = client.payment.get_state(1234) # PaymentState
```

## Development

Deploy to backbone PyPi server executing `./publish.sh`

## TODO

- Create Enum object for LULU payment methods
