A simple and lightweight Python wrapper for the PayMongo API that allows developers to create payment intents, methods, and attach them using Python code.
- Create Payment Intents
- Create Payment Methods
- Attach a Payment Method to an Intent
- Supports both
card
andgcash
- Supports environment variable or direct secret key assignment
Install via pip:
pip install paymongo-wrapper
You can either:
Create a .env
file:
PAYMONGO_SECRET_KEY=sk_test_your_secret_key
PAYMONGO_PUBLIC_KEY=pk_test_your_public_key
PAYMONGO_RETURN_URL=http://127.0.0.1:8000/
Then load them using python-dotenv
:
from dotenv import load_dotenv
load_dotenv()
from paymongo_wrapper import PayMongoService
paymongo = PayMongoService(
secret_key="sk_test_your_secret_key",
return_url="http://127.0.0.1:8000/"
)
intent = paymongo.create_payment_intent(100.00)
PAYMONGO_SECRET_KEY = "sk_test_your_secret_key"
PAYMONGO_PUBLIC_KEY = "pk_test_your_public_key"
PAYMONGO_RETURN_URL = "http://127.0.0.1:8000/"
from paymongo_wrapper import PayMongoService
paymongo = PayMongoService()
# Step 1: Create a Payment Intent
intent = paymongo.create_payment_intent(amount=100) # PHP 100.00
payment_intent_id = intent['data']['id']
# Step 2: Create a Payment Method
method = paymongo.create_payment_method(
method_type="gcash",
details={"phone": "09171234567"}
)
payment_method_id = method['data']['id']
# Step 3: Attach the Payment Method to the Intent
result = paymongo.attach_payment_intent(payment_intent_id, payment_method_id)
print(result)
The library raises custom exceptions:
PaymentIntentError
PaymentMethodError
AttachIntentError
Wrap your logic in try-except blocks if needed.
Contributions are welcome. Please open an issue or pull request.
This project is licensed under the MIT License. See LICENSE for details.