Example #1
0
 protected function _doCharge()
 {
     //Set Key
     $this->loadKeys();
     $this->cardData = $this->seri . ':' . $this->pin . ':0:' . $this->_array_card[$this->card_type];
     $soap_client = new \SoapClient($this->url, ['trace' => 1]);
     //Login Get Session
     $this->login();
     //Encrypt Key
     $key = $this->hex2str($this->sessionId);
     $result = static::encryptAes($this->mpin, $key, false);
     $encryptedMpin = bin2hex($result['data']);
     // Encrypt card data
     $result = static::encryptAes($this->cardData, $key, false);
     $encryptedCardData = bin2hex($result['data']);
     $this->transaction = $this->merchant_code . $this->transaction;
     $result = $soap_client->cardCharging($this->transaction, $this->username, $this->merchant_id, $encryptedMpin, $this->user["ch_public_id"], $encryptedCardData, md5($this->sessionId));
     //        if ($this->user["ch_public_id"] == "f23741423013342")
     //        {
     //            print_r($result);
     //            die;
     //        }
     $status = $result->{"status"};
     if ($status == 1) {
         $this->msg = $this->_error_card[$status];
         $this->info_card = $this->decryptAes($this->hex2str($result->responseamount), $key);
     } else {
         $this->msg = $this->_error_card[$status];
         $this->info_card = 0;
     }
     if (!empty($result->transid)) {
         $this->transaction = $result->transid;
     }
     if (intval($this->info_card) >= 10000) {
         $response = array("status" => 1, "message" => "Bạn đã nạp : " . $this->info_card . " VNĐ. Vào tài khoản : " . $this->user["ch_nickname"], "partner_transaction" => $this->transaction, "value" => $this->info_card, "promotion" => $this->_promotion[$this->card_type]);
     } else {
         $response = array("status" => 0, "message" => $this->msg, "partner_transaction" => $this->transaction, "value" => 0, "promotion" => 0);
     }
     return $response;
 }