Python plugin for Paystack View on pypi.python.org
pip install paystackapi
from paystackapi.paystack import Paystack
paystack_secret_key = "5om3secretK3y"
paystack = Paystack(secret_key=paystack_secret_key)
# to use transaction class
paystack.transaction.list()
# to use customer class
paystack.customer.get(transaction_id)
# to use plan class
paystack.plan.get(plan_id)
# to use subscription class
paystack.subscription.list()DOC Reference: https://developers.paystack.co/v2.0/reference
To start using the Paystack Python API, you need to start by setting your secret key.
You can set your secret key in your environment by running:
export PAYSTACK_SECRET_KEY = 'your_secret_key'Don't forget to get your API key from Paystack and assign to the variable
PAYSTACK_SECRET_KEY
Usage
from paystackapi.transaction import Transaction
response = Transaction.initialize(reference='reference',
amount='amount', email='email')Arguments
reference: Unique transaction referenceamount: Amountemail: Email addressplan: Specified plan (optional)
Returns
JSON data from Paystack API.
from paystackapi.transaction import Transaction
response = Transaction.charge(reference='reference',
authorization_code='authorization_code',
email='email',
amount='amount')Arguments
reference: Unique transaction referenceauthorization_code: Authorization code for the transactionemail: Email Address of the user with the authorization codeamount: Amount in kobo
Returns
JSON data from Paystack API.
from paystackapi.transaction import Transaction
response = Transaction.charge_token(reference='reference',
token='token', email='email',
amount='amount')Arguments
- reference: unique transaction reference
- token: paystack token
- email: Email Address
- amount: Amount in Kobo
Returns
JSON data from Paystack API.
from paystackapi.transaction import Transaction
response = Transaction.get(transaction_id=23)Arguments
id: Transaction id(integer).
Returns
JSON data from paystack API.
from paystackapi.transaction import Transaction
response = Transaction.list()Arguments
No argument required.
Returns
JSON data from paystack API.
from paystackapi.transaction import Transaction
response = Transaction.totals()Arguments
No argument required.
Returns
JSON data from paystack API.
from paystackapi.transaction import Transaction
response = Transaction.verify(reference='reference')Arguments
reference: a unique value needed for transaction.
Returns
JSON data from paystack API.
Plan.create(name, description, amount, interval, send_invoices, send_sms, hosted_page, hosted_page_url, hosted_page_summary, currency) - Create a plan
from paystackapi.plan import Plan
response = Plan.create(name='value', description='value',
amount=amount, interval='value',
send_invoices='value',
send_sms='value',
hosted_page='value',
hosted_page_url='value',
hosted_page_summary='value',
currency='value')Arguments
name: plan's name.description: description of the plan.amount: amount for the plan in kobointerval: plan's interval(daily...etc)send_invoices: booleansend_sms: (optional)hosted_page: (optional)hosted_page_url: url of hosted page (optional)hosted_page_summary: summary of the hosted pagecurrency: plans currency (NGN)
Returns
JSON data from paystack API.
from paystackapi.plan import Plan
response = Plan.get(plan_id=25)Arguments
id: paystack plan id.
Returns
JSON data from paystack API.
from paystackapi.plan import Plan
response = Plan.list()Arguments
No argument required.
Returns
JSON data from paystack API.
Plan.update(plan_id=88, name=None, description=None, amount=None, interval=None, send_invoices=None, send_sms=None, hosted_page=None, hosted_page_url=None, hosted_page_summary=None, currency=None) - Update paystack plan
from paystackapi.plan import Plan
response = Plan.update(plan_id=23, name=None, description=None,
amount=None, interval=None,
send_invoices=None, send_sms=None,
hosted_page=None, hosted_page_url=None,
hosted_page_summary=None, currency=None)Arguments
plan_id: plan identity number.name: name of plandescription: plan description(optional)amount: plan amount in Kobointerval: plan interval9(monthly, yearly, quarterly...etc)send_invoice: (optional)send_sms: (optional)hosted_page: (optional)hosted_page_url: (optional)hosted_page_summary: (optional)currency: Naira in kobo(NGN)
Returns
JSON data from paystack API.
from paystackapi.customer import Customer
response = Customer.create(first_name='first_name',
last_name='last_name',
email='email', phone='phone')Arguments
first_name: customer's first name.last_name: customer's last name.email: customer's email address.phone: customer's phone number.
Returns
JSON data from paystack API.
from paystackapi.customer import Customer
response = Customer.get(customer_id=24)Arguments
id: paystack customer id
Returns
JSON data from paystack API.
from paystackapi.customer import Customer
response = Customer.list()Arguments
No argument required.
Returns
JSON data from paystack API.
Customer.update(customer_id, first_name=None, last_name=None, email=None, phone=None) - Update paystack customer data by id.
from paystackapi.customer import Customer
response = Customer.update(customer_id=24, first_name=None,
last_name=None, email=None,
phone=None)Arguments
customer_id: paystack customer id.first_name: customer's first name(optional).last_name: customer's last name(optional).email: customer's email address(optional).phone: customer's phone number(optional).
Returns
JSON data from paystack API.
from paystackapi.subscription import Subscription
response = Subscription.create(customer='CUS_xnxdt6s1zg1f4nx',
plan='Pln_2yudUnIds2p',
authorization='34',
start_date=None)Arguments
customer: Customer's email address or customer code.plan: Plan code.authorization: customers authorization code.start_date: the date for the first debit. (ISO 8601 format)
Returns
JSON data from paystack API.
from paystackapi.subscription import Subscription
response = Subscription.fetch(subscription_id=4033)Arguments
subscription_id: subscription id.
Returns
JSON data from paystack API.
from paystackapi.subscription import Subscription
response = Subscription.list()Arguments
No argument required.
Returns
JSON data from paystack API.
from paystackapi.subscription import Subscription
response = Subscription.disable(code="SUB_vsyqdmlzble3uii",
token="d7gofp6yppn3qz7")Arguments
Arguments
code: Subscription code.token: Email token.
Returns
JSON data from paystack API.
from paystackapi.subscription import Subscription
response = Subscription.enable(code="SUB_vsyqdmlzble3uii",
token="d7gofp6yppn3qz7")Arguments
code: Subscription code.token: Email token.
Returns
JSON data from paystack API.
from paystackapi.verification import Verification
response = Verification.verify_bvn(bvn='1234567890')Arguments
bvn: customer's bvn number
Returns
JSON data from paystack API.
from paystackapi.verification import Verification
response = Verification.verify_account(account_number='1234567890')Arguments
account_number: customer's account number
Returns
JSON data from paystack API.
from paystackapi.verification import Verification
response = Verification.verify_card_bin(card_bin='001')Arguments
card_bin: customer's card bin
Returns
JSON data from paystack API.
Verification.verify_phone(verification_type, phone, callback_url) - verify a customer's phone number
from paystackapi.verification import Verification
response = Verification.verify_phone(
verification_type='truecaller',
phone='090123456890,
callback_url='https://google.com'
)Arguments
verification_type: phone number verification typephone: phone number to be verifiedcallback_url: callback url to send verification details to
Returns
JSON data from paystack API.
from paystackapi.refund import Refund
response = Refund.create(**kwargs)Arguments
transaction: Transaction reference or idamount: How much in kobo to be refunded to the customer - Optionalcurrency: Three-letter ISO currency - Optionalcustomer_note: Customer reason - Optionalmerchant_note: Merchant reason - Optional
Returns
JSON data from paystack API.
from paystackapi.refund import Refund
response = Refund.list(**kwargs)Arguments
reference: Identifier for transaction to be refunded - Optionalcurrency: Three-letter ISO currency - Optional
Returns
JSON data from paystack API.
from paystackapi.refund import Refund
response = Refund.fetch(refund_id=1234)Arguments
refund_id: Refund ID
Returns
JSON data from paystack API.
Usage
from paystackapi.product import Product
response = Product.create(name="Product pypaystack test",
description="my test description",
price=500000, currency="NGN", **kwargs)Arguments
name: Name of the productdescription: Description of productprice: Price of the product, in kobo(Integer)currency: Currency in which amount should be charged- **kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.product import Product
response = Product.list()Arguments
No argument required.
Returns
JSON data from Paystack API.
Usage
from paystackapi.product import Product
response = Product.fetch(product_id=5499)Arguments
product_id: Product id(integer).
Returns
JSON data from Paystack API.
Usage
from paystackapi.product import Product
response = Product.update(product_id=5499, **kwargs)Arguments
product_id: Paystack product id.name: Name of the productdescription: Description of productprice: Price of the product, in kobo(Integer)currency: Currency in which amount should be charged**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.subaccount import SubAccount
response = SubAccount.create(
business_name="Test Biz 123",
settlement_bank="Access Bank",
account_number="xxxxxxxxx",
percentage_charge="6.9"
)Arguments
business_name: Name of business for subaccountsettlement_bank: Name of Bank (accepted banks)account_number: NUBAN Bank Account numberpercentage_charge: Default percentage charged on subaccount?**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.subaccount import SubAccount
response = SubAccount.list(perPage=3, page=1)Arguments
perPage: Records you want to retrieve per page (Integer)page: What page you want to retrieve (Integer)**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.subaccount import SubAccount
response = SubAccount.fetch(id_or_slug="some_slug_like_subaccount_code_or_id)Arguments
id_or_slug: ID or Subaccount_Code
Returns
JSON data from Paystack API.
Usage
from paystackapi.subaccount import SubAccount
response = SubAccount.update(
id_or_slug="some_slug_like_subaccount_code_or_id),
**kwargs
)Arguments
id_or_slug: ID or Subaccount_Codebusiness_name: Name of business for subaccountsettlement_bank: Name of Bank (accepted banks)account_number: NUBAN Bank Account numberpercentage_charge: Default percentage charged on subaccount?**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.page import Page
response = Page.create(
name="New test product One"
)Arguments
name: name of page**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.page import Page
response = Page.list(perPage=3, page=1)Arguments
perPage: records you want to retrieve per page (Integer)page: what page you want to retrieve (Integer)
Returns
JSON data from Paystack API.
Usage
from paystackapi.page import Page
response = Page.fetch(id_or_slug="5nApBwZkvY")Arguments
id_or_slug: id or slug
Returns
JSON data from Paystack API.
Usage
from paystackapi.page import Page
response = Page.update(id_or_slug="5nApBwZkvY", **kwargs)Arguments
id_or_slug: id or slug**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.page import Page
response = Page.is_slug_available(slug="new_or_existing_slug")Arguments
slug: URL slug to be confirmed
Returns
JSON data from Paystack API.
Usage
from paystackapi.page import Page
response = Page.add_products(
payment_page_id="new_or_existing_slug"
product=[123, 456, 457]
)Arguments
payment_page_id: Id of the payment page (Integer)product: Ids of all the products i.e. [473, 292]
Returns
JSON data from Paystack API.
Usage
from paystackapi.settlement import Settlement
response = Settlement.fetch(
from="2016-09-12T00:00:00.000Z",
to="2016-09-12T00:00:00.000Z",
subaccount="subaccount"
)Arguments
start_date: Lower bound of date range. Leave undefined to export settlement from day one.end_date: Upper bound of date range.Leave undefined to export settlements till date.subaccount: code to export only settlements for that subaccount. Set to none to export only transactions for the account.
Returns
JSON data from Paystack API.
Usage
from paystackapi.cpanel import ControlPanel
response = ControlPanel.fetch_payment_session_timeout()Arguments
No argument required.
Returns
JSON data from Paystack API.
Usage
from paystackapi.cpanel import ControlPanel
response = ControlPanel.update_payment_session_timeout(timeout=30)Arguments
timeout: Time before stopping session (in seconds). Set to 0 to cancel session timeouts
Returns
JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.create(
customer="CUS_je02lbimlqixzax",
amount=42000,
due_date="2019-05-08T00:00:00.000Z"
)Arguments
customer: customer id or codeamount: payment request amount.(Integer) Only useful if line items and tax values are ignored. Endpoint will throw a friendly warning if neither is available.due_date: ISO 8601 representation of request due date.**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.list(
customer="CUS_je02lbimlqixzax",
status="pending",
currency="NGN",
paid="false",
include_archive="true"
)Arguments
customer: filter by customer IDstatus: filter by invoice statuscurrency: filter by currencypaid: filter by paid invoiceinclude_archive: include_archive
Returns
JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.view(
invoice_id_or_code="PRQ_kp4lleqc7g8xckk",
)Arguments
invoice_id_or_code: invoice ID or Code (string)
Returns
JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.verify(
invoice_code="PRQ_kp4lleqc7g8xckk",
)Arguments
invoice_code: invoice Code (string)
Returns
JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.send_notification(
id_or_code="PRQ_kp4lleqc7g8xckk",
)Arguments
id_or_code: id or code (string)
Returns
JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.dashboard_metrics()Arguments No Arguments required
Returns JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.finalize_draft(
id_or_code="PRQ_kp4lleqc7g8xckk",
send_notification=False
)Arguments
id_or_code: ID or Code (string)send_notification: Indicates whether Paystack sends an email notification to customer. Defaults to true. (Boolean)
Returns JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.update(
id_or_code="PRQ_kp4lleqc7g8xckk",
amount=450000
)Arguments
id_or_code: ID or Code**kwargs
Returns JSON data from Paystack API.
Usage
from paystackapi.invoice import Invoice
response = Invoice.archive(
id_or_code="PRQ_kp4lleqc7g8xckk",
)Arguments
id_or_code: ID or Code
Returns JSON data from Paystack API.
Invoice.update_transfer_recipient(recipient_code_or_id, **kwargs) - Update transfer recipienta draft
Usage
from paystackapi.invoice import Invoice
response = Invoice.update_transfer_recipient(
recipient_code_or_id="PRQ_kp4lleqc7g8xckk",
name="new name",
email="[email protected]"
)Arguments
recipient_code_or_id: recipient code or IDname: a name for the recipient (string)email: the email address of the recipient (string)
Returns JSON data from Paystack API.
Usage
from paystackapi.trecipient import TransferRecipient
response = TransferRecipient.create(
type="nuban",
name="Zombie",
description="Zombier",
account_number="01000000010",
bank_code="044",
)Arguments
type: Recipient Type (Only nuban at this time)name: A name for the recipientaccount_number: Required if type is nubanbank_code: Required if type is nuban. You can get the list of Bank Codes by calling the List Banks endpoint.**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.trecipient import TransferRecipient
response = TransferRecipient.list(perPage=3, page=1)Arguments
perPage: records you want to retrieve per page (Integer)page: what page you want to retrieve (Integer)
Returns
JSON data from Paystack API.
Usage
from paystackapi.transfer import Transfer
response = Transfer.initiate(
source="balance",
reason="Calm down",
amount="3794800",
recipient="RCP_gx2wn530m0i3w3m",
)Arguments
source: Where should we transfer from? Only balance for nowamount: Amount to transfer in kobocurrency: Currency type to userecipient: Code for transfer recipient**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.transfer import Transfer
response = Transfer.list(perPage=3,page=1)Arguments
perPage: records you want to retrieve per page (Integer)page: what page you want to retrieve (Integer)
Returns
JSON data from Paystack API.
Usage
from paystackapi.transfer import Transfer
response = Transfer.fetch(
id_or_code="TRF_2x5j67tnnw1t98k",
)Arguments
id_or_code: An ID or code for the transfer whose details you want to retrieve.
Returns
JSON data from Paystack API.
Usage
from paystackapi.transfer import Transfer
response = Transfer.finalize(
transfer_code="TRF_2x5j67tnnw1t98k",
otp="928783"
)Arguments
transfer_code: Transfer codeotp: OTP sent to business phone to verify transfer
Returns
JSON data from Paystack API.
Usage
from paystackapi.transfer import Transfer
response = Transfer.initiate_bulk_transfer(
currency="TRF_2x5j67tnnw1t98k",
source="928783",
transfers=[
{
"amount": 50000,
"recipient": "RCP_db342dvqvz9qcrn"
},
{
"amount": 50000,
"recipient": "RCP_db342dvqvz9qcrn"
}
]
)Arguments
currency: Currency type to use
source: Where should we transfer from? Only balance for now
transfers: Array of transfer objects [
{
amount: Amount to transfer in kobo
recipient: Code for transfer recipient
},
{
amount: Amount to transfer in kobo
recipient: Code for transfer recipient
}
]
Returns
JSON data from Paystack API.
Usage
from paystackapi.transfer import Transfer
response = Transfer.verify(
reference="ref_demo",
)Arguments
reference: Transfer reference
Returns
JSON data from Paystack API.
Usage
from paystackapi.charge import Charge
response = Charge.start_charge(
email="CUS_je02lbimlqixzax",
amount=42000,
metadata={
"custom_fields": [
{
"value":"makurdi",
"display_name": "Donation for",
"variable_name": "donation_for"
},
],
},
bank={
"code":"057",
"account_number":"0000000000"
},
birthday="1995-12-23"
)Arguments
email: Customer's email addressamount: Amount in kobo**kwargs
Returns
JSON data from Paystack API.
Usage
from paystackapi.charge import Charge
response = Charge.submit_pin(
pin="0987",
reference="5bwib5v6anhe9xa",
)Arguments
pin: PIN submitted by userreference: reference for transaction that requested pin
Returns
JSON data from Paystack API.
Usage
from paystackapi.charge import Charge
response = Charge.submit_otp(
otp="0987",
reference="5bwib5v6anhe9xa",
)Arguments
otp: OTP submitted by userreference: reference for ongoing transaction
Returns
JSON data from Paystack API.
Usage
from paystackapi.charge import Charge
response = Charge.submit_phone(
phone="0XX4XX9X0XF",
reference="5bwib5v6anhe9xa",
)Arguments
phone: Phone submitted by userreference: reference for ongoing transaction Returns
JSON data from Paystack API.
Usage
from paystackapi.charge import Charge
response = Charge.submit_birthday(
birthday="1975-12-23",
reference="5bwib5v6anhe9xa",
)Arguments
birthday: Birthday submitted by userreference: reference for ongoing transaction
Returns
JSON data from Paystack API.
Usage
from paystackapi.charge import Charge
response = Charge.check_pending(
reference="5bwib5v6anhe9xa",
)Arguments
reference: The reference to check
Returns
JSON data from Paystack API.
Usage
from paystackapi.tcontrol import TransferControl
response = TransferControl.check_balance()Arguments
No argument required.
Returns
JSON data from Paystack API.
Usage
from paystackapi.tcontrol import TransferControl
response = TransferControl.resend_otp(
transfer_code="TRF_vsyqdmlzble3uii",
reason="Just do it."
)Arguments
transfer_code: Transfer codereason: either resend_otp or transfer
Returns
JSON data from Paystack API.
TransferControl.disable_otp_finalize(**kwargs) - Finalize Disabling of OTP requirement for Transfers
Usage
from paystackapi.tcontrol import TransferControl
response = TransferControl.disable_otp_finalize(
otp="928783",
)Arguments
otp: OTP sent to business phone to verify disabling OTP requirement
Returns
JSON data from Paystack API.
Usage
from paystackapi.tcontrol import TransferControl
response = TransferControl.disable_otp()Arguments
No arguments required
Returns
JSON data from Paystack API.
Usage
from paystackapi.tcontrol import TransferControl
response = TransferControl.enable_otp()Arguments
No arguments required
Returns
JSON data from Paystack API.
Misc.list_banks() - List Banks
from paystackapi.misc import Misc
response = Misc.list_banks()Returns
JSON data from paystack API.
