This is my code
public function getPurchaseData(Request $request)
{
$credentialsPath = config(‘services.fcm.credentials_path’);
if (!file_exists($credentialsPath)) {
return response()->json(['error' => 'Credentials file not found'], 404);
}
// dd($credentialsPath);
$fileContent = file_get_contents($credentialsPath);
$decodedCredentials = json_decode($fileContent, true);
$client = new Client();
$client->setApplicationName('AI Dating');
// dd($client);
$client->setAuthconfig($credentialsPath);
// dd($client);
$client->addScope(AndroidPublisher::ANDROIDPUBLISHER);
$service = new AndroidPublisher($client);
// dd($service);
$packageName = config('services.google_play.package_name');
$subscriptionId = config('services.google_play.subscription_id');
$purchaseToken = config('services.google_play.purchase_token'); // Get purchase token from request
// try {
$result = $service->purchases_subscriptions->get($packageName,$subscriptionId,$purchaseToken);
// dd('sdfdfdf',$result);
$expiryTimeMillis = $result->getExpiryTimeMillis();
$expiryDate = DateTime::createFromFormat('U', $expiryTimeMillis / 1000);
$currentDate = new DateTime();
$interval = $currentDate->diff($expiryDate);
$daysRemaining = $interval->format('%a');
return $daysRemaining;
// echo "Days remaining: " . $daysRemaining;
// } catch (Exception $e) {
// echo 'Error: ' . $e->getMessage();
// }
}
I got error message
{ “error”: { “code”: 400, “message”: “Invalid Value”, “errors”: [ { “message”: “Invalid Value”, “domain”: “global”, “reason”: “invalid” } ] } }
I want to get details of that user subscription like
expire time
remaining days
payment amount
and plan details
New contributor
hiral patadiya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.