php - Users and channels are not getting created when executed inside Paypal IPN
问题描述
Issue Summary
I implemented Twilio chat service for my CodeIgniter 3
application. I added a new method and called it from Paypal IPN
which will create two types of users and a private channel for one-to-one communication.
Strangely, after executing few lines of that method, execution is getting stopped. It's happening when the Paypal IPN
is hit for the first time. But next time, when I make a payment and the IPN
is hit again, all the code is working properly.
Recently updated to the latest version of twilio-php
but the issue remains. Not sure whether I'm doing something wrong. Please suggest a solution for this.
Code Snippet
// Paypal IPN
public function paypal_ipn() {
...............[code]...............
if ($this->makeChatKitRelation($check_relation_exists['company_id'], $check_relation_exists['job_seeker_id'], $check_relation_exists['channel_id'])) {
// 1. Not entering inside this as (see comment 2 below)
$update_data = array(
'number_allowed' => $check_chat_allowed_count->number_allowed + $packageDetails["num_careerseeker_contact_allowed"],
'already_availed' => $check_chat_allowed_count->already_availed + 1,
);
$this->Company_career_seeker_contact_allowed_model->updateChatAllowedCount($update_data, $check_relation_exists['company_id']);
}
die;
}
// Function used to make chat users & channels
public function makeChatKitRelation($companyId, $userId, $channel_id) {
$companyDetails = $this->Companybasic_model->checkChatKitStatus($companyId); // fetch user details from DB (if user doesn't exists in twilio)
$userDetails = $this->Jobseekerbasic_model->checkChatKitStatus($userId); // fetch user details from DB (if user doesn't exists in twilio)
require_once('vendor/autoload.php');
$twilio = new Twilio\Rest\Client(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
if ($companyDetails) { // if user doesn't exist in twilio
$twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->users
->create('company-' . $companyId); // 2. Working till this line in the first IPN call
$twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->users('company-' . $companyId)
->update([
'friendlyName' => $companyDetails->company_name
]);
}
if ($userDetails) { // if user doesn't exist in twilio
$twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->users
->create('user-' . $userId);
$twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->users('user-' . $userId)
->update([
'friendlyName' => $userDetails->full_name
]);
}
// Fetch channel or create a new one if it doesn't exist
try {
$channel = $twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->channels($channel_id)
->fetch();
} catch (\Twilio\Exceptions\RestException $e) {
$channel = $twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->channels
->create([
'createdBy' => 'company-' . $companyId,
'uniqueName' => $channel_id,
'type' => 'private'
]);
$twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->channels($channel_id)
->members
->create('company-' . $companyId);
$twilio->chat->v2->services(TWILIO_CHAT_SERVICE_SID)
->channels($channel_id)
->members
->create('user-' . $userId);
}
return $channel->sid;
}
Technical details:
- twilio-php version: 6.18.0
- php version: 7.3
解决方案
推荐阅读
- indexing - 无法调用链代码名称:“scbcch”,错误:执行事务时超时已过期
- java - 返回令人困惑的布尔语句 - 重构
- powershell - 循环遍历多个 SharePoint 网站集
- c++ - 如何使用 C++ 将 FRED 的经济数据下载到 txt 文件中?
- c# - C# - 无法从 xml 文件中获取节点值
- reactjs - 如何将 componentWillUpdate 更改为 getSnapshotBeforeUpdate
- jestjs - 开玩笑覆盖率:我怎样才能获得覆盖率的总百分比?
- oracle - 无法使用融合 CLI 设置 CLASSPATH:java.sql.SQLException:找不到适合 jdbc:oracle:thin 的驱动程序
- algorithm - 如何制作随机出现墙壁的蛇游戏?
- cypher - AgensGraph 社区版中使用的 Cypher 版本是什么?