Skip to main content

Wirecard

A Python wrapper for the Wirecard REST API. Only supports credit card payments with 3D secure enrolment.

CircleCI

All examples below use Wirecard test data. You can find them in the links below:

Setting up environment variables

export WIRECARD_USERNAME='70000-APILUHN-CARD'
export WIRECARD_PASSWORD='8mhwavKVb91T'
export WIRECARD_MERCHANT_ACCOUNT_ID='33f6d473-3036-4ca5-acb5-8c64dac862d1'
export WIRECARD_API_URL='https://api-test.wirecard.com/engine/rest/payments'
export WIRECARD_ORIGIN_IP='127.0.0.1'

Using it

from wirecard import AccountHolder, Card, RequestedAmount, Wirecard


card = Card(
    account_number='4012000300001003',
    expiration_month='01',
    expiration_year='2023',
    security_code='003',
    _type='visa',
)
account_holder = AccountHolder(
    first_name='John',
    last_name='Doe',
)
requested_amount = RequestedAmount(
    amount='10.99',
    currency='ZAR',
)

w = Wirecard()

result = w.check_3d_enrollment(card, account_holder, requested_amount)

# If everything is fine, you should redirect the user to the ACS page
# https://document-center.wirecard.com/display/PTD/Payment+Features#PaymentFeatures-ACSHTTPSRedirect

# Here's a Django View Example
transaction_id = result.get('payment').get('transaction-id')
acs_url = result.get('payment').get('three-d').get('acs-url')
pareq = result.get('payment').get('three-d').get('pareq')

context = {
    'acs_url': acs_url,
    'pareq': pareq,
    'term_url': 'https://your_callback_url',
    'md': f'{"transaction_id": {transaction_id}, "cvv": {card.security_code}}',
}

return render(
    request,
    'acs_template.html',
    context,
)

# The bank successfully calls your callback
# Here's a Django View Example
pares = request.POST.get('PaRes')
md = json.loads(request.POST.get('MD', 'null'))

parent_transaction_id = md['transaction_id']
cvv = md['cvv']

w = Wirecard()
result = w.authorize_and_capture_payment(pares, parent_transaction_id, cvv)

Instead of using environment variables, you can initialize the Wirecard with the necessary information:

w = Wirecard(
    username='70000-APILUHN-CARD',
    password='8mhwavKVb91T',
    merchant_account_id='33f6d473-3036-4ca5-acb5-8c64dac862d1',
    url='https://api-test.wirecard.com/engine/rest/payments',
)

Exceptions

  • WirecardFailedInit: raised when the initialization of Wirecard fails
  • WirecardInvalidCard: raised when an invalid card is given to Card
  • WirecardInvalidRequestedAmount: raised when an invalid card is given to RequestedAmount
  • WirecardFailedTransaction: raised when any communication with the Wirecard platform fails
  • WirecardInvalidResponse: Raised when Wirecard fails to return JSON

Testing

Install poetry.

$ poetry install
$ poetry run pytest

License

MIT.

Release files for wirecard 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wirecard 0.2.4
File Size Uploaded
wirecard-0.2.4.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wirecard 0.2.4
File Interpreter ABI Platform
wirecard-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 20.1 kB

Release files / wirecard-0.2.4.tar.gz

Download URL wirecard-0.2.4.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
70a43a80a46ce8b7e807d420717e4d9aa1d9f389bf4e38bc8c8aaca65124972f
BLAKE2b-256 checksum
How to use checksums
0af230a22ba643054437fdc49214b4e9201fc3172904d3c46482cf8fc6b8361c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.6.8 Linux/4.4.0-141-generic

Release files / wirecard-0.2.4-py3-none-any.whl

Download URL wirecard-0.2.4-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b32f274a3d17938e74a30946581900b9227cf0fa7925409b65f79674e8e821d
BLAKE2b-256 checksum
How to use checksums
ba2404e59736fcde53ffc0167151e5e07b17e86632fbef33769d66f09913aec8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/3.6.8 Linux/4.4.0-141-generic

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.5

2 release files

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page