Skip to main content

A Python wrapper for the Wirecard REST API.

Project description

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',
    origin_ip='127.0.0.1',
)

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.

Project details


Download files

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

Source Distribution

wirecard-0.3.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

wirecard-0.3.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file wirecard-0.3.0.tar.gz.

File metadata

  • Download URL: wirecard-0.3.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.6 Linux/4.15.0-1077-aws

File hashes

Hashes for wirecard-0.3.0.tar.gz
Algorithm Hash digest
SHA256 790c4b27fd83be0f1e76b69d85e933d443049dbbdb60c4f655cdb02eab1eaefc
MD5 7a2529fb7907e2eb5b9adf0de8f03e17
BLAKE2b-256 2aac3e9fac72e91bd266cd814a39c98193c20486cf4afa99f247e3b8ead5a28d

See more details on using hashes here.

File details

Details for the file wirecard-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: wirecard-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.6 Linux/4.15.0-1077-aws

File hashes

Hashes for wirecard-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ec717edff99a57deeb5676d5b0f34d0668e13aea1600bca2886caefb5bb9c6a
MD5 eecbdb00e11c8b08904a003c3ecc6de9
BLAKE2b-256 11c80064c138c15c923f2b9543a8431684c22a1e310ddd194735e7942b52e482

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