{"id":31589410,"url":"https://github.com/mikechiloane/payfast-java-sdk","last_synced_at":"2026-05-14T23:14:32.740Z","repository":{"id":308012303,"uuid":"1031320926","full_name":"mikechiloane/payfast-java-sdk","owner":"mikechiloane","description":"A comprehensive Java SDK for PayFast payment gateway integration with proper signature validation and PayFast-compliant URL encoding.","archived":false,"fork":false,"pushed_at":"2025-08-10T20:53:16.000Z","size":95,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-10T22:23:00.111Z","etag":null,"topics":["java","payfast","payments","sdk"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikechiloane.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-03T13:52:04.000Z","updated_at":"2025-08-10T20:53:19.000Z","dependencies_parsed_at":"2025-08-03T17:32:03.610Z","dependency_job_id":null,"html_url":"https://github.com/mikechiloane/payfast-java-sdk","commit_stats":null,"previous_names":["mikechiloane/payfast-java-sdk"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mikechiloane/payfast-java-sdk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikechiloane%2Fpayfast-java-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikechiloane%2Fpayfast-java-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikechiloane%2Fpayfast-java-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikechiloane%2Fpayfast-java-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikechiloane","download_url":"https://codeload.github.com/mikechiloane/payfast-java-sdk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikechiloane%2Fpayfast-java-sdk/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278551493,"owners_count":26005388,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-06T02:00:05.630Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["java","payfast","payments","sdk"],"created_at":"2025-10-06T02:52:38.033Z","updated_at":"2025-10-06T02:52:39.095Z","avatar_url":"https://github.com/mikechiloane.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PayFast Java SDK\n\n![PayFast SDK Logo](payfast-sdk-logo.png)\n\nA comprehensive Java SDK for PayFast payment gateway integration with proper signature validation and PayFast-compliant URL encoding.\n\n**Developer:** Mike Chiloane  \n**Email:** mike@mikechiloane.co.za\n\n## Features\n\n- **One-off payments** - Single payment transactions\n- **Automatic signature generation** - Python-compatible URL encoding\n- **Sandbox/Production modes** - Easy environment switching\n- **Comprehensive error handling** - Specific exceptions for different scenarios\n- **Full PayFast compliance** - Matches official implementation\n\n## Installation\n\nAdd to your `pom.xml`:\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.recceda\u003c/groupId\u003e\n    \u003cartifactId\u003epayfast-java-sdk\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.7\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Quick Start\n\n### 1. Basic Setup\n```java\nimport com.recceda.payfast.PayFastService;\nimport com.recceda.payfast.config.PayFastConfig;\n\n// Sandbox configuration\nPayFastConfig config = new PayFastConfig(\n    \"10000100\",           // merchant ID\n    \"46f0cd694581a\",      // merchant key  \n    null,                 // passphrase (optional)\n    true                  // sandbox mode\n);\n\nPayFastService service = new PayFastService(config);\n```\n\n### 2. One-off Payment\n```java\nimport com.recceda.payfast.model.PaymentRequest;\nimport com.recceda.payfast.model.PayFastFormData;\nimport java.math.BigDecimal;\n\n### 2. One-off Payment\n```java\nimport com.recceda.payfast.model.PaymentRequest;\nimport com.recceda.payfast.model.PayFastResponse;\nimport java.math.BigDecimal;\n\nPaymentRequest payment = new PaymentRequest();\npayment.setAmount(new BigDecimal(\"100.00\"));\npayment.setItemName(\"Demo Product\");\npayment.setItemDescription(\"Product description\");\npayment.setMPaymentId(\"ORDER-\" + System.currentTimeMillis());\n\n// Optional: Set return URLs\npayment.setReturnUrl(\"https://yoursite.com/return\");\npayment.setCancelUrl(\"https://yoursite.com/cancel\");\npayment.setNotifyUrl(\"https://yoursite.com/notify\");\n\n// Optional: Set buyer information\npayment.setNameFirst(\"John\");\npayment.setNameLast(\"Doe\");\npayment.setEmailAddress(\"john.doe@example.com\");\n\n// Create payment form data with all fields and signature\nPayFastFormData formData = service.createPaymentFormData(payment);\n```\n\n## Demo Application\n```\n\n### 3. Subscription Payment\n```java\nimport com.recceda.payfast.model.SubscriptionRequest;\n\nSubscriptionRequest subscription = new SubscriptionRequest();\nsubscription.setAmount(new BigDecimal(\"50.00\"));           // Initial amount\nsubscription.setItemName(\"Monthly Subscription\");\nsubscription.setItemDescription(\"Premium service subscription\");\nsubscription.setMPaymentId(\"SUB-\" + System.currentTimeMillis());\n\n// Subscription specific settings\nsubscription.setSubscriptionType(\"1\");                     // Subscription\nsubscription.setRecurringAmount(5000);                     // 50.00 in cents\nsubscription.setFrequency(3);                             // Monthly (1=Daily, 2=Weekly, 3=Monthly, 4=Quarterly, 5=Biannually, 6=Annual)\nsubscription.setCycles(12);                               // 12 months (0 = infinite)\n\n// Create subscription form data with all fields and signature\nPayFastFormData formData = service.createSubscriptionFormData(subscription);\n\n\n\n## Demo Application\n\nRun the included demo to see the SDK in action:\n\n```bash\nmvn exec:java -Dexec.mainClass=\"com.recceda.App\"\n```\n\nThis will:\n- Create a sample payment form\n- Create a sample subscription form  \n- Display PayFast sandbox URLs for testing\n\n## Error Handling\n\nThe SDK provides comprehensive error handling with specific exceptions:\n\n```java\nimport com.recceda.payfast.exception.*;\n\ntry {\n    PayFastFormData formData = service.createPaymentFormData(payment);\n} catch (ConfigurationException e) {\n    // Invalid configuration (missing merchant ID/key)\n    log.error(\"Configuration error: {}\", e.getMessage());\n} catch (ValidationException e) {\n    // Invalid request data (missing required fields, invalid amounts, etc.)\n    log.error(\"Validation error: {}\", e.getMessage());\n} catch (SignatureException e) {\n    // Signature generation or validation errors\n    log.error(\"Signature error: {}\", e.getMessage());\n} catch (HttpException e) {\n    // HTTP communication errors\n    log.error(\"HTTP error: {}\", e.getMessage());\n} catch (PayFastException e) {\n    // Base exception for all other PayFast operations\n    log.error(\"PayFast error: {}\", e.getMessage());\n}\n```\n\n## Configuration Options\n\n### PayFast Frequency Values\n\n- `1` - Daily\n- `2` - Weekly  \n- `3` - Monthly\n- `4` - Quarterly\n- `5` - Biannually\n- `6` - Annual\n\n#### Generate Your Own Sandbox Credentials\n1. Go to [PayFast Sandbox](https://sandbox.payfast.co.za)\n2. Register for a free sandbox account with your email\n3. Login to your sandbox dashboard\n4. Navigate to **Settings** → **Merchant Details** to get your unique:\n   - Merchant ID\n   - Merchant Key\n5. Set a **Salt Passphrase** in **Settings** → **Account Information** (required for subscriptions)\n\n**Benefits of your own sandbox account:**\n- Test subscriptions with proper passphrase\n- View transaction history and ITN logs\n- Test subscription management features\n- More realistic testing environment\n\n## Technical Implementation\n\n### Signature Generation\nThis SDK implements PayFast's signature generation algorithm with:\n- **Python-compatible URL encoding** using `urllib.parse.quote_plus` equivalent\n- **Proper parameter ordering** matching PayFast's official Python implementation\n- **Spaces encoded as '+'** (not '%20') per PayFast requirements\n- **Uppercase hex encoding** for special characters\n\n### HTML Form Generation\nThe SDK automatically generates HTML payment forms that:\n- Include all required PayFast parameters\n- Have proper signatures for validation\n- Auto-submit via JavaScript (optional)\n- Save to descriptive filenames for debugging\n\n## Testing\n\nRun the comprehensive test suite:\n\n```bash\nmvn test\n```\n\nThe SDK includes:\n- **146 test cases** covering all functionality\n- Unit tests for all components\n- Integration tests with real PayFast examples\n- Signature validation tests\n- Error handling tests\n\n## Requirements\n\n- **Java 8+**\n- **Maven 3.6+**\n- **SLF4J** for logging\n\n## Production Setup\n\nFor production use:\n\n1. **Get real credentials** from PayFast merchant portal\n2. **Set sandbox to false**:\n   ```java\n   PayFastConfig config = new PayFastConfig(\n       \"your-merchant-id\",\n       \"your-merchant-key\", \n       \"your-passphrase\",\n       false  // production mode\n   );\n   ```\n3. **Configure proper return URLs** for your domain\n4. **Use HTTPS** for all URLs\n\n## Support\n\n- **PayFast Documentation**: https://developers.payfast.co.za/\n- **PayFast Support**: https://www.payfast.co.za/support/\n\n## Author\n\n**Mike Chiloane**\nEmail: [mike@mikechiloane.co.za](mailto:mike@mikechiloane.co.za)\n\n## License\n\nMIT License - see LICENSE file for details\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Add tests for new functionality  \n4. Ensure all tests pass\n5. Submit a pull request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikechiloane%2Fpayfast-java-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikechiloane%2Fpayfast-java-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikechiloane%2Fpayfast-java-sdk/lists"}