The AgilePay Python sdk will provide convenient access to the AgilePay API from applications written in the Python language. It will include a pre-defined set of classes for API resources that initialize themselves dynamically from API responses which makes it compatible with a wide range of versions of the AgilePay API.
See the Python API docs.
pip install --upgrade agilepay
or
easy_install --upgrade agilepay
Install from source with:
python setup.py install
Register for an account and get your api_key and secret at AgilePay.
import agilepay
agile_pay = AgilePay({
'api_key': 'key',
'api_secret': 'secret'
})
gateway = agile_pay.gateway().create('stripe', {'secret_key': 'stripe-secret-key'})
The response body will contain a gateway reference which is used to perform transactions against the gateway
gateway_reference = gateway.get_body()['reference']
In this case the payment method will be retained with the provided gateway, please check the availability of transaction store in the gateways list
Gateways list -> http://docs.agilepay.io/#!/gateway
Gateway token -> http://docs.agilepay.io/#!/payment-method-create-gateway-token
payment_method = agile_pay.payment_method().create_gateway_token(gateway_reference, {
'cvv': '123',
'number': '4111111111111111',
'holder_name': 'Mario Rossi',
'expiry_month': '12',
'expiry_year': '17'
})
The response body will contain a payment method token which is used to perform transactions against the payment method
payment_method_token = payment_method.get_body()['token']
transaction = agile_pay.transaction().set_payment_method(payment_method_gateway_token).auth(5000, 'EUR') # charging 5.00 euros
The response will contain a reference which can be used for second steps transactions such as void, capture and credit
transaction_reference = transaction.get_body()['reference']
response = agile_pay.transaction(transaction_reference).void();
response = agile_pay.transaction(transaction_reference).capture();
response = agile_pay.transaction(transaction_reference).credit();
Below the response object available methods.
get_status_code() # Retrieves the response status code
get_body() # retrieves the response body as a dictionary