Advertisement
Guest User

Untitled

a guest
Oct 25th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 57.43 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3.  
  4. require APPPATH . '/libraries/REST_Controller.php';
  5. require '/home/digipos.gatewize.com/public_html/vendor/autoload.php';
  6.  
  7. use Restserver\Libraries\REST_Controller;
  8. use Psr\Http\Message\ResponseInterface;
  9. use GuzzleHttp\Exception\RequestException;
  10. use GuzzleHttp\Client;
  11. use GuzzleHttp\Cookie\CookieJar;
  12. use GuzzleHttp\Middleware;
  13. use GuzzleHttp\Pool;
  14. use GuzzleHttp\Promise\EachPromise;
  15. use GuzzleHttp\Psr7\Request;
  16. use GuzzleHttp\HandlerStack;
  17.  
  18. class Digipos extends REST_Controller
  19. {
  20. public $activeUser = null;
  21. public $client = null;
  22. public $appVersion = "2.5.9";
  23.  
  24. function __construct()
  25. {
  26. parent::__construct();
  27. date_default_timezone_set('Asia/Jakarta');
  28. $this
  29. ->parser
  30. ->setModule("api");
  31.  
  32. $this->activeUser = $this->check_user();
  33. if ($this->client == null) $this->client = new Client([
  34. 'base_uri' => 'https://digipos.telkomsel.com/api/',
  35. 'timeout' => 150,
  36. 'connection_timeout' => 100,
  37. 'headers' => [
  38. 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
  39. 'Accept' => 'application/json, text/javascript, */*;;q=0.8',
  40. 'Accept-Encoding' => 'gzip, deflate, br'
  41. ],
  42. 'verify' => false
  43. ]);
  44. }
  45.  
  46. private function check_user()
  47. {
  48. $license = $this
  49. ->uri
  50. ->segment(4);
  51.  
  52. $user = $this
  53. ->user_m
  54. ->get_by('license_key', $license);
  55.  
  56. if (is_null($user) && !($user->expired_date >= date("Y-m-d"))) die(json_encode(array(
  57. "status" => false,
  58. "status_code" => "ERR-001",
  59. "message" => "License is not Valid or Expired"
  60. )));
  61. else return $user;
  62. }
  63.  
  64. public function index_get()
  65. {
  66. echo "@STATUS:GAGAL@MESSAGE:URL ANDA SALAH@";
  67. }
  68.  
  69. public function index_post()
  70. {
  71. echo "@STATUS:GAGAL@MESSAGE:URL ANDA SALAH@";
  72. }
  73.  
  74. /** DIGIPOS MAIN FUNCTION **/
  75. public function doLogin($license = "", $password = "")
  76. {
  77. $username = $this->activeUser->username;
  78. $password = "666" . md5($password);
  79.  
  80. if ($this->activeUser->autotp == 1){
  81. $loginResp = $this->guzzLogin($username, $password);
  82.  
  83. if ($loginResp->status){
  84. return $loginResp->data;
  85. } else {
  86. return $loginResp;
  87. }
  88. } else {
  89. return (object)array(
  90. "status" => false,
  91. "status_code" => "ERR-015",
  92. "message" => "Fitur AutOTP disabled. Silahkan upgrade user anda!"
  93. );
  94. }
  95. }
  96.  
  97. public function verifyOtp($license = "", $token = "", $otp = "")
  98. {
  99.  
  100. $otpResp = $this->guzzLoginOtp($token, $otp);
  101. if ($otpResp->status)
  102. {
  103. $token = $otpResp->token;
  104. $decrypt = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/decrypt.js " . $token);
  105. $decrypt = explode("|", $decrypt);
  106. $loginData = $otpResp->data;
  107. $userId = $loginData
  108. ->data
  109. ->user->userId;
  110. $userCode = $loginData
  111. ->data
  112. ->user->code;
  113. $rsNumber = $loginData
  114. ->data
  115. ->user
  116. ->rsOutlet->rsNumber;
  117. $profile = $this->guzzProfile($userCode, $token);
  118.  
  119. $updateId = $this
  120. ->user_m
  121. ->update($this
  122. ->activeUser->id, array(
  123. 'outlet_id' => $profile
  124. ->data
  125. ->outlet->outletId,
  126. 'token' => $decrypt[0],
  127. 'data_login' => json_encode($loginData)
  128. ));
  129.  
  130. return $this
  131. ->user_m
  132. ->get($this
  133. ->activeUser
  134. ->id);
  135. }
  136. else return $otpResp;
  137.  
  138. }
  139.  
  140. public function getProduct($tipe = "", $tujuan = "082136333348")
  141. {
  142. $trxType = $this->parseTipeProduk($tipe);
  143.  
  144. $token = $this->activeUser->token;
  145. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  146. $outletId = $this->activeUser->outlet_id;
  147. if($trxType != "VF") {
  148. $brand = $this->guzzItem("brand", $tujuan, $token);
  149. $product = $this->guzzProduct($trxType, $tujuan, $brand->data, $outletId, $token);
  150. } else {
  151. $product = $this->guzzProductVoucher($token);
  152. }
  153.  
  154. return $product;
  155. }
  156.  
  157. public function getReport($startDate = "", $endDate = "")
  158. {
  159. if ($startDate == "") $startDate = date("Ymd");
  160. if ($endDate == "") $endDate = date("Ymd");
  161.  
  162. $username = $this
  163. ->activeUser->username;
  164. $token = $this
  165. ->activeUser->token;
  166. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  167. $loginData = json_decode($this
  168. ->activeUser
  169. ->data_login);
  170. $userId = $loginData
  171. ->data
  172. ->user->userId;
  173. $userCode = $loginData
  174. ->data
  175. ->user->code;
  176. $rsNumber = $loginData
  177. ->data
  178. ->user
  179. ->rsOutlet->rsNumber;
  180. $report = $this->guzzReport($startDate, $endDate, $userId, $rsNumber, $token);
  181.  
  182. return $report;
  183. }
  184.  
  185. public function getVoucherReport($startDate = "", $endDate = "")
  186. {
  187. if ($startDate == "") $startDate = date("Ymd");
  188. if ($endDate == "") $endDate = date("Ymd");
  189.  
  190. $username = $this
  191. ->activeUser->username;
  192. $token = $this
  193. ->activeUser->token;
  194. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  195. $loginData = json_decode($this
  196. ->activeUser
  197. ->data_login);
  198. $userId = $loginData
  199. ->data
  200. ->user->userId;
  201. $userCode = $loginData
  202. ->data
  203. ->user->code;
  204. $rsNumber = $loginData
  205. ->data
  206. ->user
  207. ->rsOutlet->rsNumber;
  208. $report = $this->guzzVoucherReport($startDate, $endDate, $userId, $rsNumber, $token);
  209.  
  210. return $report;
  211. }
  212.  
  213. public function getRechargeReport($startDate = "", $endDate = "")
  214. {
  215. if ($startDate == "") $startDate = date("Ymd");
  216. if ($endDate == "") $endDate = date("Ymd");
  217.  
  218. $username = $this
  219. ->activeUser->username;
  220. $token = $this
  221. ->activeUser->token;
  222. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  223. $loginData = json_decode($this
  224. ->activeUser
  225. ->data_login);
  226. $userId = $loginData
  227. ->data
  228. ->user->userId;
  229. $userCode = $loginData
  230. ->data
  231. ->user->code;
  232. $rsNumber = $loginData
  233. ->data
  234. ->user
  235. ->rsOutlet->rsNumber;
  236. $report = $this->guzzRechargeReport($startDate, $endDate, $userId, $rsNumber, $token);
  237.  
  238. return $report;
  239. }
  240.  
  241. public function cekProduk($produk, $tujuan,$idTrx) {
  242. $bulkProduct = $this->getProduct("bulk", $tujuan);
  243.  
  244. if ($bulkProduct->status) {
  245. $product = null;
  246. $trxType = "AP_BULK";
  247. if (is_numeric($produk)) {
  248. $product = $this->product_m->get_by(array('product_id' => $produk));
  249. $trxType = $product->product_cat;
  250. }
  251. else {
  252. foreach ($bulkProduct->data->list as $key => $value)
  253. {
  254. $productName = str_replace(" ", "", str_replace("/", "X", $value->productName));
  255. if (strpos(strtolower(trim($productName)) , strtolower(trim($produk))) !== false)
  256. {
  257. $product = $value;
  258. $product->product_id = $product->productId;
  259. unset($product->productId);
  260. break;
  261. }
  262. }
  263. }
  264.  
  265. if (!is_null($product)) {
  266. $token = $this->activeUser->token;
  267. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  268. $loginData = json_decode($this->activeUser->data_login);
  269. $userId = $loginData->data->user->userId;
  270. $userCode = $loginData->data->user->code;
  271. $rsNumber = $loginData->data->user->rsOutlet->rsNumber;
  272. $outletId = $this->activeUser->outlet_id;
  273. $segment = $this->guzzItem("segment", $tujuan, $token);
  274. $productId = $product->product_id;
  275.  
  276. if ($segment->status) {
  277. $los = $segment->data->los[0];
  278. }
  279.  
  280. $harga = $this->guzzProductErin($tujuan, $productId, $rsNumber, $trxType, $token);
  281. if ($harga->status) {
  282. $nominal = $harga->data->nominal;
  283. $quota = $harga->data->quota;
  284. $validity = $harga->data->validity;
  285.  
  286. $msg = "@STATUS:OK@MSISDN:".$tujuan."@HARGA:".$nominal."@KODE:".$produk."@PRODUK:".$quota . " / " . $validity . " hari"."@LOS:".$los."@";
  287.  
  288. return (object)array("status" => true, "status_code" => "OK", "message" => $msg);
  289. } else {
  290. //gagal
  291. $msg = "@STATUS:GAGAL@MSISDN:".$tujuan."@MESSAGE:Gagal Inquiry Harga@KODE:ERR-016@";
  292.  
  293. return (object)array("status" => false, "status_code" => "ERR-009", "message" => $msg);
  294. }
  295.  
  296.  
  297. }
  298. } else {
  299. if(strpos($bulkProduct->message, 'Token Expired') !== false) {
  300. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:TOKEN / OTP EXPIRED@KET:".$produk."@IDTRX:".$idTrx."@";
  301.  
  302. return (object) array("status" => "GAGAL", "status_code" => "ERR-010", "message" => $msg);
  303. } else {
  304. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:".$bulkProduct->message."@KET:".$produk."@IDTRX:".$idTrx."@";
  305.  
  306. return (object) array("status" => "GAGAL", "status_code" => "ERR-011", "message" => $msg);
  307. }
  308. }
  309. }
  310.  
  311. public function topupVoucher($pin = "", $produk = "", $tujuan = "", $idTrx = "")
  312. {
  313. $transaction = $this->transaction_m->get_by(array('trxserverid'=>$idTrx, 'id_user' => $this->activeUser->id));
  314.  
  315. if (is_null($transaction)){
  316. //get product bulk
  317. $bulkProduct = $this->getProduct("voucher", $tujuan);
  318.  
  319. if ($bulkProduct->status){
  320. $product = null;
  321. foreach ($bulkProduct->data->list as $key => $value){
  322. $productName = str_replace(" ", "", str_replace("/", "X", $value->productName));
  323. if (strpos(strtolower(trim($productName)) , strtolower(trim($produk))) !== false){
  324. $product = $value;
  325. $product->product_id = $product->productId;
  326. unset($product->productId);
  327. break;
  328. }
  329. }
  330.  
  331. if (!is_null($product)) {
  332. //product ditemukan
  333. $token = $this->activeUser->token;
  334. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  335. $loginData = json_decode($this->activeUser->data_login);
  336. $userId = $loginData->data->user->userId;
  337. $userCode = $loginData->data->user->code;
  338. $rsNumber = $loginData->data->user->rsOutlet->rsNumber;
  339. $outletId = $this->activeUser->outlet_id;
  340. $productId = $product->product_id;
  341.  
  342. $validate = $this->guzzValidateVoucher($tujuan, $token);
  343.  
  344. if($validate->status) {
  345. //voucher validated
  346. $detail = $this->guzzVoucherErin($productId, $token);
  347.  
  348. if($detail->status){
  349. $productDesc = $detail->data->productDesc;
  350. $nominal = $detail->data->nominal;
  351.  
  352. // $insertId = $this->transaction_m->insert(array(
  353. // 'msisdn' => $tujuan,
  354. // 'trxserverid' => $idTrx,
  355. // 'id_user' => $this->activeUser->id,
  356. // 'productId' => $productId,
  357. // 'harga' => $nominal,
  358. // 'message' => '',
  359. // 'status_code' => 'DIGI-000',
  360. // 'status' => 'PROSES'
  361. // ));
  362.  
  363. $topup = $this->guzzVoucherBeli($pin, $productId, $tujuan, $token);
  364.  
  365. var_dump($topup);
  366. } else {
  367.  
  368. }
  369. } else {
  370. //voucher not validated
  371. }
  372. } else {
  373. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:PRODUK TIDAK DITEMUKAN@KET:".$produk."@IDTRX:".$idTrx."@";
  374.  
  375. return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
  376. }
  377. } else {
  378. //error atau session habis
  379. if(strpos($bulkProduct->message, 'Token Expired') !== false) {
  380. $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TOKEN / OTP EXPIRED@KET:".$produk."@IDTRX:".$idTrx."@";
  381.  
  382. return (object) array("status" => "GAGAL", "status_code" => "ERR-010", "message" => $msg);
  383. } else {
  384. $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:".$bulkProduct->message."@KET:".$produk."@IDTRX:".$idTrx."@";
  385.  
  386. return (object) array("status" => "GAGAL", "status_code" => "ERR-011", "message" => $msg);
  387. }
  388. }
  389. } else {
  390. //transaksi ada
  391. $msg = "@MSISDN:".$tujuan."@MESSAGE:TRANSAKSI TELAH DILAKUKAN@KET:".$produk."@".$transaction->message."@";
  392.  
  393. return (object) array("status" => false, "message" => $msg, "status_code" => "ERR-015");
  394. }
  395. }
  396.  
  397. public function beliProduk($pin = "", $limitHarga = "", $limitLos = "", $produk = "", $tujuan = "", $idTrx = "")
  398. {
  399. $transaction = $this->transaction_m->get_by(array('trxserverid'=>$idTrx, 'id_user' => $this->activeUser->id));
  400.  
  401. if (is_null($transaction)){
  402. //get product bulk
  403. $bulkProduct = $this->getProduct("bulk", $tujuan);
  404. if ($bulkProduct->status){
  405. $product = null;
  406. $trxType = "AP_BULK";
  407. if (is_numeric($produk)){
  408. //bukan bulk
  409. $product = $this
  410. ->product_m
  411. ->get_by(array(
  412. 'product_id' => $produk
  413. ));
  414. $trxType = $product->product_cat;
  415. } else {
  416. //bulk
  417. foreach ($bulkProduct->data->list as $key => $value){
  418. $productName = str_replace(" ", "", str_replace("/", "X", $value->productName));
  419. if (strpos(strtolower(trim($productName)) , strtolower(trim($produk))) !== false){
  420. $product = $value;
  421. $product->product_id = $product->productId;
  422. unset($product->productId);
  423. break;
  424. }
  425. }
  426. }
  427.  
  428. if (!is_null($product)) {
  429. //product ditemukan
  430. $token = $this->activeUser->token;
  431. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  432. $loginData = json_decode($this->activeUser->data_login);
  433. $userId = $loginData->data->user->userId;
  434. $userCode = $loginData->data->user->code;
  435. $rsNumber = $loginData->data->user->rsOutlet->rsNumber;
  436. $outletId = $this->activeUser->outlet_id;
  437. $productId = $product->product_id;
  438. //jika los < 0, bypass segment.
  439. $los = -1;
  440. if(intval($limitLos) > 0) {
  441. $segment = $this->guzzItem("segment", $tujuan, $token);
  442. if ($segment->status){
  443. $los = $segment->data->los[0];
  444. $los = ($los > 0) ? $los : -1;
  445. }
  446. }
  447. if ($los == -1 || intval($los) >= intval($limitLos)){
  448. $harga = $this->guzzProductErin($tujuan, $productId, $rsNumber, $trxType, $token);
  449. if ($harga->status){
  450. $nominal = $harga->data->nominal;
  451. $quota = $harga->data->quota;
  452. $validity = $harga->data->validity;
  453.  
  454. if (intval($nominal) <= intval($limitHarga)){
  455. $insertId = $this->transaction_m->insert(array(
  456. 'msisdn' => $tujuan,
  457. 'trxserverid' => $idTrx,
  458. 'id_user' => $this->activeUser->id,
  459. 'productId' => $productId,
  460. 'harga' => $nominal,
  461. 'message' => '',
  462. 'status_code' => 'DIGI-000',
  463. 'status' => 'PROSES'
  464. ));
  465.  
  466. $data = $this->aktivasiProduk([$quota, $validity], $insertId, $idTrx, $los, $nominal, $pin, $tujuan, $productId, $rsNumber, $userId, $outletId, $token);
  467.  
  468. return $data;
  469.  
  470.  
  471. } else {
  472. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:HARGALEBIH BESAR DARI LIMIT HARGA REQUEST@KET:".$produk."@IDTRX:".$idTrx."@";
  473. return (object)array("status" => false, "status_code" => "ERR-006", "message" => $msg);
  474. }
  475. } else {
  476. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:PRODUK TIDAK DITEMUKAN@KET:".$produk."@IDTRX:".$idTrx."@";
  477.  
  478. return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
  479. }
  480. } else {
  481. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:LOS LEBIH KECIL DARIPADA LIMIT LOS@KET:".$produk."@IDTRX:".$idTrx."@";
  482.  
  483. return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
  484. }
  485. } else {
  486. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:PRODUK TIDAK DITEMUKAN@KET:".$produk."@IDTRX:".$idTrx."@";
  487.  
  488. return (object)array("status" => false, "status_code" => "ERR-004", "message" => $msg);
  489. }
  490. } else {
  491. //error atau session habis
  492. if(strpos($bulkProduct->message, 'Token Expired') !== false) {
  493. $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TOKEN / OTP EXPIRED@KET:".$produk."@IDTRX:".$idTrx."@";
  494.  
  495. return (object) array("status" => "GAGAL", "status_code" => "ERR-010", "message" => $msg);
  496. } else {
  497. $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:".$bulkProduct->message."@KET:".$produk."@IDTRX:".$idTrx."@";
  498.  
  499. return (object) array("status" => "GAGAL", "status_code" => "ERR-011", "message" => $msg);
  500. }
  501. }
  502. } else {
  503. //transaksi ada
  504. $msg = "@MSISDN:".$tujuan."@MESSAGE:TRANSAKSI TELAH DILAKUKAN@KET:".$produk."@".$transaction->message."@";
  505.  
  506. return (object) array("status" => false, "message" => $msg, "status_code" => "ERR-015");
  507. }
  508. }
  509.  
  510. public function aktivasiProduk($item, $insertId, $idTrx, $los, $harga, $pin, $tujuan, $productId, $rsNumber, $userId, $outletId, $token)
  511. {
  512. $todayDate = date("Ymd");
  513. $buyProduct = $this->guzzAktivasiPaket($harga, $pin, $tujuan, $productId, $rsNumber, $userId, $outletId, $token);
  514. if ($buyProduct->status){
  515. sleep(10);
  516. $report = $this->guzzReport($todayDate, $todayDate, $userId, $rsNumber, $token);
  517. if($report->status) {
  518. sleep(3);
  519. $filtered_report = $this->searchReport($report->data, $tujuan, $productId);
  520. if(!is_null($filtered_report)) {
  521. if(strcasecmp($filtered_report->status,"SUKSES") == 0) {
  522. $stok = $this->guzzProductMkios($rsNumber, $pin, $outletId, $token);
  523.  
  524. $total = $stok->data->total;
  525. $bulk = $stok->data->list[6]->inventoryTransactionResult->inventory;
  526. $sn = $filtered_report->serialNumber;
  527. $extTrxId = $filtered_report->extTrxId;
  528. $sn = !is_null($sn) ? "1".$sn : substr($extTrxId, 4);
  529. $msisdn = $filtered_report->msisdn;
  530. $status = $filtered_report->status;
  531. $id = $filtered_report->id;
  532. $cashbackStatus = $filtered_report->id;
  533. $statusDesc = $filtered_report->statusDesc;
  534.  
  535. $msg = "@SN:".$sn."@MSISDN:".$msisdn."@STATUS:".$status."@ID:".$id."@CASHBACKSTS:".$cashbackStatus."@STATUSDESC:".$statusDesc."@LOS:".$los."@HARGA:".$harga."@PRODUK:" . $item[0] . "/" . $item[1] . " hari" ."@SALDO:".$bulk."@TOTALSALDO:".$total."@"."IDTRX:".$idTrx."@";
  536.  
  537. $resp = array("status" => "SUKSES", "status_code" => "OK", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
  538. } else if(strpos($filtered_report->statusDesc, 'XML Frontend Halted') !== false) {
  539. $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TRANSAKSI PENDING@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
  540. $resp = array("status" => "SUSPECT", "status_code" => "ERR-008", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
  541. } else if((strcasecmp($filtered_report->status, "GAGAL") == 0
  542. || strpos($filtered_report->statusDesc, 'location') !== false
  543. || strpos($filtered_report->statusDesc, 'stockNotEnough') !== false
  544. || strpos($filtered_report->statusDesc, 'postPaidNumber') !== false
  545. || strpos($filtered_report->statusDesc, 'subsTypeNotDefined') !== false
  546. || strpos($filtered_report->statusDesc, 'error while checking balance') !== false
  547. || strpos($filtered_report->statusDesc, 'pinIncorrect') !== false
  548. || strpos($filtered_report->statusDesc, 'recharge split code failed') !== false
  549. )){
  550.  
  551. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:TRANSAKSI GAGAL@KET:".$filtered_report->statusDesc."@IDTRX:".$idTrx."@";
  552.  
  553. $resp = array("status" => "GAGAL", "status_code" => "ERR-007", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
  554. } else {
  555. $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TRANSAKSI PENDING@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
  556. $resp = array("status" => "SUSPECT", "status_code" => "ERR-008", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
  557. }
  558. } else {
  559. $msg = "@MSISDN:".$tujuan."@STATUS:GAGAL@MESSAGE:TRANSAKSI GAGALT@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
  560. $resp = array("status" => "GAGAL", "status_code" => "ERR-007", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
  561. }
  562. } else {
  563. //failed to get report
  564. $msg = "@MSISDN:".$tujuan."@STATUS:SUSPECT@MESSAGE:TRANSAKSI PENDING@KET:CEK WEB REPORT@IDTRX:".$idTrx."@";
  565. $resp = array("status" => "SUSPECT", "status_code" => "ERR-008", "message" => $msg, "harga" => $harga, "los" => $los, "idtrx" => $idTrx);
  566. }
  567.  
  568. $this->transaction_m->update($insertId, array('status' => $resp['status'], "message" => $resp['message'], "status_code" => $resp['status_code']));
  569.  
  570. return $this->transaction_m->get($insertId);
  571. } else {
  572. $msg = "@MSISDN:" . $tujuan . "@STATUS:GAGAL@MESSAGE:" . $buyProduct->message . "@KET:" . $produk . "@IDTRX:" . $idTrx . "@";
  573. return (object)array(
  574. "status" => false,
  575. "status_code" => "ERR-012",
  576. "message" => $msg
  577. );
  578.  
  579. $this->transaction_m->update($insertId, array('status' => $resp['status'], "message" => $resp['message'], "status_code" => $resp['status_code']));
  580.  
  581. return $this->transaction_m->get($insertId);
  582. }
  583. }
  584.  
  585. public function test()
  586. {
  587. // $token = $this->activeUser->token;
  588. // $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  589. // $code = $this->activeUser->username;
  590. // $profile = $this->guzzProfile($code, $token);
  591. // $data = $this->getRechargeReport("","");
  592. $data = $this->getProduct("bulk", "082136333348");
  593.  
  594. var_dump($data);
  595. }
  596.  
  597. public function testSession()
  598. {
  599. $token = $this
  600. ->activeUser->token;
  601. $token = shell_exec("node /home/digipos.gatewize.com/public_html/node_lib/jwt.js " . $token);
  602.  
  603. echo $token;
  604. $client = new Client();
  605. $promise = $client->requestAsync('GET', 'https://digipos.telkomsel.com/outapp/dashboard', ['headers' => ['Authorization' => 'Bearer ' . $token]]);
  606.  
  607. $response = $promise->wait();
  608.  
  609. echo $response->getBody()
  610. ->getContents();
  611. }
  612.  
  613. /** DIGIPOS GUZZLE FUNCTION **/
  614. public function guzzSmof()
  615. {
  616. $client = new Client(['headers' => ['User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36', 'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'Accept-Encoding' => 'gzip, deflate, br', ]]);
  617. try
  618. {
  619. $promise = $client->requestAsync('POST', 'https://digipos.telkomsel.com/mwa/Smof?', ['form_params' => ['media' => '1', 'activity' => '', 'outletid' => '', 'userid' => '', 'pin' => '', 'capcha' => '', 'lac' => 'lac_wb', 'ci' => 'ci_wb', 'lat' => '-1', 'lng' => '-1', 'mcc' => 'mcc_wb', 'mnc' => 'mnc_wb', 'imei' => '-1', 'iccid' => 'iccid-web', 'lastid' => '0', 'limit' => '10', 'procid' => 'ua', 'proccode' => 'ua-10', 'usercode' => 'AND7571037', 'xid' => '44556677884', 'password' => '583' . md5('123321') , 'version' => 'MO-05']]);
  620.  
  621. $response = $promise->wait();
  622.  
  623. $data = json_decode($response->getBody()
  624. ->getContents());
  625. echo $response->getBody()
  626. ->getContents();
  627. echo "test";
  628. var_dump($data);
  629. //{"response":"200 OK","error_code":"200 OK"}
  630. //GET COOKIE
  631.  
  632. }
  633. catch(\Exception $e)
  634. {
  635. //throw exception
  636. var_dump($e);
  637. echo "error";
  638. }
  639. }
  640.  
  641. public function guzzLogin($username, $password)
  642. {
  643. try
  644. {
  645. $promise = $this
  646. ->client
  647. ->requestAsync('POST', 'user/auth', ['form_params' => ['username' => $username, 'password' => $password, 'isBrowser' => true, 'browser' => 'Firefox', 'browserVersion' => '61.0', 'osVersion' => '10.0', 'appVersion' => $this->appVersion, 'karyawan' => true, 'os' => 'MAC OS']]);
  648.  
  649. $response = $promise->wait();
  650. // var_dump($response);
  651. $data = json_decode($response->getBody()
  652. ->getContents());
  653.  
  654. if ($response->getStatusCode() == 200 && $data->status == 0)
  655. {
  656. return (object)array(
  657. "status" => true,
  658. "status_code" => "OK",
  659. "data" => $data
  660. );
  661. }
  662. else
  663. {
  664. return (object)array(
  665. "status" => false,
  666. "status_code" => "ERR-001",
  667. "message" => $data->message
  668. );
  669. }
  670. }
  671. catch(\Exception $e)
  672. {
  673. //do nothing
  674. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  675. return (object)array(
  676. "status" => false,
  677. "status_code" => $data->code,
  678. "message" => $data->message
  679. );
  680. }
  681. }
  682.  
  683. public function guzzLoginOtp($token = "", $otp = "")
  684. {
  685. try
  686. {
  687. $promise = $this
  688. ->client
  689. ->requestAsync('POST', 'auth/otp', ['json' => ['token' => $token, 'otp' => $otp]]);
  690.  
  691. $response = $promise->wait();
  692.  
  693. $data = json_decode($response->getBody()
  694. ->getContents());
  695. //{"status":1,"messageInfo":{"code":"AUTH-013","title":"PIN salah, Kesempatan tinggal 3 kali lagi","message":"PIN salah, Kesempatan tinggal 3 kali lagi"}}
  696. $authorization = $response->getHeader('Authorization') [0];
  697. // var_dump($data);
  698. if ($response->getStatusCode() == 200 && $data->status == 0)
  699. {
  700. //sukses
  701. return (object)array(
  702. "status" => true,
  703. "status_code" => "OK",
  704. "data" => $data,
  705. "token" => $authorization
  706. );
  707. }
  708. else
  709. {
  710. //error
  711. return (object)array(
  712. "status" => false,
  713. "status_code" => "ERR-002",
  714. "message" => $data->message
  715. );
  716. }
  717. }
  718. catch(\Exception $e)
  719. {
  720. //do nothing
  721. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  722. return (object)array(
  723. "status" => false,
  724. "status_code" => $data->code,
  725. "message" => $data->message
  726. );
  727. }
  728. }
  729.  
  730. public function guzzProduct($trxType = "AP_BULK", $msisdn, $brand, $outletId, $token)
  731. {
  732. try
  733. {
  734. $promise = $this
  735. ->client
  736. ->requestAsync('GET', 'product?msisdn=' . $msisdn . '&brand=' . $brand . '&outletId=' . $outletId . '&trxType=' . $trxType, ['headers' => ['Authorization' => 'Bearer ' . $token]]);
  737.  
  738. $response = $promise->wait();
  739.  
  740. $data = json_decode($response->getBody()
  741. ->getContents());
  742.  
  743. if ($response->getStatusCode() == 200 && $data->status == 0)
  744. {
  745. return (object)array(
  746. "status" => true,
  747. "status_code" => "OK",
  748. "data" => $data->data
  749. );
  750. }
  751. else
  752. {
  753. return (object)array(
  754. "status" => false,
  755. "status_code" => "ERR-" . $data->status,
  756. "message" => $data->message
  757. );
  758. }
  759.  
  760. }
  761. catch(\Exception $e)
  762. {
  763. //do nothing
  764. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  765. return (object)array(
  766. "status" => false,
  767. "status_code" => $data->code,
  768. "message" => $data->message
  769. );
  770. }
  771. }
  772.  
  773. public function guzzItem($type = "brand", $msisdn, $token)
  774. {
  775. try
  776. {
  777. $promise = $this
  778. ->client
  779. ->requestAsync('GET', 'product/' . $type . '?msisdn=' . $msisdn, ['headers' => ['Authorization' => 'Bearer ' . $token]]);
  780.  
  781. $response = $promise->wait();
  782.  
  783. $data = json_decode($response->getBody()
  784. ->getContents());
  785. if ($response->getStatusCode() == 200 && $data->status == 0)
  786. {
  787. return (object)array(
  788. "status" => true,
  789. "status_code" => "OK",
  790. "data" => $data->data
  791. );
  792. }
  793. else
  794. {
  795. return (object)array(
  796. "status" => false,
  797. "status_code" => "ERR-" . $data->status,
  798. "message" => $data->message
  799. );
  800. }
  801. }
  802. catch(\Exception $e)
  803. {
  804. //do nothing
  805. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  806. return (object)array(
  807. "status" => false,
  808. "status_code" => $data->code,
  809. "message" => $data->message
  810. );
  811. }
  812. }
  813.  
  814. public function guzzProductHVC($trxType = "HVC", $msisdn, $class, $token)
  815. {
  816. try
  817. {
  818. $promise = $this
  819. ->client
  820. ->requestAsync('POST', 'product?msisdn=' . $msisdn . '&hvcClassification=' . strtoupper($class) . '&trxType=' . $trxType, ['headers' => ['Authorization' => $token]]);
  821.  
  822. $response = $promise->wait();
  823.  
  824. $data = json_decode($response->getBody()
  825. ->getContents());
  826. //{"status":1,"messageInfo":{"code":"AUTH-013","title":"PIN salah, Kesempatan tinggal 3 kali lagi","message":"PIN salah, Kesempatan tinggal 3 kali lagi"}}
  827.  
  828. }
  829. catch(\Exception $e)
  830. {
  831. //do nothing
  832. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  833. return (object)array(
  834. "status" => false,
  835. "status_code" => $data->code,
  836. "message" => $data->message
  837. );
  838. }
  839. }
  840.  
  841. public function guzzProfile($code, $token)
  842. {
  843. try
  844. {
  845. $promise = $this
  846. ->client
  847. ->requestAsync('GET', 'user/profile?code=' . $code . '&_=' . time() , ['headers' => ['Authorization' => 'Bearer ' . $token, 'Connection' => 'keep-alive']]);
  848.  
  849. $response = $promise->wait();
  850.  
  851. $data = json_decode($response->getBody()
  852. ->getContents());
  853.  
  854. if ($response->getStatusCode() == 200 && $data->status == 0)
  855. {
  856. return (object)array(
  857. "status" => true,
  858. "status_code" => "OK",
  859. "data" => $data->data
  860. );
  861. }
  862. else
  863. {
  864. return (object)array(
  865. "status" => false,
  866. "status_code" => $data
  867. ->messageInfo->code,
  868. "message" => $data
  869. ->messageInfo
  870. ->message
  871. );
  872. }
  873. }
  874. catch(\Exception $e)
  875. {
  876. //do nothing
  877. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  878. return (object)array(
  879. "status" => false,
  880. "status_code" => $data->code,
  881. "message" => $data->message
  882. );
  883. }
  884. }
  885.  
  886. public function guzzProductVoucher($token) {
  887. try
  888. {
  889. $promise = $this
  890. ->client
  891. ->requestAsync('GET', '/api/product/?trxType=VF', ['headers' => ['authorization' => 'Bearer ' . $token]]);
  892.  
  893. $response = $promise->wait();
  894. $data = json_decode($response->getBody()
  895. ->getContents());
  896.  
  897. if ($response->getStatusCode() == 200 && $data->status == 0)
  898. {
  899. return (object)array(
  900. "status" => true,
  901. "status_code" => "OK",
  902. "data" => $data->data
  903. );
  904. }
  905. else
  906. {
  907. return (object)array(
  908. "status" => false,
  909. "status_code" => "ERR-004",
  910. "message" => "Tidak dapat mengambil detail produk"
  911. );
  912. }
  913. }
  914. catch(\Exception $e)
  915. {
  916. //do nothing
  917. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  918. return (object)array(
  919. "status" => false,
  920. "status_code" => $data->code,
  921. "message" => $data->message
  922. );
  923. }
  924. }
  925.  
  926. public function guzzProductMkios($rsNumber = "", $pin = "", $outletId = "", $token = "") {
  927. try
  928. {
  929. $promise = $this
  930. ->client
  931. ->requestAsync('GET', '/api/product/mkios?rsNumber=' . $rsNumber . "&pin=" . $pin . "&outletId=" . $outletId, ['headers' => ['authorization' => 'Bearer ' . $token]]);
  932.  
  933. $response = $promise->wait();
  934. $data = json_decode($response->getBody()
  935. ->getContents());
  936.  
  937. if ($response->getStatusCode() == 200 && $data->status == 0)
  938. {
  939. return (object)array(
  940. "status" => true,
  941. "status_code" => "OK",
  942. "data" => $data->data
  943. );
  944. }
  945. else
  946. {
  947. return (object)array(
  948. "status" => false,
  949. "status_code" => "ERR-004",
  950. "message" => "Tidak dapat mengambil detail produk"
  951. );
  952. }
  953. }
  954. catch(\Exception $e)
  955. {
  956. //do nothing
  957. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  958. return (object)array(
  959. "status" => false,
  960. "status_code" => $data->code,
  961. "message" => $data->message
  962. );
  963. }
  964. }
  965.  
  966. public function guzzProductErin($msisdn = "", $productId = "", $rsNumber = "", $trxType = "", $token = "")
  967. {
  968. try
  969. {
  970. $promise = $this
  971. ->client
  972. ->requestAsync('GET', '/api/product/erin?msisdn=' . $msisdn . "&productId=" . $productId . "&rsNumber=" . $rsNumber . "&trxType=" . $trxType, ['headers' => ['authorization' => 'Bearer ' . $token]]);
  973.  
  974. $response = $promise->wait();
  975. $data = json_decode($response->getBody()
  976. ->getContents());
  977.  
  978. if ($response->getStatusCode() == 200 && $data->status == 0)
  979. {
  980. return (object)array(
  981. "status" => true,
  982. "status_code" => "OK",
  983. "data" => $data->data
  984. );
  985. }
  986. else
  987. {
  988. return (object)array(
  989. "status" => false,
  990. "status_code" => "ERR-004",
  991. "message" => "Tidak dapat mengambil detail produk"
  992. );
  993. }
  994. }
  995. catch(\Exception $e)
  996. {
  997. //do nothing
  998. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  999. return (object)array(
  1000. "status" => false,
  1001. "status_code" => $data->code,
  1002. "message" => $data->message
  1003. );
  1004. }
  1005. }
  1006.  
  1007.  
  1008.  
  1009. public function guzzAktivasiPaket($price = "", $pin = "", $msisdn = "", $packageId = "", $rsNumber = "", $userId = "", $outletId = "", $token = "")
  1010. {
  1011. $curl = curl_init();
  1012.  
  1013. curl_setopt_array($curl, array(
  1014. CURLOPT_URL => "https://digipos.telkomsel.com/api/package-activation",
  1015. CURLOPT_RETURNTRANSFER => true,
  1016. CURLOPT_ENCODING => "",
  1017. CURLOPT_MAXREDIRS => 10,
  1018. CURLOPT_TIMEOUT => 150,
  1019. CURLOPT_CONNECTTIMEOUT => 100,
  1020. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  1021. CURLOPT_CUSTOMREQUEST => "POST",
  1022. CURLOPT_POSTFIELDS => "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"price\"\r\n\r\n".trim($price)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"pin\"\r\n\r\n".trim($pin)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"msisdn\"\r\n\r\n".trim($msisdn)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"packageId\"\r\n\r\n".trim($packageId)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"rsNumber\"\r\n\r\n".trim($rsNumber)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"userId\"\r\n\r\n".trim($userId)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"outletId\"\r\n\r\n".trim($outletId)."\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
  1023. CURLOPT_HTTPHEADER => array(
  1024. "authorization: Bearer " . trim($token),
  1025. "cache-control: no-cache",
  1026. "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
  1027. "postman-token: 7587f3e8-5d66-38f7-3162-26220beef978"
  1028. ),
  1029. ));
  1030.  
  1031. $response = curl_exec($curl);
  1032. $err = curl_error($curl);
  1033. $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  1034.  
  1035. curl_close($curl);
  1036.  
  1037. $data = json_decode($response);
  1038.  
  1039. if($httpCode == 200 && $data->status == 0) {
  1040. return (object)array("status" => true, "status_code" => "OK", "data" => $data);
  1041. } else {
  1042. return (object)array("status" => false, "status_code" => "ERR-" . array_key_exists("status", $data) ? $data->status : "ERR-002", "message" => array_key_exists("message", $data) ? $data->message : "Digipos not responding");
  1043. }
  1044. }
  1045.  
  1046. public function guzzRechargePulsa($price = "", $pin = "", $msisdn = "", $packageId = "", $rsNumber = "", $userId = "", $outletId = "", $token = "")
  1047. {
  1048. $boundary = '----WebKitFormBoundary7MA4YWxkTrZu0gW';
  1049. $multipart_form = [['name' => 'denomRecharge', 'contents' => $price], ['name' => 'pin', 'contents' => $pin, ], ['name' => 'msisdn', 'contents' => $msisdn, ], ['name' => 'productId', 'contents' => $packageId, ], ['name' => 'rsNumber', 'contents' => $rsNumber, ], ['name' => 'userId', 'contents' => $userId, ], ['name' => 'outletId', 'contents' => $outletId, ]];
  1050. try
  1051. {
  1052. $promise = $this
  1053. ->client
  1054. ->requestAsync('POST', '/api/recharge', ['headers' => ['accept' => 'application/json, text/javascript, */*; q=0.01', 'authorization' => 'Bearer ' . $token, 'cache-control' => 'no-cache', 'content-type' => 'multipart/form-data; boundary=' . $boundary], 'body' => new GuzzleHttp\Psr7\MultipartStream($multipart_form, $boundary) , ]);
  1055.  
  1056. $response = $promise->wait();
  1057. $data = json_decode($response->getBody()
  1058. ->getContents());
  1059.  
  1060. if ($response->getStatusCode() == 200)
  1061. {
  1062. if (!is_null($data) && $data->status == 0)
  1063. {
  1064. return (object)array(
  1065. "status" => true,
  1066. "status_code" => "OK",
  1067. "data" => $data
  1068. );
  1069. }
  1070. else
  1071. {
  1072. return (object)array(
  1073. "status" => false,
  1074. "status_code" => "ERR-" . array_key_exists("status", $data) ? $data->status : "ERR-002",
  1075. "message" => array_key_exists("message", $data) ? $data->message : "Digipos not responding"
  1076. );
  1077. }
  1078. }
  1079. else
  1080. {
  1081. return (object)array(
  1082. "status" => false,
  1083. "status_code" => array_key_exists("messageInfo", $data) ? $data
  1084. ->messageInfo->code : "ERR-002",
  1085. "message" => array_key_exists("messageInfo", $data) ? $data
  1086. ->messageInfo->message : "Digipos not responding"
  1087. );
  1088. }
  1089. }
  1090. catch(\Exception $e)
  1091. {
  1092. //do nothing
  1093. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1094. return (object)array(
  1095. "status" => false,
  1096. "status_code" => $data->code,
  1097. "message" => $data->message
  1098. );
  1099. }
  1100. }
  1101.  
  1102. public function guzzReport($startDate = "", $endDate = "", $userId = "", $rsNumber = "", $token = "")
  1103. {
  1104. try
  1105. {
  1106. $promise = $this
  1107. ->client
  1108. ->requestAsync('GET', '/api/package-activation/report?startDate=' . $startDate . "&endDate=" . $endDate . "&userId=" . $userId . "&rsNumber=" . $rsNumber, ['headers' => ['authorization' => 'Bearer ' . $token]]);
  1109.  
  1110. $response = $promise->wait();
  1111. $data = json_decode($response->getBody()
  1112. ->getContents());
  1113.  
  1114. if ($response->getStatusCode() == 200 && $data->status == 0)
  1115. {
  1116. return (object)array(
  1117. "status" => true,
  1118. "status_code" => "OK",
  1119. "data" => $data->data
  1120. );
  1121. }
  1122. else
  1123. {
  1124. return (object)array(
  1125. "status" => false,
  1126. "status_code" => "ERR-" . $data
  1127. ->messageInfo->code,
  1128. "message" => $data
  1129. ->messageInfo
  1130. ->message
  1131. );
  1132. }
  1133. }
  1134. catch(\Exception $e)
  1135. {
  1136. //do nothing
  1137. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1138. return (object)array(
  1139. "status" => false,
  1140. "status_code" => $data->code,
  1141. "message" => $data->message
  1142. );
  1143. }
  1144.  
  1145. }
  1146.  
  1147. public function guzzPrepaidRegistration()
  1148. {
  1149.  
  1150. try
  1151. {
  1152. $promise = $this
  1153. ->client
  1154. ->requestAsync('GET', '/outapp/prepaidregistration', ['headers' => ['authorization' => 'Bearer ' . $token, 'cache-control' => 'no-cache']]);
  1155.  
  1156. $response = $promise->wait();
  1157. }
  1158. catch(\Exception $e)
  1159. {
  1160. //do nothing
  1161. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1162. return (object)array(
  1163. "status" => false,
  1164. "status_code" => $data->code,
  1165. "message" => $data->message
  1166. );
  1167. }
  1168.  
  1169. }
  1170.  
  1171. private function guzzVoucherBeli($pin = "", $productId = "", $tujuan = "", $token = "") {
  1172. try
  1173. {
  1174. $promise = $this
  1175. ->client
  1176. ->requestAsync('POST', '/api/voucher-fisik', ['debug' => true, 'headers' => ['authorization' => 'Bearer ' . trim($token)], 'json' => [
  1177. 'pin' => $pin,
  1178. 'productId' => $productId,
  1179. 'serialNumber' => $tujuan
  1180. ]]);
  1181.  
  1182. $response = $promise->wait();
  1183.  
  1184. $data = json_decode($response->getBody()
  1185. ->getContents());
  1186.  
  1187. var_dump($data);
  1188.  
  1189. if ($response->getStatusCode() == 200 && $data->status == 0)
  1190. {
  1191. return (object)array(
  1192. "status" => true,
  1193. "status_code" => "OK",
  1194. "data" => $data->data
  1195. );
  1196. }
  1197. else
  1198. {
  1199. return (object)array(
  1200. "status" => false,
  1201. "status_code" => $data
  1202. ->messageInfo->code,
  1203. "message" => $data
  1204. ->messageInfo
  1205. ->message
  1206. );
  1207. }
  1208. }
  1209. catch(\Exception $e)
  1210. {
  1211. //do nothing
  1212. echo $e->getResponse()->getBody(true);
  1213. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1214. return (object)array(
  1215. "status" => false,
  1216. "status_code" => $data->code,
  1217. "message" => $data->message
  1218. );
  1219. }
  1220. }
  1221.  
  1222. private function guzzVoucherReport($startDate, $endDate, $userId, $rsNumber, $token) {
  1223. try
  1224. {
  1225. $promise = $this
  1226. ->client
  1227. ->requestAsync('GET', '/api/voucher-fisik/report?startDate=' . $startDate . '&endDate=' . $endDate . '&userId=' . $userId . '&rsNumber=' . $rsNumber, ['headers' => ['authorization' => 'Bearer ' . $token]]);
  1228.  
  1229. $response = $promise->wait();
  1230.  
  1231. $data = json_decode($response->getBody()
  1232. ->getContents());
  1233.  
  1234. if ($response->getStatusCode() == 200 && $data->status == 0)
  1235. {
  1236. return (object)array(
  1237. "status" => true,
  1238. "status_code" => "OK",
  1239. "data" => $data->data
  1240. );
  1241. }
  1242. else
  1243. {
  1244. return (object)array(
  1245. "status" => false,
  1246. "status_code" => $data
  1247. ->messageInfo->code,
  1248. "message" => $data
  1249. ->messageInfo
  1250. ->message
  1251. );
  1252. }
  1253. }
  1254. catch(\Exception $e)
  1255. {
  1256. //do nothing
  1257. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1258. return (object)array(
  1259. "status" => false,
  1260. "status_code" => $data->code,
  1261. "message" => $data->message
  1262. );
  1263. }
  1264. }
  1265.  
  1266. //api/voucher-fisik/erin?productId=
  1267. private function guzzVoucherErin($productId = "", $token = "") {
  1268. try
  1269. {
  1270. $promise = $this
  1271. ->client
  1272. ->requestAsync('GET', '/api/voucher-fisik/erin?productId=' . $productId, ['headers' => ['authorization' => 'Bearer ' . $token]]);
  1273.  
  1274. $response = $promise->wait();
  1275.  
  1276. $data = json_decode($response->getBody()
  1277. ->getContents());
  1278.  
  1279. if ($response->getStatusCode() == 200 && $data->status == 0)
  1280. {
  1281. return (object)array(
  1282. "status" => true,
  1283. "status_code" => "OK",
  1284. "data" => $data->data
  1285. );
  1286. }
  1287. else
  1288. {
  1289. return (object)array(
  1290. "status" => false,
  1291. "status_code" => $data
  1292. ->messageInfo->code,
  1293. "message" => $data
  1294. ->messageInfo
  1295. ->message
  1296. );
  1297. }
  1298. }
  1299. catch(\Exception $e)
  1300. {
  1301. //do nothing
  1302. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1303. return (object)array(
  1304. "status" => false,
  1305. "status_code" => $data->code,
  1306. "message" => $data->message
  1307. );
  1308. }
  1309. }
  1310.  
  1311. //voucher-fisik/validate?serialNumber=900008179616
  1312. private function guzzValidateVoucher($voucher = "", $token = "") {
  1313. try
  1314. {
  1315. $promise = $this
  1316. ->client
  1317. ->requestAsync('GET', '/api/voucher-fisik/validate?serialNumber=' . $voucher, ['headers' => ['authorization' => 'Bearer ' . $token]]);
  1318.  
  1319. $response = $promise->wait();
  1320.  
  1321. $data = json_decode($response->getBody()
  1322. ->getContents());
  1323.  
  1324. if ($response->getStatusCode() == 200 && $data->status == 0)
  1325. {
  1326. return (object)array(
  1327. "status" => true,
  1328. "status_code" => "OK",
  1329. "data" => $data->data
  1330. );
  1331. }
  1332. else
  1333. {
  1334. return (object)array(
  1335. "status" => false,
  1336. "status_code" => $data
  1337. ->messageInfo->code,
  1338. "message" => $data
  1339. ->messageInfo
  1340. ->message
  1341. );
  1342. }
  1343. }
  1344. catch(\Exception $e)
  1345. {
  1346. //do nothing
  1347. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1348. return (object)array(
  1349. "status" => false,
  1350. "status_code" => $data->code,
  1351. "message" => $data->message
  1352. );
  1353. }
  1354. }
  1355.  
  1356. private function guzzRechargeReport($startDate = "", $endDate = "", $userId = "", $rsNumber = "", $token = "")
  1357. {
  1358. try
  1359. {
  1360. $promise = $this
  1361. ->client
  1362. ->requestAsync('GET', '/api/recharge/report?startDate=' . $startDate . '&endDate=' . $endDate . '&userId=' . $userId . '&rsNumber=' . $rsNumber, ['headers' => ['authorization' => 'Bearer ' . $token]]);
  1363.  
  1364. $response = $promise->wait();
  1365.  
  1366. $data = json_decode($response->getBody()
  1367. ->getContents());
  1368.  
  1369. if ($response->getStatusCode() == 200 && $data->status == 0)
  1370. {
  1371. return (object)array(
  1372. "status" => true,
  1373. "status_code" => "OK",
  1374. "data" => $data->data
  1375. );
  1376. }
  1377. else
  1378. {
  1379. return (object)array(
  1380. "status" => false,
  1381. "status_code" => $data
  1382. ->messageInfo->code,
  1383. "message" => $data
  1384. ->messageInfo
  1385. ->message
  1386. );
  1387. }
  1388. }
  1389. catch(\Exception $e)
  1390. {
  1391. //do nothing
  1392. $data = json_decode($e->getResponse()->getBody(true))->messageInfo;
  1393. return (object)array(
  1394. "status" => false,
  1395. "status_code" => $data->code,
  1396. "message" => $data->message
  1397. );
  1398. }
  1399. }
  1400.  
  1401. /** DIGIMON UTILITIES FUNCTION **/
  1402.  
  1403. public function searchReport($report = array() , $tujuan = "", $idProduk = "")
  1404. {
  1405. foreach ($report as $key => $value)
  1406. {
  1407. if ($value->msisdn == $tujuan && $value
  1408. ->product->productId == $idProduk)
  1409. {
  1410. return $value;
  1411. break;
  1412. }
  1413. }
  1414.  
  1415. return null;
  1416. }
  1417.  
  1418. public function searchRechargeReport($report = array() , $tujuan = "", $denom = "")
  1419. {
  1420. foreach ($report as $key => $value)
  1421. {
  1422. if ($value->msisdn == $tujuan && $value->denomRecharge == $denom)
  1423. {
  1424. return $value;
  1425. break;
  1426. }
  1427. }
  1428.  
  1429. return null;
  1430. }
  1431.  
  1432. private function parseTipeProduk($tipe = "")
  1433. {
  1434. if ($tipe == "digital")
  1435. {
  1436. $trxType = "DIGITAL";
  1437. }
  1438. elseif ($tipe == "bulk")
  1439. {
  1440. $trxType = "AP_BULK";
  1441. }
  1442. elseif ($tipe == "voice")
  1443. {
  1444. $trxType = "AP_VOICE";
  1445. }
  1446. elseif ($tipe == "sms")
  1447. {
  1448. $trxType = "AP_SMS";
  1449. }
  1450. elseif ($tipe == "fix")
  1451. {
  1452. $trxType = "AP_FIX";
  1453. }
  1454. elseif ($tipe = "voucher")
  1455. {
  1456. $trxType = "VF";
  1457. }
  1458.  
  1459. return $trxType;
  1460. }
  1461. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement