Skip to main content

ThePay API library

Project description

ThePay

Library for accesing ThePay payment gateway from python

https://github.com/nijel/thepay/workflows/Test/badge.svg PyPI package https://codecov.io/gh/nijel/thepay/branch/master/graph/badge.svg

Example

Configure ThePay account

from thepay.config import Config
config = Config()
config.setCredentials(12345, 12345, 'abcdefg12345', 'abcdefg12345')  # Credentials from ThePay account settings

List available payment methods

from thepay.dataApi import DataApi
data_api = DataApi(config)
payments = data_api.getPaymentMethods()

print methods as radio buttons with images

<div>
    {% for payment in payments %}
     <div class="payment-method">
        <input type="radio" name="payment_method" value="{{ payment.id }}" id="payment_{{ payment.id }}">
        <label for="payment_{{ payment.id }}" title="{{ payment.name }}">
           <img src='http://www.thepay.cz/gate/images/logos/public/209x127/{{ payment.id }}.png' alt="{{ payment.name }}">
        </label>
     </div>
    {% endfor %}
</div>

Redirect user to ThePay - create payment

from thepay.payment import Payment

payment = Payment(config)

payment.setValue(321)
payment.setMethodId(13) # ID of payment method from above
payment.setCustomerEmail('test@test.te')
payment.setDescription('Order 123 payment')
payment.setReturnUrl('https://example.com/payment')  # where to redirect user after payment
payment.setMerchantData(123)  # Any custom data - not visible to user

payment.getCreateUrl()  # Redirect user to this URL to begin payment

Check incomming payment

This code should be run on returnUrl from above code

from thepay.payment import ReturnPayment

return_payment = ReturnPayment(config)
return_payment.parseData(self.request.GET)  # Pass all GET received data in form of dict()

if not return_payment.checkSignature():
    return False  # Invalid payment signature

return_payment.getMerchantData()  # -> 123, previously saved custom data
return_payment.getValue()  # -> 321
return_payment.getStatus()  # Order status, see next paragraph
Order statuses
  • 2 = STATUS_OK

  • 3 = STATUS_CANCELED

  • 4 = STATUS_ERROR

  • 6 = STATUS_UNDERPAID

  • 7 = STATUS_WAITING

  • 9 = STATUS_CARD_DEPOSIT

Get info about payment

payment_id = return_payment.getPaymentId()
payment = data_api.getPayment(payment_id)  # returns object with all payment data

License

LGPL

Project details


Release history Release notifications | RSS feed

This version

0.5

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nijel-thepay-0.5.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

nijel_thepay-0.5-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file nijel-thepay-0.5.tar.gz.

File metadata

  • Download URL: nijel-thepay-0.5.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for nijel-thepay-0.5.tar.gz
Algorithm Hash digest
SHA256 77dff6e0b6bf5faf80fd7065caf50c1d5cc3d0e37f8640c4a65153808f6b3aca
MD5 366c094ecc6d1b074c30410adf813cfd
BLAKE2b-256 74efe7843b85bdc5bb8bef65ba2ca734834b537b4a9e8da4d821d7d6885d43f9

See more details on using hashes here.

File details

Details for the file nijel_thepay-0.5-py3-none-any.whl.

File metadata

  • Download URL: nijel_thepay-0.5-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.7

File hashes

Hashes for nijel_thepay-0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e7d4013f52e7cbc4d3c82729bec9ded7ff534e7d45cf7fd650ae69953c7543
MD5 86e1ff995604f9575fe9dc8ec417ddd4
BLAKE2b-256 7f5a78b049d730e310f0db4eceae87a119188f513cc12341dfaf5bf15fd79aee

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page