# Devdraft Payment Plugin

A WordPress plugin for creating payments with bank transfer and stablecoin options.

## Features

- **Bank Transfer Support**: ACH Push, Same-day ACH, Wire Transfer, SEPA, SWIFT, SPEI
- **Stablecoin Support**: USDC and EURC transfers across multiple networks
- **Dynamic Form**: Switches between bank transfer and stablecoin options
- **Real-time Summary**: Shows payment details in a sidebar
- **Success/Error Messages**: Displays bank details for transfers and wallet addresses for stablecoins
- **Admin Configuration**: Easy setup through WordPress admin panel

## Installation

1. Upload the plugin files to the WordPress plugins directory
2. Activate the plugin through the 'Plugins' menu in WordPress
3. Configure the plugin settings at Settings > Payment

## External Service Usage

**Important**: This plugin connects to external payment processing services operated by Devdraft. When you use this plugin, data will be transmitted to Devdraft's servers under the following circumstances:

- **When**: Payments are created through the form
- **What Data**: Customer information (name, email), payment amounts, payment method details, and destination addresses
- **Where**: Data is sent to the Devdraft Payment API at https://api.devdraft.ai
- **Why**: To process payment transactions and provide banking/stablecoin transfer services

**Legal Notice**: By using this plugin, you acknowledge that:

- Customer data will be shared with Devdraft for payment processing
- You are responsible for ensuring compliance with applicable privacy laws
- You should review Devdraft's terms of service and privacy policy

**Service Provider Information**:

- **Service**: Devdraft Payment API
- **Provider**: Devdraft Inc.
- **Website**: https://devdraft.ai
- **Terms of Service**: https://devdraft.ai/terms
- **Privacy Policy**: https://devdraft.ai/privacy
- **API Documentation**: https://devdraft.ai/docs

For questions about data handling, contact Devdraft directly through their official channels.

## Configuration

### Required Settings

1. **API Configuration**:

   - API Key: Your Devdraft API client key
   - API Secret: Your Devdraft API client secret
   - API Host: Your Devdraft API host URL (e.g., https://api.devdraft.ai)

2. **Destination Configuration**:

   - USDC Destination Address: Wallet address for USDC transfers
   - USDC Network: Network for USDC transfers (Ethereum, Polygon, etc.)
   - EURC Destination Address: Wallet address for EURC transfers
   - EURC Network: Network for EURC transfers

   **Note**: The destination network is configured in the admin settings and cannot be changed by users in the form.

## Usage

### Shortcode

Use the shortcode with customer details and amount:

```
[devdraft_payment customer_first_name="John" customer_last_name="Doe" customer_email="john@example.com" amount="1000.00" title="Payment Form"]
```

### Parameters

- `customer_first_name` (required): Customer's first name
- `customer_last_name` (required): Customer's last name
- `customer_email` (required): Customer's email address
- `amount` (required): Payment amount
- `orderid` (required): Order ID for transaction mapping
- `title` (optional): Custom form title

## Features

### Bank Transfer Options

- **ACH Push (US)**: Standard ACH transfers
- **Same-day ACH (US)**: Expedited ACH transfers
- **Wire Transfer (International)**: International wire transfers
- **SEPA (Europe)**: European SEPA transfers
- **SWIFT (International)**: International SWIFT transfers
- **SPEI (Mexico)**: Mexican SPEI transfers

### Stablecoin Options

- **USDC**: USD Coin transfers
- **EURC**: Euro Coin transfers
- **Networks**: Ethereum, Polygon, Solana, Base, Arbitrum, Optimism, Avalanche C-Chain

### Success Messages

#### Bank Transfers

When a bank transfer payment is created successfully, the form displays:

- Bank name and account holder
- Account number and routing number (for US transfers)
- IBAN and BIC (for international transfers)
- Bank address
- Important reference number to include in the transfer

#### Stablecoin Transfers

When a stablecoin payment is created successfully, the form displays:

- Wallet address (formatted as code)
- Network information
- Currency information
- Important instructions about sending the exact amount

## Testing

### Debug Information

The plugin includes comprehensive debugging:

2. **PHP Error Log**: Logs API responses and errors
3. **Form Validation**: Validates required fields before submission
4. **Error Messages**: Displays detailed error information

### Common Issues

1. **"API credentials not configured"**: Configure API settings in WordPress admin
2. **"Destination address not configured"**: Set up destination addresses in plugin settings
3. **"Destination network is required"**: Ensure the destination network field is properly set
4. **AJAX errors**: Check browser console for detailed error information

## File Structure

```
devdraft-plugin/
├── devdraft-payment.php           # Main plugin file
├── assets/
│   ├── css/
│   │   └── payment.css            # Form styles
│   └── js/
│       ├── payment.js             # Form functionality
│       ├── qrcode.js              # QR Code library source (uncompressed)
│       └── qrcode.min.js          # QR Code library (compressed)
├── templates/
│   └── payment-form.php           # Form template
└── README.md                      # This file
```

## Third-Party Libraries

### QR Code Library

This plugin includes the QRCode for JavaScript library for generating QR codes:

- **Library**: QRCode for JavaScript
- **Author**: davidshimjs
- **License**: MIT License
- **Source Code**: Available in `assets/js/qrcode.js` (uncompressed)
- **Compressed Version**: `assets/js/qrcode.min.js`
- **Original Project**: http://www.d-project.com/
- **jQuery Plugin**: http://jeromeetienne.github.com/jquery-qrcode/

The source code is included in the plugin for transparency and compliance with WordPress.org guidelines.

## API Integration

The plugin integrates with the Devdraft API endpoints:

- **Bank Transfers**: `/api/v0/payment-intents/bank`
- **Stablecoin Transfers**: `/api/v0/payment-intents/stablecoin`

### API Request Format

#### Bank Transfer

```json
{
  "sourcePaymentRail": "ach_push",
  "sourceCurrency": "usd",
  "destinationCurrency": "usdc",
  "destinationNetwork": "ethereum",
  "destinationAddress": "0x...",
  "amount": 1000.0,
  "customer_first_name": "John",
  "customer_email": "john@example.com",
  "ach_reference": "INV12345"
}
```

#### Stablecoin Transfer

```json
{
  "sourceCurrency": "usdc",
  "sourceNetwork": "ethereum",
  "destinationCurrency": "usdc",
  "destinationNetwork": "ethereum",
  "destinationAddress": "0x...",
  "amount": 1000.0,
  "customer_first_name": "John",
  "customer_email": "john@example.com"
}
```

## Recent Changes

### Fixed Issues

1. **Success/Error Messages**: Fixed display of success and error messages
2. **Bank Details**: Added proper display of bank account details for transfers
3. **Wallet Address**: Added display of wallet addresses for stablecoin transfers
4. **Form Validation**: Added proper validation for required fields
5. **CSS Issues**: Fixed CSS conflicts that were hiding result messages
6. **Debug Information**: Added comprehensive debugging for troubleshooting

### New Features

1. **Test Page**: Added a test page for easy debugging
2. **Enhanced Error Handling**: Better error messages and debugging
3. **Form Validation**: Client-side and server-side validation
4. **Dynamic Network Selection**: Proper handling of destination networks

## Support

For support and issues:

1. Check the test page for configuration status
2. Review browser console for JavaScript errors
3. Check WordPress error logs for PHP errors
4. Verify API credentials and destination addresses are configured

## Version History

- **1.0.0**: Initial release with basic functionality
- **1.0.1**: Fixed success/error message display and added bank/wallet details
