Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@mehmet-gandomi
Copy link
Contributor

@mehmet-gandomi mehmet-gandomi commented Nov 13, 2025

Describe your changes

Refactor iransmspanel gateway based on new API https://developer.persianbulk.com

Submission Review Guidelines:

  • I have performed a self-review of my code
  • If it is a core feature, I have added thorough tests.
  • Will this be part of a product update? If yes, please write one phrase about this update.
  • I have reviewed my code for security best practices.
  • Following the above guidelines will result in quick merges and clear and detailed feedback when appropriate.
  • My code follows the style guidelines of this project
  • I have updated the change-log in CHANGELOG.md.

Type of change

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Summary by CodeRabbit

New Features

  • Added template-based SMS sending with flexible token support and optional date/custom parameters
  • Introduced SMS credit balance inquiry functionality via API

Chores

  • Updated gateway integration to Persian Bulk SMS service with enhanced API connectivity, improved error handling, and comprehensive response logging

mehmet-gandomi and others added 2 commits November 13, 2025 15:46
…ssaging

## Changes

### Persian Bulk SMS Gateway Updates
- Updated gateway to use Persian Bulk SMS API (persianbulk.com, formerly iransmspanel.ir)
- Updated API base URL to https://developer.persianbulk.com
- Updated documentation and help text to reflect new branding

### Bulk SMS Support
- Implemented SendArray endpoint for efficient bulk message delivery
- Changed from comma-separated string to array format for recipients
- All messages now use bulk endpoint by default for better performance

### Template SMS Support
- Added SendTemplateSMS() public method for direct template message sending
- Implemented auto-detection for template messages in SendSMS() method
- Added support for multiple tokens (token, token2, token3, etc.)
- Template format: "template:TEMPLATE_ID|token:VALUE|date:VALUE|token2:VALUE2"
- Flexible token passing: string, array, or additional parameters

### Features
- Single recipient and multiple recipient support
- Optional date parameter for templates
- Comprehensive error handling and logging
- Backward compatible with existing code
- WordPress filters maintained (wp_sms_from, wp_sms_to, wp_sms_msg)

## API Endpoints Used
- `/sms/SendArray` - Bulk SMS sending
- `/sms/Send/pattern` - Template SMS sending
- `/sms/Balance` - Account credit/balance retrieval

## Breaking Changes
None. All existing functionality remains compatible.

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 13, 2025

Walkthrough

The PR updates the Iran SMS Panel gateway integration to use Persian Bulk SMS API. This includes remapping the gateway domain from iransmspanel.ir to persianbulk.com in the global gateway registry, and comprehensively refactoring the gateway class to migrate from legacy socket/cURL flows to Persian Bulk's API-based endpoints with template support and API key authentication.

Changes

Cohort / File(s) Summary
Gateway Registry Mapping
includes/class-wpsms-gateway.php
Updated gateway slug mapping from iransmspanel.ir to persianbulk.com in the global pro gateways configuration.
Persian Bulk Gateway Implementation
includes/gateways/class-wpsms-gateway-iransmspanel.php
Replaced legacy Iran SMS Panel integration with Persian Bulk SMS API. Added new public properties (version, base_url, tariff, help, documentUrl, flash, unitrial, isflash, bulk_send, unit, api_key, gatewayFields). Introduced SendTemplateSMS() method for template-based messaging with flexible token handling. Added GetCredit() for balance queries via API. Refactored message sending to use unified request-based flow with try-catch error handling and status validation.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • API integration and request flows: Verify correct endpoint construction, HTTP method usage, and payload formatting for Persian Bulk API compatibility
  • Template message handling: Review sendTemplateMessage() logic, token processing (single vs. array), and date/additionalParams flexibility
  • Error handling and credential validation: Ensure API key presence checks, HTTP status code validation (200), and proper error logging with WP_Error returns
  • Gateway property initialization: Confirm all new public properties align with gateway interface expectations and maintain backward compatibility

Possibly related PRs

  • PR #407: Updates gateway domain mappings in includes/class-wpsms-gateway.php for Iran-region gateways, sharing similar gateway registry configuration changes.
  • PR #388: Modifies gateway metadata and implements API/key-based refactors for gateway implementations, including iransmspanel to persianbulk migration patterns.

Pre-merge checks and finishing touches

βœ… Passed checks (3 passed)
Check name Status Explanation
Title check βœ… Passed The title accurately summarizes the main change: updating the iransmspanel gateway to support bulk SMS and template functionality, which aligns with the primary objective of refactoring to the new Persian Bulk SMS API.
Docstring Coverage βœ… Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • πŸ“ Generate docstrings
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-iransmspanel-gateway

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

πŸ“œ Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 13360b3 and 6a7761d.

πŸ“’ Files selected for processing (2)
  • includes/class-wpsms-gateway.php (1 hunks)
  • includes/gateways/class-wpsms-gateway-iransmspanel.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
includes/gateways/class-wpsms-gateway-iransmspanel.php (1)
includes/class-wpsms-gateway.php (7)
  • help (995-1005)
  • __construct (380-411)
  • from (1010-1016)
  • response (987-990)
  • request (1134-1139)
  • status (925-982)
  • log (546-567)
πŸ”‡ Additional comments (1)
includes/class-wpsms-gateway.php (1)

817-817: LGTM: gateway mapping now reflects Persian Bulk

The slug now points to persianbulk.com, keeping the registry consistent with the refactored gateway class.

Comment on lines +153 to +169
'sender' => $receptor, // Recipient number
'template' => $template, // Template ID
];

// Handle token parameter - supports string or array
if (is_array($token)) {
// Multiple tokens provided as array
// Try format 1: token, token2, token3, etc.
$body['token'] = $token[0] ?? '';
for ($i = 1; $i < count($token); $i++) {
$body['token' . ($i + 1)] = $token[$i];
}
} else {
// Single token as string
$body['token'] = $token;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | πŸ”΄ Critical

Fix template payload: recipient sent as sender

Both SendTemplateSMS() and sendTemplateMessage() populate the request body with 'sender' => $receptor and never send a receptor field. Persian Bulk expects the sender line ID and the recipient number separately; with the current mapping the API receives no recipient and uses the target number as the sender, so template messages will fail. Please swap the assignments so the sender line comes from $this->from and add the missing receptor.

Apply this diff:

-        'sender'   => $receptor,
-        'template' => $template,
+        'sender'   => $this->from,
+        'receptor' => $receptor,
+        'template' => $template,
-        'sender'   => $receptor,
-        'template' => $data['template'],
-        'token'    => $data['token'],
+        'sender'    => $this->from,
+        'receptor'  => $receptor,
+        'template'  => $data['template'],
+        'token'     => $data['token'],

Also applies to: 249-253

πŸ€– Prompt for AI Agents
In includes/gateways/class-wpsms-gateway-iransmspanel.php around lines 153 to
169 (also apply same change to lines ~249-253), the request body maps the
recipient into the 'sender' field and omits 'receptor'; change the payload so
'sender' is set to $this->from (the SMS line ID) and add a 'receptor' =>
$receptor entry to include the recipient number, keeping the existing 'template'
and token handling intact; apply the identical swap/addition for the other
occurrence at lines ~249-253.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants