Pix Wallet
Add a credit system (digital wallet) via Pix to your WordPress and earn money with paid posts.
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/rafywp/pix-wallet/archive/refs/heads/master.zipReadme
Pix Wallet - WordPress Credit System Plugin
Overview
Pix Wallet is a comprehensive WordPress plugin that implements a credit-based payment system integrated with OpenPix (Brazilian PIX payment system). Users can purchase credits and spend them to publish posts, creating a monetization system for WordPress content creators.
Features
Core Functionality
- Credit Balance Management: Real-time user balance tracking with caching
- OpenPix Integration: Seamless PIX payment processing
- Transaction System: Complete audit trail of all credit operations
- Post Publication Control: Credit verification before post publication
- Package System: Pre-defined credit packages with bonus calculations
- Notification System: Email notifications for purchases and low balance warnings
- Analytics Dashboard: Comprehensive reporting and analytics
- Performance Optimization: Advanced caching and query optimization
- Security Features: CSRF protection, input sanitization, and rate limiting
User Features
- Purchase credits via PIX payments
- View transaction history
- Set up auto-recharge preferences
- Receive balance notifications
- Export transaction data
Admin Features
- Manage credit packages and pricing
- Monitor system performance
- Generate financial reports
- Configure OpenPix settings
- Manage user balances
- View webhook logs
Requirements
- WordPress: 5.0 or higher
- PHP: 7.4 or higher (8.0+ recommended)
- MySQL: 8.0+ or MariaDB 10.5+
- OpenPix Account: For payment processing
- SSL Certificate: Required for secure webhook processing
Installation
Automatic Installation
- Upload the plugin zip file through WordPress admin
- Activate the plugin
- Go to Pix Wallet > Settings to configure
Manual Installation
- Extract the plugin files to
/wp-content/plugins/pix-wallet/ - Activate the plugin through the WordPress admin interface
- Configure the plugin settings
Configuration
OpenPix Setup
- Create an OpenPix account at openpix.com.br
- Get your App ID and API credentials
- Configure webhook URL in your OpenPix dashboard
- Enter credentials in Pix Wallet > OpenPix Settings
General Settings
- Set credit cost per post
- Configure minimum balance requirements
- Enable/disable negative balance
- Set currency preferences
Package Configuration
- Create credit packages with pricing
- Set bonus credit percentages
- Configure package display order
- Mark popular packages
Usage
For Users
Purchasing Credits
- Visit the credit purchase page
- Select a credit package
- Complete PIX payment
- Credits are automatically added to balance
Publishing Posts
- Create post content as usual
- System checks credit balance before publication
- Credits are automatically deducted on publish
- Insufficient balance blocks publication
Managing Balance
- View current balance in admin bar
- Check transaction history
- Set up auto-recharge preferences
- Receive low balance notifications
For Administrators
Package Management
// Create a new credit package
$package_data = array(
'credits' => 1000,
'price' => 9900, // R$ 99.00 in cents
'bonus_credits' => 100,
'name' => '1000 Credits + 100 Bonus'
);
Balance Management
// Add credits to user
$balance_manager = new Pix_Wallet_Balance_Manager();
$balance_manager->add_credits($user_id, $amount, $transaction_id);
// Check user balance
$balance = $balance_manager->get_user_balance($user_id);
Transaction Handling
// Create transaction
$transaction_handler = new Pix_Wallet_Transaction_Handler();
$transaction_id = $transaction_handler->create_purchase_transaction($user_id, $amount, $openpix_data);
API Reference
Balance Manager
class Pix_Wallet_Balance_Manager {
public function get_user_balance($user_id);
public function add_credits($user_id, $amount, $transaction_id);
public function deduct_credits($user_id, $amount, $transaction_id);
public function has_sufficient_balance($user_id, $amount);
public function validate_balance_integrity($user_id);
}
Transaction Handler
class Pix_Wallet_Transaction_Handler {
public function create_transaction($transaction_data);
public function create_purchase_transaction($user_id, $amount, $openpix_data);
public function create_spend_transaction($user_id, $amount, $post_id);
public function update_transaction_status($transaction_id, $status);
public function get_user_transactions($user_id, $filters = array());
}
OpenPix Integration
class Pix_Wallet_OpenPix_Integration {
public function create_charge($amount, $user_id, $description);
public function get_charge_status($charge_id);
public function cancel_charge($charge_id);
public function refund_charge($charge_id, $amount);
public function validate_api_credentials();
}
Hooks and Filters
Action Hooks
// Fired when credits are added to user balance
do_action('pix_wallet_credits_added', $user_id, $amount, $transaction_id);
// Fired when credits are deducted
do_action('pix_wallet_credits_deducted', $user_id, $amount, $transaction_id);
// Fired when transaction is completed
do_action('pix_wallet_transaction_completed', $transaction_id, $transaction_data);
// Fired when payment fails
do_action('pix_wallet_payment_failed', $transaction_id, $reason);
Filter Hooks
// Modify post cost calculation
$cost = apply_filters('pix_wallet_post_cost', $cost, $post_data, $user_id);
// Modify package pricing
$price = apply_filters('pix_wallet_package_price', $price, $package_id, $user_id);
// Modify balance display
$display = apply_filters('pix_wallet_balance_display', $balance, $user_id);
// Modify notification content
$content = apply_filters('pix_wallet_notification_content', $content, $type, $user_id);
Shortcodes
Credit Purchase
[pix_wallet_purchase]
// Display credit packages for purchase
[pix_wallet_purchase package_id="123"]
// Display specific package
[pix_wallet_purchase show_popular="true"]
// Show only popular packages
Balance Display
[pix_wallet_balance]
// Show current user balance
[pix_wallet_balance show_history="true"]
// Include transaction history link
[pix_wallet_balance format="detailed"]
// Show detailed balance information
Transaction History
[pix_wallet_history]
// Show user transaction history
[pix_wallet_history limit="20"]
// Limit number of transactions shown
[pix_wallet_history type="purchase"]
// Show only purchase transactions
Database Schema
Custom Post Types
pix_transaction
post_title: Unique transaction IDpost_content: Transaction detailspost_author: User IDpost_status: Transaction status (pending, completed, failed, cancelled)
Meta Fields:
_pix_transaction_type: purchase, spent, refund, bonus_pix_credit_amount: Credit amount_pix_user_id: User ID_pix_related_post_id: Related post ID (if applicable)_pix_openpix_charge_id: OpenPix charge ID_pix_payment_value: Payment value in cents
pix_credit_package
post_title: Package namepost_content: Package descriptionpost_status: Active/inactive
Meta Fields:
_pix_package_credits: Credit amount_pix_package_price: Price in cents_pix_package_bonus_credits: Bonus credits_pix_package_order: Display order
User Meta Fields
_pix_wallet_balance: Current credit balance_pix_wallet_total_purchased: Total credits purchased_pix_wallet_total_spent: Total credits spent_pix_wallet_notifications: Notification preferences_pix_wallet_auto_recharge: Auto-recharge settings
Security
Input Validation
- All user inputs are sanitized and validated
- SQL injection prevention through prepared statements
- XSS prevention through output escaping
Authentication
- CSRF token validation for all forms
- Nonce verification for admin actions
- User capability checks
Webhook Security
- Signature validation for OpenPix webhooks
- IP filtering for webhook endpoints
- Request rate limiting
Performance
Caching Strategy
- User balance caching with automatic invalidation
- Transaction summary caching
- Package data caching
- Database query optimization
Database Optimization
- Proper indexing on frequently queried fields
- Optimized queries for balance calculations
- Query result pagination for large datasets
Background Processing
- WordPress cron for heavy operations
- Async notification sending
- Batch processing for bulk operations
Testing
The plugin includes comprehensive test coverage:
- Unit Tests: Individual class testing
- Integration Tests: Complete workflow testing
- Security Tests: Vulnerability testing
- Performance Tests: Benchmark testing
Running Tests
# Run all tests
phpunit --configuration phpunit.xml
# Run specific test suite
phpunit tests/unit/
phpunit tests/integration/
phpunit tests/security/
phpunit tests/performance/
# Generate coverage report
phpunit --coverage-html coverage/
Troubleshooting
Common Issues
Payment Not Confirmed
- Check webhook configuration in OpenPix dashboard
- Verify webhook URL is accessible
- Check webhook logs in admin panel
- Ensure SSL certificate is valid
Balance Not Updating
- Clear plugin cache
- Verify transaction status
- Check user permissions
- Run balance integrity check
Post Publication Blocked
- Check user credit balance
- Verify minimum balance settings
- Check category-specific pricing
- Review error logs
Debug Mode
Enable debug mode to see detailed error information:
define('PIX_WALLET_DEBUG', true);
Log Files
Check these logs for troubleshooting:
- WordPress debug log
- Plugin-specific logs in
/wp-content/uploads/pix-wallet-logs/ - Server error logs
Support
Documentation
Community
- GitHub Issues: Report bugs and feature requests
- WordPress.org Support Forum: Community support
Changelog
Version 1.0.0
- Initial release
- Complete credit system implementation
- OpenPix integration
- Admin dashboard
- Performance optimization
- Comprehensive testing suite
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
Development Setup
# Clone repository
git clone https://github.com/your-username/pix-wallet.git
# Install dependencies
composer install
# Run tests
phpunit
# Run code standards check
phpcs --standard=WordPress .
License
This plugin is licensed under the GPL v2 or later.
Credits
- OpenPix API integration
- WordPress Plugin Boilerplate
- Chart.js for analytics
- PHPUnit for testing
For more information, visit the plugin documentation or contact support.