paymongo-python


Namepaymongo-python JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/paymongo/paymongo-python
SummaryPayMongo Python Library
upload_time2023-07-11 08:02:17
maintainer
docs_urlNone
authorPayMongo
requires_python
licenseMIT
keywords paymongo
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PayMongo Python Library

PayMongo Python library provides python applications an easy access to the PayMongo API. Explore various classes that can represent API resources on object instantiation. The goal of this library is simplify PayMongo integration with any python application.

## Pending TODOs

- TBD

## Documentation

See the [PayMongo API docs](https://developers.paymongo.com/reference/getting-started-with-your-api).

### Requirements

- Python 3.9.+

## Installation

You don't need this source code unless you want to modify the library. If you just
want to use the package, just run:

```sh
pip3 install paymongo-python
```

If you want to run the library from source:

Create a virtual environment

```sh
python3 -m venv env
```

Activate the virtual environment

```sh
source env/bin/activate
```

Installing package to virtual environment (editable)

```sh
pip3 install -e paymongo-python

python
```

## Usage

The library needs to be configured with your account's secret key which is
available in your [PayMongo Dashboard][api-keys]. Initialize the library to its
value:

```python
import paymongo

# Set api key config
paymongo.api_key='sk_test...'

# Payment Method
payment_method = paymongo.PaymentMethod.retrieve('pm_...')

# Retrieve attributes
payment_method.id
 => "pm_..."

payment_method.type
 => "card"

paymongo.PaymentMethod.create({
  'type': 'card',
  'details': {
    'card_number': '5111111111111118',
    'cvc': '123',
    'exp_month': 3,
    'exp_year': 2025,
  },
  'billing': {
    'address': {
      'line1': 'test line 1',
      'line2': 'test line 2',
      'city': 'Antipolo',
      'state': 'Rizal',
      'postal_code': '1870',
      'country': 'PH'
    },
    'email': 'test@paymongo.com',
    'name': 'Pay Mongo',
    'phone': '09123456789'
  }
})

# Payment Intent
paymongo.PaymentIntent.retrieve('pi_...')

payment_intent = paymongo.PaymentIntent.create({
  'amount': 10000,
  'currency': 'PHP',
  'description': 'Dog Treat',
  'payment_method_allowed': [
    'card'
  ],
  'statement_descriptor': 'BarkerShop'
})

paymongo.PaymentIntent.attach('pi_...', {
  'payment_method': 'pm_...',
  'return_url': 'https://test/success'
})

paymongo.PaymentIntent.cancel('pi_...')

paymongo.PaymentIntent.capture('pi_...', {
  'amount':10000
})

# Payment
paymongo.Payment.retrieve('pay_...')

# Refund
paymongo.Refund.retrieve('ref_...')

paymongo.Refund.create({
  'amount': 10000,
  'payment_id': 'pay_...',
  'reason': 'requested_by_customer',
  'metadata': {
    'merchant': 'test value'
  }
})
```

## Customers

```python
paymongo.Customer.retrieve('cus_...')

paymongo.Customer.create({
  'default_device': 'phone',
  'email': 'test@paymongo.com',
  'first_name': 'Pay',
  'last_name': 'Mongo',
  'phone': '+624123456789'
})

paymongo.Customer.update('cus_...', {
  'default_device': 'phone',
  'email': 'test@paymongo.com',
  'first_name': 'Pay',
  'last_name': 'Mongo',
  'phone': '+649223456789'
})

paymongo.Customer.delete('cus_...')
```

## Links

```python
paymongo.Link.retrieve('link_...')

paymongo.Link.archive('link_...')

paymongo.Link.unarchive('link_...')

paymongo.Link.create({
  'amount': 10000,
  'description': 'link description',
  'remarks': 'link remarks'
})

links = paymongo.Link.all({'reference_number': '1234abc'})
```

## Webhooks

```python
paymongo.Webhook.retrieve('hook_...')

paymongo.Webhook.create({
  'events': ['payment.refunded', 'payment.refund.updated'],
  'url': 'http://localhost:3100/webhook'
})

paymongo.Webhook.disable('hook_...')

paymongo.Webhook.enable('hook_...')

paymongo.Webhook.update('hook_...', {
   'events': ['payment.refunded', 'payment.refund.updated'],
   'url': 'http://localhost:3001/webhook'
})

webhooks = paymongo.Webhook.all()
```

## Handle errors

```python
try:
  payment_intent = paymongo.PaymentIntent.retrieve('pi_...')
except paymongo.StandardException as e:
  # Handle error
  print(e.errors[0].detail)
  print(e.errors[0].code)
```

## Verifying webhook signature

```python
payload = '{"data":{"id":"evt_...","type":"event","attributes":{"type":"source.chargeable"},"created_at":1675323264}}}'
signature_header = 't=1675323267,te=,li=99f...'
webhook_secret_key = 'whsk_...'

try:
  event = paymongo.Webhook.construct_event(
    payload=payload,
    signature_header=signature_header,
    webhook_secret_key=webhook_secret_key
  )

  event.id
  event.type
  event.resource
except paymongo.SignatureVerificationException:
  # Handle invalid signature
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/paymongo/paymongo-python",
    "name": "paymongo-python",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "paymongo",
    "author": "PayMongo",
    "author_email": "support@paymongo.com",
    "download_url": "https://files.pythonhosted.org/packages/7d/43/4d2d6f17fd9f24702e16133b84cfc73b2e530da5ae34b44ed442856d5b28/paymongo-python-0.1.0.tar.gz",
    "platform": null,
    "description": "# PayMongo Python Library\n\nPayMongo Python library provides python applications an easy access to the PayMongo API. Explore various classes that can represent API resources on object instantiation. The goal of this library is simplify PayMongo integration with any python application.\n\n## Pending TODOs\n\n- TBD\n\n## Documentation\n\nSee the [PayMongo API docs](https://developers.paymongo.com/reference/getting-started-with-your-api).\n\n### Requirements\n\n- Python 3.9.+\n\n## Installation\n\nYou don't need this source code unless you want to modify the library. If you just\nwant to use the package, just run:\n\n```sh\npip3 install paymongo-python\n```\n\nIf you want to run the library from source:\n\nCreate a virtual environment\n\n```sh\npython3 -m venv env\n```\n\nActivate the virtual environment\n\n```sh\nsource env/bin/activate\n```\n\nInstalling package to virtual environment (editable)\n\n```sh\npip3 install -e paymongo-python\n\npython\n```\n\n## Usage\n\nThe library needs to be configured with your account's secret key which is\navailable in your [PayMongo Dashboard][api-keys]. Initialize the library to its\nvalue:\n\n```python\nimport paymongo\n\n# Set api key config\npaymongo.api_key='sk_test...'\n\n# Payment Method\npayment_method = paymongo.PaymentMethod.retrieve('pm_...')\n\n# Retrieve attributes\npayment_method.id\n => \"pm_...\"\n\npayment_method.type\n => \"card\"\n\npaymongo.PaymentMethod.create({\n  'type': 'card',\n  'details': {\n    'card_number': '5111111111111118',\n    'cvc': '123',\n    'exp_month': 3,\n    'exp_year': 2025,\n  },\n  'billing': {\n    'address': {\n      'line1': 'test line 1',\n      'line2': 'test line 2',\n      'city': 'Antipolo',\n      'state': 'Rizal',\n      'postal_code': '1870',\n      'country': 'PH'\n    },\n    'email': 'test@paymongo.com',\n    'name': 'Pay Mongo',\n    'phone': '09123456789'\n  }\n})\n\n# Payment Intent\npaymongo.PaymentIntent.retrieve('pi_...')\n\npayment_intent = paymongo.PaymentIntent.create({\n  'amount': 10000,\n  'currency': 'PHP',\n  'description': 'Dog Treat',\n  'payment_method_allowed': [\n    'card'\n  ],\n  'statement_descriptor': 'BarkerShop'\n})\n\npaymongo.PaymentIntent.attach('pi_...', {\n  'payment_method': 'pm_...',\n  'return_url': 'https://test/success'\n})\n\npaymongo.PaymentIntent.cancel('pi_...')\n\npaymongo.PaymentIntent.capture('pi_...', {\n  'amount':10000\n})\n\n# Payment\npaymongo.Payment.retrieve('pay_...')\n\n# Refund\npaymongo.Refund.retrieve('ref_...')\n\npaymongo.Refund.create({\n  'amount': 10000,\n  'payment_id': 'pay_...',\n  'reason': 'requested_by_customer',\n  'metadata': {\n    'merchant': 'test value'\n  }\n})\n```\n\n## Customers\n\n```python\npaymongo.Customer.retrieve('cus_...')\n\npaymongo.Customer.create({\n  'default_device': 'phone',\n  'email': 'test@paymongo.com',\n  'first_name': 'Pay',\n  'last_name': 'Mongo',\n  'phone': '+624123456789'\n})\n\npaymongo.Customer.update('cus_...', {\n  'default_device': 'phone',\n  'email': 'test@paymongo.com',\n  'first_name': 'Pay',\n  'last_name': 'Mongo',\n  'phone': '+649223456789'\n})\n\npaymongo.Customer.delete('cus_...')\n```\n\n## Links\n\n```python\npaymongo.Link.retrieve('link_...')\n\npaymongo.Link.archive('link_...')\n\npaymongo.Link.unarchive('link_...')\n\npaymongo.Link.create({\n  'amount': 10000,\n  'description': 'link description',\n  'remarks': 'link remarks'\n})\n\nlinks = paymongo.Link.all({'reference_number': '1234abc'})\n```\n\n## Webhooks\n\n```python\npaymongo.Webhook.retrieve('hook_...')\n\npaymongo.Webhook.create({\n  'events': ['payment.refunded', 'payment.refund.updated'],\n  'url': 'http://localhost:3100/webhook'\n})\n\npaymongo.Webhook.disable('hook_...')\n\npaymongo.Webhook.enable('hook_...')\n\npaymongo.Webhook.update('hook_...', {\n   'events': ['payment.refunded', 'payment.refund.updated'],\n   'url': 'http://localhost:3001/webhook'\n})\n\nwebhooks = paymongo.Webhook.all()\n```\n\n## Handle errors\n\n```python\ntry:\n  payment_intent = paymongo.PaymentIntent.retrieve('pi_...')\nexcept paymongo.StandardException as e:\n  # Handle error\n  print(e.errors[0].detail)\n  print(e.errors[0].code)\n```\n\n## Verifying webhook signature\n\n```python\npayload = '{\"data\":{\"id\":\"evt_...\",\"type\":\"event\",\"attributes\":{\"type\":\"source.chargeable\"},\"created_at\":1675323264}}}'\nsignature_header = 't=1675323267,te=,li=99f...'\nwebhook_secret_key = 'whsk_...'\n\ntry:\n  event = paymongo.Webhook.construct_event(\n    payload=payload,\n    signature_header=signature_header,\n    webhook_secret_key=webhook_secret_key\n  )\n\n  event.id\n  event.type\n  event.resource\nexcept paymongo.SignatureVerificationException:\n  # Handle invalid signature\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PayMongo Python Library",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/paymongo/paymongo-python"
    },
    "split_keywords": [
        "paymongo"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b42779a47e3897cdae780e38298a93b54ad3aa1e868a40e7dae1b1eb3bae40a8",
                "md5": "2eb7daf06302b37df41c33f10c54102d",
                "sha256": "7e8c29c9916ebf99ae41dc9c6ed8db5088fc43f785e92f2b5fd6329df5ed31b8"
            },
            "downloads": -1,
            "filename": "paymongo_python-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2eb7daf06302b37df41c33f10c54102d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 18291,
            "upload_time": "2023-07-11T08:02:13",
            "upload_time_iso_8601": "2023-07-11T08:02:13.528820Z",
            "url": "https://files.pythonhosted.org/packages/b4/27/79a47e3897cdae780e38298a93b54ad3aa1e868a40e7dae1b1eb3bae40a8/paymongo_python-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7d434d2d6f17fd9f24702e16133b84cfc73b2e530da5ae34b44ed442856d5b28",
                "md5": "1743cf7271edd67156b1f87f460e5040",
                "sha256": "d785d8e2a39e199f8723e9ce91e053367e055859f9cf317d9fe915b206bf47df"
            },
            "downloads": -1,
            "filename": "paymongo-python-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1743cf7271edd67156b1f87f460e5040",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3770850,
            "upload_time": "2023-07-11T08:02:17",
            "upload_time_iso_8601": "2023-07-11T08:02:17.357149Z",
            "url": "https://files.pythonhosted.org/packages/7d/43/4d2d6f17fd9f24702e16133b84cfc73b2e530da5ae34b44ed442856d5b28/paymongo-python-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-11 08:02:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "paymongo",
    "github_project": "paymongo-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "paymongo-python"
}
        
Elapsed time: 0.52793s