Metadata-Version: 2.4
Name: pesepay
Version: 1.1.0
Summary: Pesepay online payment gateway integration
Author: CodeVirtus
Author-email: developer@codevirtus.com
Keywords: pesepay
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Description-Content-Type: text/markdown
Requires-Dist: requests
Requires-Dist: jsonpickle
Requires-Dist: pycryptodome
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: keywords
Dynamic: requires-dist
Dynamic: summary


### Installation
```shell
pip install pesepay
```

### Getting Started
Import the library into your project/application

```python  
from pesepay import Pesepay
```

Create an instance of the `Pesepay` class using your integration key and encryption key as supplied by Pesepay.

```python 
pesepay = Pesepay("INTEGRATION KEY", "ENCRYPTION KEY");
```

Set return and result urls

```python 
pesepay.result_url = 'https://example.com/result'
pesepay.return_url = 'https://example.com/return'
```

### Sandbox

Pass `True` as the third argument to send all requests to the sandbox environment. It defaults to `False` (production).

```python
pesepay = Pesepay("SANDBOX INTEGRATION KEY", "SANDBOX ENCRYPTION KEY", True)
```

Sandbox base URL: `https://api.test.sandbox.pesepay.com/payments-engine`
Production base URL: `https://api.pesepay.com/api/payments-engine`

Use sandbox keys with the sandbox URL and production keys with the production URL. The sandbox only supports `USD` and the `PZW211` (EcoCash), `PZW204` (Visa) and `PZW205` (Mastercard) payment methods.

### Make seamless payment

Create the payment 
##### NB: Customer email or number should be provided

```python
payment = pesepay.create_payment('CURRECNCY_CODE', 'PAYMENT_METHOD_CODE', 'CUSTOMER_EMAIL', 
   'CUSTOMER_PHONE_NUMBER(OPTIONAL)', 'CUSTOMER_NAME(OPTIONAL)')
```

Create a `dict` of the required fields (if any)
```python
required_fields = {'requiredFieldName': 'requiredFieldValue'}
```

Send of the payment
```python
response = pesepay.make_seamless_payment(payment, 'PAYMENT_REASON', 1.00, required_fields)

if response.success:
    # Save the reference number and/or poll url (used to check the status of a transaction)
    poll_url = response.pollUrl
    reference_number = response.referenceNumber

else:
    # Get Error Message
    message = response.message
```

### Make redirect payment
Create a transaction
```python
transaction = pesepay.create_transaction(amount, 'CURRENCY_CODE', 'PAYMENT_REASON')
```

Initiate the transaction
```python
response = pesepay.initiate_transaction(transaction)

if response.success:
    # Save the reference number and/or poll url (used to check the status of a transaction)
    poll_url = response.pollUrl
    reference_number = response.referenceNumber
    # Get the redirect url and redirect user to complete transaction   
    redirect_url = response.redirectUrl

else:
    # Get Error Message
    message = response.message
```
### Check Payment Status
#### Method 1: Check using reference number
```python
response = pesepay.check_payment(reference_number)
if response.success:
    if response.paid:
        # Payment was successful
else:
    # Get Error Message
    message = response.message
```
#### Method 2: Check using poll url
```python
response = pesepay.poll_transaction(poll_url)
if response.success:
    if response.paid:
        # Payment was successful
else:
    # Get Error Message
    message = response.message
```

### Split payments

A split payment settles part of every payment to a second Pesepay merchant (the beneficiary). Set the split on the transaction (redirect flow) or the payment (seamless flow) before sending it.

```python
# Redirect flow
transaction = pesepay.create_transaction(100.00, 'USD', 'Order #1042')
transaction.set_split_payment('vendor@example.com')

# Seamless flow
payment = pesepay.create_payment('USD', 'PZW211', 'customer@example.com')
payment.set_split_payment('vendor@example.com')
```

The split amount mode is optional and defaults to `PRINCIPAL`:

```python
transaction.set_split_payment('vendor@example.com', Transaction.SPLIT_AMOUNT_MODE_ADD_ON)
```

- `PRINCIPAL` takes the master merchant's share out of the amount you submit.
- `ADD_ON` adds the master merchant's share on top, so the customer is charged more than the amount you send.

The aliases `PRINCIPAL_AMOUNT`, `ADDON`, `ADDED_ON_TOP` and `ON_TOP` are also accepted. Once your application has an accepted split beneficiary, **every** transaction must carry the beneficiary email or initiation will fail.

For full control over the metadata, use `set_payment_metadata` with the raw dict:

```python
transaction.set_payment_metadata({'beneficiaryMerchantEmail': 'vendor@example.com'})
```
