Metadata-Version: 2.1
Name: safepay_python
Version: 0.0.5
Summary: Safepay's python SDK for checkout integration
Project-URL: Homepage, https://github.com/getsafepay/safepay-python
Project-URL: Bug Tracker, https://github.com/getsafepay/safepay-python/issues
Author-email: Fatima Aurangzeb <faurangzeb@getsafepay.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.6
Requires-Dist: requests==2.27.1
Requires-Dist: six==1.16.0
Requires-Dist: urllib3==1.26.14
Description-Content-Type: text/markdown

# Safepay Python SDK

Official python library for [Safepay API](https://getsafepay.com).

## Installation

### With Pip

```
pip install safepay-python
```

## Usage

Import and create a Safepay client by passing your config;

```python
from safepay_python.safepay import *

env = Safepay(
    {
        "environment": "sandbox",
        "apiKey": "sec_asd12-2342s-1231s",
        "v1Secret": "bar",
        "webhookSecret": "foo",
    }
)

```

You can now create payments and checkout links.

### Payments

#### Create payment

| Parameter  | Type         | Required |
| ---------- | ------------ | -------- |
| `amount`   | `number`     | Yes      |
| `currency` | `PKR`, `USD` | Yes      |

```python
payment_response = env.set_payment_details({"amount": 10000, "currency": "PKR"})

token = (payment_response['data'])['token']



# Pass `token` to create checkout link
```

### Checkout

#### Create checkout link

| Parameter     | Type      | Description                                   | Required |
| ------------- | --------- | --------------------------------------------- | -------- |
| `token`       | `string`  | Token from `env.set_payment_details`          | Yes      |
| `orderId`     | `string`  | Your internal invoice / order id              | No       |
| `cancelUrl`   | `string`  | Url to redirect to if user cancels the flow   | Yes      |
| `redirectUrl` | `string`  | Url to redirect to if user completes the flow | Yes      |
| `source`      | `string`  | Optional, defaults to `custom`                | No       |
| `webhooks`    | `boolean` | Optional, defaults to `false`                 | No       |

```python
checkout_url = env.get_checkout_url(
    {
        "beacon": token,
        "cancelUrl": "http://example.com/cancel",
        "orderId": "T800",
        "redirectUrl": "http://example.com/success",
        "source": "custom",
        "webhooks": True,
    }
)


# set webhooks = True if want to subscribe to webhooks
# redirect user to `url`
```

### Verification

#### Signature

| Parameter | Type     | Description                             | Required |
| --------- | -------- | --------------------------------------- | -------- |
| `sig`     | `string` | The `signature` string from your server | Yes      |
| `tracker` | `string` | The `tracker` string from your server   | Yes      |

```python
signature_verification = env.is_signature_valid({"sig": "abcd", "tracker": token})


# mark the invoice as paid if valid
# show an error if invalid
```

#### Webhook

| Parameter          | Type     | Description                             | Required |
| ------------------ | -------- | --------------------------------------- | -------- |
| `x-sfpy-signature` | `string` | The `signature` string from your server | Yes      |
| `data`             | `object` | The `data` object from your server      | Yes      |

```python
webhook_verification = env.is_webhook_valid(
    {"x-sfpy-signature": "abcd"}, {"data": data}
)



# mark the invoice as paid if valid
# show an error if invalid
```
