<?php
namespace app\components\modules\notification;
use framework\log\Log;
/**
* panda payam
*
* @author Saeed Johari <sjohari74@gmail.com>
* @since 1.0
* @package notification module
* @copyright (c) 2014 all rights reserved
*/
class Pandapayam extends Notification
{
/**
* run module
*
* @param object $trans, trans informations
* @param array $module, module data
* @param object $cards, buyed cards
* @access public
* @return void
*/
public function run( $trans, $module, $cards )
{
if( !class_exists( 'SoapClient' ) ) {
exit( 'not found SoapClient class' );
}
$client = new \SoapClient( $module['webserviceUrl']['value'],
[
'typemap' => array(
array(
'type_ns' => 'http://www.w3.org/2001/XMLSchema',
'type_name' => 'long',
'to_xml' => function( $long ){return "<long>{$long}</long>"; },
'from_xml' => function( $string ){return (string) strip_tags( $string ); },
),
),
]
);
$client->soap_defencoding = 'UTF-8';
$recipients[0] = $module['adminMobile']['value'];
if( !empty( $trans->transMobile ) ) {
$recipients[1] = $trans->transMobile;
}
$find = [ '{au}', '{price}', '{cards}' ];
$cardOutput = '';
foreach( $cards as $card ) {
$cardOutput .= PHP_EOL . $card->cardName . PHP_EOL . strip_tags($card->cardValue,'<br><br/>') . '--';
}
$content = str_replace( $find, [ $trans->transAu, $trans->transPrice, $cardOutput ], $module['content']['value'] );
$params = new \stdClass;
$params->username = $module['username']['value'];
$params->password = $module['password']['value'];
$params->senderNumbers = $module['from']['value'];
$params->recipientNumbers = $recipients;
$params->messageBodies = $content;
ob_start();
$result = $client->SendSms( $params );
print_r( $result );
$result = ob_get_contents();
ob_end_clean();
Log::instance()->initialize()->write( 'pandapayam', "Send Sms Response : {$result}" );
}
/**
* module fields for install this
*
* @access public
* @return array
*/
public function fields()
{
return [
'webserviceUrl' => [
'label' => $this->lang()->getIndex( 'pandapayam', 'webserviceUrl' ),
'value' => 'http://parsasms.com/webservice/v2.asmx?WSDL',
],
'username' => [
'label' => $this->lang()->getIndex( 'pandapayam', 'username' ),
'value' => '',
],
'password' => [
'label' => $this->lang()->getIndex( 'pandapayam', 'password' ),
'value' => '',
],
'from' => [
'label' => $this->lang()->getIndex( 'pandapayam', 'from' ),
'value' => '',
],
'adminMobile' => [
'label' => $this->lang()->getIndex( 'pandapayam', 'adminMobile' ),
'value' => '',
],
'content' => [
'label' => $this->lang()->getIndex( 'pandapayam', 'content' ),
'value' => 'کد پیگیری : {au} <br> مبلغ : {price} <br> {cards}',
],
];
}
}