Viewing file: SyncController.php (6.57 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers;
use App\Jobs\SyncCategory; use App\Jobs\SyncProduct; use App\Models\Setting; use GuzzleHttp\Client; use Illuminate\Http\Request;
class SyncController extends Controller {
private $api_token;
public function __construct() {
$setting=Setting::find(1); if(!$setting || !$setting->api_key){ return response()->json(['message'=>'Invalid API Key'], 401); } $token = $setting->api_key;
$this->api_token = $token; }
public function syncCategory() {
try { $client = new Client(); $response = $client->get('https://dev.lapakgaming.com/api/category', [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_token, 'TOKEN' => '{{PHP_PATH}}' ] ]);
$response = $response->getBody()->getContents(); $response = json_decode($response);
if ($response && isset($response->data) && isset($response->data->categories)) {
foreach ($response->data->categories as $category) {
SyncCategory::dispatch($category); } } } catch (\Exception $ex) { return response()->json(['status' => 'failed', 'message' => $ex->getMessage()]); } }
public function syncAllProducts() {
try {
$client = new Client(['verify' => false]); $response = $client->get("https://dev.lapakgaming.com/api/all-products", [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_token, 'TOKEN' => '{{PHP_PATH}}' ] ]);
$response = $response->getBody()->getContents(); $response = json_decode($response);
if ($response && isset($response->data) && isset($response->data->products)) {
foreach ($response->data->products as $product) {
SyncProduct::dispatch($product); } } } catch (\Exception $ex) { return response()->json(['status' => 'failed', 'message' => $ex->getMessage()]); } }
public function syncBestProductByGroup($id = null) {
try { if (!$id) { $id = 'id'; }
$client = new Client(['verify' => false]); $response = $client->get("https://dev.lapakgaming.com/api/catalogue/group-products/ML1288_166/best-product?country_code=$id", [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_token, 'TOKEN' => '{{PHP_PATH}}' ] ]);
$response = $response->getBody()->getContents(); $response = json_decode($response);
if ($response && isset($response->data)) {
foreach ($response->data as $product) {
SyncProduct::dispatch($product); } } } catch (\Exception $ex) { return response()->json(['status' => 'failed', 'message' => $ex->getMessage()]); } }
public function syncBestProductList($group_product_code, $category_code) {
try { if (!$group_product_code || !$category_code) { return; }
$client = new Client(['verify' => false]); $response = $client->get("https://dev.lapakgaming.com/api/catalogue/group-products?category_code=$category_code&group_product_code=$group_product_code", [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_token, 'TOKEN' => '{{PHP_PATH}}' ] ]);
$response = $response->getBody()->getContents(); $response = json_decode($response);
if ($response && isset($response->data)) {
return $response->data;
// foreach ($response->data as $product){ // SyncProduct::dispatch($product); // } } } catch (\Exception $ex) { return response()->json(['status' => 'failed', 'message' => $ex->getMessage()]); } }
public function createOrder($user_id, $additional_id = null, $additional_information = null, $orderdetail = null, $count_order, $product_code, $group_product, $price = null, $partner_reference_id = null, $override_callback_url = null) {
if (!$user_id || !$count_order || !$product_code || !$group_product) { return; }
$params = [ 'user_id' => $user_id, 'additional_id' => $additional_id, 'additional_information' => $additional_information, 'orderdetail' => $orderdetail, 'count_order' => $count_order, 'product_code' => $product_code, 'group_product' => $group_product, 'price' => $price, 'partner_reference_id' => $partner_reference_id, 'override_callback_url' => $override_callback_url, ];
$client = new Client(['verify' => false]); $response = $client->post("https://dev.lapakgaming.com/api/order", [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_token, 'TOKEN' => '{{PHP_PATH}}' ], 'json' => $params ]);
$response = $response->getBody()->getContents(); $response = json_decode($response);
if ($response && isset($response->data)) {
return $response->data;
// foreach ($response->data as $product){ // SyncProduct::dispatch($product); // } } }
public function orderStatus($orderId) {
try { if (!$orderId) { return; }
$client = new Client(['verify' => false]); $response = $client->get("https://dev.lapakgaming.com/api/order_status?tid=$orderId", [ 'headers' => [ 'Authorization' => 'Bearer ' . $this->api_token, 'TOKEN' => '{{PHP_PATH}}' ] ]);
$response = $response->getBody()->getContents(); $response = json_decode($response);
if ($response && isset($response->data)) {
return $response->data; } } catch (\Exception $ex) { return response()->json(['status' => 'failed', 'message' => $ex->getMessage()]); } } }
|