Skip to content

RafyWP/pix-wallet

Repository files navigation

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

  1. Upload the plugin zip file through WordPress admin
  2. Activate the plugin
  3. Go to Pix Wallet > Settings to configure

Manual Installation

  1. Extract the plugin files to /wp-content/plugins/pix-wallet/
  2. Activate the plugin through the WordPress admin interface
  3. Configure the plugin settings

Configuration

OpenPix Setup

  1. Create an OpenPix account at openpix.com.br
  2. Get your App ID and API credentials
  3. Configure webhook URL in your OpenPix dashboard
  4. 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

  1. Visit the credit purchase page
  2. Select a credit package
  3. Complete PIX payment
  4. Credits are automatically added to balance

Publishing Posts

  1. Create post content as usual
  2. System checks credit balance before publication
  3. Credits are automatically deducted on publish
  4. 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 ID
  • post_content: Transaction details
  • post_author: User ID
  • post_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 name
  • post_content: Package description
  • post_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

  1. Check webhook configuration in OpenPix dashboard
  2. Verify webhook URL is accessible
  3. Check webhook logs in admin panel
  4. Ensure SSL certificate is valid

Balance Not Updating

  1. Clear plugin cache
  2. Verify transaction status
  3. Check user permissions
  4. Run balance integrity check

Post Publication Blocked

  1. Check user credit balance
  2. Verify minimum balance settings
  3. Check category-specific pricing
  4. 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. 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.

About

Add a credit system (digital wallet) via Pix to your WordPress and earn money with paid posts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published