{"id":43804048,"url":"https://github.com/chamikasamaraweera/payhere-php-sdk","last_synced_at":"2026-02-11T03:01:18.711Z","repository":{"id":336445467,"uuid":"1149639886","full_name":"ChamikaSamaraweera/payhere-php-sdk","owner":"ChamikaSamaraweera","description":"A comprehensive PHP SDK for integrating PayHere Payment Gateway into your PHP applications.","archived":false,"fork":false,"pushed_at":"2026-02-08T17:13:43.000Z","size":999,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-10T04:40:05.655Z","etag":null,"topics":["gateway","payhere","payhere-php-sdk","payhere-sdk","payment","php","php-sdk","sdk"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/chamikasamaraweera/payhere-php-sdk","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ChamikaSamaraweera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"docs/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"ChamikaSamaraweera","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"lfx_crowdfunding":null,"polar":null,"buy_me_a_coffee":"teaminfinity","thanks_dev":null,"custom":null}},"created_at":"2026-02-04T10:49:58.000Z","updated_at":"2026-02-07T19:39:14.000Z","dependencies_parsed_at":"2026-02-10T02:01:15.371Z","dependency_job_id":null,"html_url":"https://github.com/ChamikaSamaraweera/payhere-php-sdk","commit_stats":null,"previous_names":["chamikasamaraweera/payhere-php-sdk"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ChamikaSamaraweera/payhere-php-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChamikaSamaraweera%2Fpayhere-php-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChamikaSamaraweera%2Fpayhere-php-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChamikaSamaraweera%2Fpayhere-php-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChamikaSamaraweera%2Fpayhere-php-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChamikaSamaraweera","download_url":"https://codeload.github.com/ChamikaSamaraweera/payhere-php-sdk/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChamikaSamaraweera%2Fpayhere-php-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29326078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T02:08:56.257Z","status":"ssl_error","status_checked_at":"2026-02-11T02:08:51.338Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gateway","payhere","payhere-php-sdk","payhere-sdk","payment","php","php-sdk","sdk"],"created_at":"2026-02-05T22:30:40.746Z","updated_at":"2026-02-11T03:01:18.661Z","avatar_url":"https://github.com/ChamikaSamaraweera.png","language":"PHP","readme":"\u003cimg width=\"600\" height=\"200\" width=\"400\" src=\"https://payherestorage.blob.core.windows.net/payhere-resources/www/images/PayHere-Logo.png\"\u003e\n\n# PayHere PHP SDK\n\n[![Latest Version](https://img.shields.io/packagist/v/chamikasamaraweera/payhere-php-sdk)](https://packagist.org/packages/chamikasamaraweera/payhere-php-sdk)\n[![License](https://img.shields.io/packagist/l/chamikasamaraweera/payhere-php-sdk)](https://github.com/ChamikaSamaraweera/payhere-php-sdk/blob/master/LICENSE)\n[![PHP Version](https://img.shields.io/packagist/php-v/chamikasamaraweera/payhere-php-sdk)](https://packagist.org/packages/chamikasamaraweera/payhere-php-sdk)\n[![PHP Composer](https://github.com/ChamikaSamaraweera/payhere-php-sdk/actions/workflows/php.yml/badge.svg)](https://github.com/ChamikaSamaraweera/payhere-php-sdk/actions/workflows/php.yml)\n\n\nA comprehensive PHP SDK for integrating PayHere Payment Gateway into your PHP applications.\n\n## Features\n\n- ✅ Simple and intuitive API\n- ✅ Secure hash generation and verification\n- ✅ Support for both Sandbox and Live environments\n- ✅ Payment notification handling\n- ✅ PSR-4 autoloading\n- ✅ Comprehensive error handling\n- ✅ Well-documented code\n\n## Requirements\n\n- PHP 7.4 or higher\n- Composer\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require ChamikaSamaraweera/payhere-php-sdk\n```\n\nOr manually add to your `composer.json`:\n\n```json\n{\n    \"require\": {\n        \"ChamikaSamaraweera/payhere-php-sdk\": \"^1.0\"\n    }\n}\n```\n\n## Quick Start\n\n### 1. Initialize the SDK\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse Payhere\\Payhere;\n\n// Initialize with your credentials\n$payhere = new Payhere(\n    'YOUR_MERCHANT_ID',\n    'YOUR_MERCHANT_SECRET',\n    true // true for sandbox, false for live\n);\n```\n\n### 2. Create a Payment Request\n\n```php\n// Create a payment request\n$payment = $payhere-\u003ecreatePaymentRequest()\n    -\u003esetOrderId('ORDER_' . time())\n    -\u003esetAmount(1000.00)\n    -\u003esetCurrency('LKR')\n    -\u003esetItems('Product Name', 1)\n    -\u003esetCustomer(\n        'John',\n        'Doe',\n        'john@example.com',\n        '0771234567',\n        '123 Main Street',\n        'Colombo',\n        'Sri Lanka'\n    )\n    -\u003esetReturnUrl('https://yoursite.com/payment/return')\n    -\u003esetCancelUrl('https://yoursite.com/payment/cancel')\n    -\u003esetNotifyUrl('https://yoursite.com/payment/notify');\n\n// Option 1: Generate HTML form\necho $payment-\u003egenerateForm('Pay Now');\n\n// Option 2: Auto-redirect to PayHere\n$payment-\u003eredirect();\n\n// Option 3: Get data array for custom implementation\n$paymentData = $payment-\u003egetData();\n```\n\n### 3. Handle Payment Notifications\n\nCreate a notification handler endpoint (e.g., `notify.php`):\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse Payhere\\Payhere;\n\n$payhere = new Payhere(\n    'YOUR_MERCHANT_ID',\n    'YOUR_MERCHANT_SECRET',\n    true\n);\n\n// Handle the notification\n$notification = $payhere-\u003ehandleNotification();\n\n// Verify the notification\nif ($notification-\u003everify()) {\n    \n    // Check if payment was successful\n    if ($notification-\u003eisSuccess()) {\n        $orderId = $notification-\u003egetOrderId();\n        $paymentId = $notification-\u003egetPaymentId();\n        $amount = $notification-\u003egetAmount();\n        $currency = $notification-\u003egetCurrency();\n        \n        // Update your database\n        // Mark order as paid\n        // Send confirmation email, etc.\n        \n        echo \"Payment successful!\";\n    } else {\n        $status = $notification-\u003egetStatusText();\n        echo \"Payment status: \" . $status;\n    }\n    \n} else {\n    // Invalid notification\n    http_response_code(400);\n    echo \"Invalid notification\";\n}\n```\n\n## Configuration\n\n### Merchant Credentials\n\nYou need two credentials from your PayHere account:\n\n1. **Merchant ID**: Found in `Side Menu \u003e Integrations`\n2. **Merchant Secret**: Generate by adding your domain/app in `Side Menu \u003e Integrations`\n\n### Sandbox vs Live\n\n```php\n// Sandbox (for testing)\n$payhere = new Payhere('MERCHANT_ID', 'MERCHANT_SECRET', true);\n\n// Live (for production)\n$payhere = new Payhere('MERCHANT_ID', 'MERCHANT_SECRET', false);\n```\n\n## API Reference\n\n### PaymentRequest Methods\n\n| Method | Description |\n|--------|-------------|\n| `setOrderId(string $orderId)` | Set unique order ID |\n| `setAmount(float $amount)` | Set payment amount |\n| `setCurrency(string $currency)` | Set currency (default: LKR) |\n| `setItems(string $name, int $number)` | Set item details |\n| `setCustomer(...)` | Set customer information |\n| `setReturnUrl(string $url)` | Set return URL after payment |\n| `setCancelUrl(string $url)` | Set cancel URL |\n| `setNotifyUrl(string $url)` | Set notification callback URL |\n| `setCustomFields(string $custom1, ?string $custom2)` | Set custom fields |\n| `getData()` | Get payment data array with hash |\n| `generateForm(string $buttonText, array $attrs)` | Generate HTML form |\n| `redirect()` | Auto-redirect to PayHere |\n\n### NotificationHandler Methods\n\n| Method | Description |\n|--------|-------------|\n| `verify()` | Verify notification hash |\n| `isSuccess()` | Check if payment was successful |\n| `getStatusCode()` | Get status code (2=success, 0=pending, -1=canceled, -2=failed) |\n| `getStatusText()` | Get status as text |\n| `getOrderId()` | Get order ID |\n| `getPaymentId()` | Get PayHere payment ID |\n| `getAmount()` | Get payment amount |\n| `getCurrency()` | Get currency |\n| `getCustom1()` | Get custom field 1 |\n| `getCustom2()` | Get custom field 2 |\n| `getCardHolderName()` | Get card holder name |\n| `getCardNo()` | Get masked card number |\n| `getMethod()` | Get payment method |\n| `getData()` | Get all notification data |\n| `get(string $key, $default)` | Get specific field |\n\n### Payment Status Codes\n\n| Code | Constant | Description |\n|------|----------|-------------|\n| 2 | `STATUS_SUCCESS` | Payment successful |\n| 0 | `STATUS_PENDING` | Payment pending |\n| -1 | `STATUS_CANCELED` | Payment canceled |\n| -2 | `STATUS_FAILED` | Payment failed |\n| -3 | `STATUS_CHARGEDBACK` | Payment chargedback |\n\n## Complete Example\n\nSee the `examples/` directory for complete working examples:\n\n- `examples/checkout.php` - Payment checkout page\n- `examples/notify.php` - Payment notification handler\n- `examples/return.php` - Return page handler\n\n## Security Best Practices\n\n1. **Never expose your Merchant Secret** in client-side code\n2. **Always verify notifications** using the `verify()` method\n3. **Use HTTPS** for all callback URLs\n4. **Validate amounts** in your notification handler\n5. **Store payment records** before redirecting to PayHere\n6. **Use unique order IDs** for each transaction\n\n## Testing\n\nUse PayHere's sandbox environment for testing:\n\n```php\n$payhere = new Payhere('MERCHANT_ID', 'MERCHANT_SECRET', true);\n```\n\nTest card details are available in PayHere's documentation.\n\n## Documentation\n\n- 📖 [Quick Start Guide](docs/QUICKSTART.md)\n- 📘 [Detailed Usage Guide](docs/HOW_TO_USE.md)\n- 🔐 [Security Best Practices](docs/SECURITY.md)\n- 📋 [Project Structure](docs/STRUCTURE.md)\n- 📝 [Changelog](docs/CHANGELOG.md)\n\n## Support\n\n- [PayHere Documentation](https://support.payhere.lk/)\n- [API Documentation](https://support.payhere.lk/api-\u0026-mobile-sdk/checkout-api)\n- [GitHub Issues](https://github.com/ChamikaSamaraweera/payhere-php-sdk/issues)\n\n## Author\n\n**Chamika Samaraweera**\n- Email: chamika@teaminfinity.lk\n- GitHub: [@ChamikaSamaraweera](https://github.com/ChamikaSamaraweera)\n\n## License\n\nMIT License - see the [LICENSE](LICENSE) file for details\n\n## Contributing\n\nContributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on how to submit pull requests.\n\n## Acknowledgments\n\n- PayHere for providing the payment gateway service\n- All contributors who help improve this SDK\n\n","funding_links":["https://github.com/sponsors/ChamikaSamaraweera","https://buymeacoffee.com/teaminfinity"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchamikasamaraweera%2Fpayhere-php-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchamikasamaraweera%2Fpayhere-php-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchamikasamaraweera%2Fpayhere-php-sdk/lists"}