feat: get status route
This commit is contained in:
@@ -378,8 +378,6 @@ public function status(Request $request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
$user->load(['response', 'plans']);
|
|
||||||
|
|
||||||
if ($user->mobile == config('approo.admin_mobile')) {
|
if ($user->mobile == config('approo.admin_mobile')) {
|
||||||
$user['products'] = Product::where('package_name_id', $packageName->id)->get();
|
$user['products'] = Product::where('package_name_id', $packageName->id)->get();
|
||||||
} else {
|
} else {
|
||||||
@@ -400,7 +398,7 @@ public function status(Request $request)
|
|||||||
// }
|
// }
|
||||||
$user['products'] = $user->products()
|
$user['products'] = $user->products()
|
||||||
->where('package_name_id', $packageName->id)
|
->where('package_name_id', $packageName->id)
|
||||||
->where(fn ($q) => $q->where('user_product.expire_at', '>', now()->addHour())->orWhere('user_product.expire_at', null))
|
->where(fn($q) => $q->where('user_product.expire_at', '>', now()->addHour())->orWhere('user_product.expire_at', null))
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$user['package_name'] = $user->packageNames()
|
$user['package_name'] = $user->packageNames()
|
||||||
|
|||||||
+4
-4
@@ -93,10 +93,10 @@ public function plans()
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Plan::class);
|
return $this->hasMany(Plan::class);
|
||||||
}
|
}
|
||||||
public function response()
|
// public function response()
|
||||||
{
|
// {
|
||||||
return $this->hasOne(UserResponse::class);
|
// return $this->hasOne(UserResponse::class);
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function breathingExercises()
|
public function breathingExercises()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\Product;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class CafeService
|
||||||
|
{
|
||||||
|
public function __construct(private $cafeConfig)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getToken()
|
||||||
|
{
|
||||||
|
if ($this->cafeConfig->token_refreshed_at > now()->subMinute(50)) {
|
||||||
|
return $this->cafeConfig->access_token;
|
||||||
|
}
|
||||||
|
$response = Http::asForm()->post('https://pardakht.cafebazaar.ir/devapi/v2/auth/token/', [
|
||||||
|
'grant_type' => 'refresh_token',
|
||||||
|
'client_id' => $this->cafeConfig->client_id,
|
||||||
|
'client_secret' => $this->cafeConfig->client_secret,
|
||||||
|
'refresh_token' => $this->cafeConfig->refresh_token,
|
||||||
|
]);
|
||||||
|
$response = json_decode($response, true);
|
||||||
|
if (isset($response['access_token'])) {
|
||||||
|
$this->cafeConfig->access_token = $response['access_token'];
|
||||||
|
$this->cafeConfig->token_refreshed_at = now();
|
||||||
|
$this->cafeConfig->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response['access_token'] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendRequest($url, $method, $params = [])
|
||||||
|
{
|
||||||
|
$response = Http::connectTimeout(2)->timeout(5)->retry(3, 500, throw: false)->send($method, $url, [
|
||||||
|
'headers' => [
|
||||||
|
'Authorization' => $this->getToken()
|
||||||
|
],
|
||||||
|
'form_params' => $params
|
||||||
|
]);
|
||||||
|
|
||||||
|
return json_decode($response, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPurchase($product, $token)
|
||||||
|
{
|
||||||
|
$response = $this->sendRequest("https://pardakht.cafebazaar.ir/devapi/v2/api/validate/{$product->packageName->name}/inapp/{$product->uuid}/purchases/$token/", 'GET');
|
||||||
|
// if ($response['consumptionState']) {
|
||||||
|
// return [
|
||||||
|
// 'status' => false,
|
||||||
|
// 'message' => 'already consumed',
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ($response['purchaseState']) {
|
||||||
|
return [
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'refunded',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'status' => true
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function consumePurchase($product, $token)
|
||||||
|
{
|
||||||
|
if ($product->type == Product::TYPES['permanent']) {
|
||||||
|
$response = $this->sendRequest("https://pardakht.cafebazaar.ir/devapi/v2/api/consume/{$product->packageName->name}/purchases/", 'POST', ['token' => $token]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkSubscription($product, $token)
|
||||||
|
{
|
||||||
|
$response = $this->sendRequest("https://pardakht.cafebazaar.ir/devapi/v2/api/applications/{$product->packageName->name}/active-subscriptions/$token/", 'GET');
|
||||||
|
return $response['subscriptions'] ?? false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\Product;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class MyketService
|
||||||
|
{
|
||||||
|
private function sendRequest($url, $method, $params = [], $packageName)
|
||||||
|
{
|
||||||
|
$response = Http::send($method, $url, [
|
||||||
|
'headers' => [
|
||||||
|
'X-Access-Token' => $packageName->myket_access_token
|
||||||
|
],
|
||||||
|
'form_params' => $params
|
||||||
|
]);
|
||||||
|
|
||||||
|
return json_decode($response, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPurchase($product, $token)
|
||||||
|
{
|
||||||
|
$response = $this->sendRequest("https://developer.myket.ir/api/applications/{$product->packageName->name}/purchases/products/{$product->uuid}/tokens/$token", 'GET', [], $product->packageName);
|
||||||
|
|
||||||
|
if ($response['purchaseState']) {
|
||||||
|
return [
|
||||||
|
'status' => false,
|
||||||
|
'message' => 'refunded',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'status' => true
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,9 +11,9 @@
|
|||||||
*/
|
*/
|
||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
// Schema::table('user_product', function (Blueprint $table) {
|
Schema::table('user_product', function (Blueprint $table) {
|
||||||
// $table->renameColumn('subscription_token' ,'gateway');
|
$table->renameColumn('subscription_token' ,'gateway');
|
||||||
// });
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-1
@@ -40,7 +40,8 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
Route::middleware('auth:sanctum')->group(function () {
|
Route::middleware('auth:sanctum')->group(function () {
|
||||||
|
Route::apiResource('reminders', ReminderController::class);
|
||||||
|
Route::get('status', [UserController::class, 'status']);
|
||||||
Route::prefix('package-names')->controller(PackageNameController::class)->group(function () {
|
Route::prefix('package-names')->controller(PackageNameController::class)->group(function () {
|
||||||
Route::get('/', 'index');
|
Route::get('/', 'index');
|
||||||
Route::middleware('abilities:admin')->post('/', 'store');
|
Route::middleware('abilities:admin')->post('/', 'store');
|
||||||
|
|||||||
Reference in New Issue
Block a user