Generation

testsSun, 23 Jul 2023

public function getSubscription(string $customer): JsonResponse { $baseUrl = config('recharge.base_url'); $response = Http::withHeaders([ 'X-Recharge-Access-Token' => config('recharge.access_token'), ])->get($baseUrl . '/subscriptions?shopify_customer_id=' . $customer); $hasSubscription = []; if( $response->successful()) { foreach (json_decode($response)->subscriptions as $subscription) { if ($subscription->status == 'ACTIVE') { $hasSubscription = ['subscription' => $subscription]; } } } else { logger('Recharge: ' . $response . ' => shopify_customer_id=' . $customer); } return response()->json([ 'status' => $response->status(), 'success' => $response->successful(), 'data' => $response->successful() ? $hasSubscription : json_decode($response) ], $response->status()); }

Want to kickstart your project?Use the new AI Studio to create your code