GPWebPay Gateway access with Python
Project description
gpwebpay
GPWebPay Gateway access with Python.
This library is meant to be used by merchants that own a webshop and use GpWebPay as its payment gateway. At the moment there are code examples for using GPWebPay in a webshop with PHP, where developers can see how to sign and verify messages exchanged with the payment gateway.
With this package you can also do it in Python and you can find an example of its usage in a webshop in the demoshop repository
Configuration
Environmental variables needed:
GPWEBPAY_MERCHANT_ID = "0987654321" # Your merchant's id from gpwebpay
GPWEBPAY_MERCHANT_PRIVATE_KEY = "" # Your merchant's private key base64 encoded (cat gpwebpay-pvk.key | base64 -w0)
GPWEBPAY_PUBLIC_KEY = "" # GPWebPay's public key base64 encoded (cat gpwebpay-pub.key | base64 -w0)
GPWEBPAY_RESPONSE_URL = "" # The url for the callback
Optional:
GPWEBPAY_CURRENCY = "978" # If not set EUR is the default currency
GPWEBPAY_DEPOSIT_FLAG = "1" # Requests instant payment
GPWEBPAY_MERCHANT_PRIVATE_KEY_PASSPHRASE = "" # If any
To use this package create a GpwebpayClient:
import base64
import os
from gpwebpay import gpwebpay
gw = gpwebpay.GpwebpayClient()
# Get your merchant's private key
private_key = os.getenv("GPWEBPAY_MERCHANT_PRIVATE_KEY")
# Decode your private key with base64
private_key_bytes = base64.b64decode(private_key)
# Call this method to request a payment to GPWebPay.
# Returns a response, redirect to response.url to go to GPWebPay's and make the payment
# The order_number needs to be unique and the amount in cents.
gw.request_payment(order_numer="123456", amount=999, key=private_key_bytes)
# Get GPWebPay's public key
public_key = os.getenv("GPWEBPAY_PUBLIC_KEY")
# Decode it with base64
public_key_bytes = base64.b64decode(public_key)
# Call this method to verify the response from GPWebPay
# You need to pass here the url you received on the callback
# Its querystring contains the data to verify the message
gw.get_payment_result(url, key=public_key_bytes)
For more details refer to the GPWebPay documentation
Tests
To run the tests:
pytest
Development
We use poetry to manage dependencies, packaging and publishing. If you want to develop locally install poetry and run:
poetry install
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.