Untitled
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
use Illuminate\Http\Request; use GuzzleHttp\Client; class CouponController extends Controller { public function checkCouponValidity(Request $request) { $couponCode = $request->input('coupon_code'); // Replace 'YOUR_API_AUTH_TOKEN' with the actual Zoho API authentication token $apiToken = 'YOUR_API_AUTH_TOKEN'; // Replace 'YOUR_ORGANIZATION_ID' with the actual Zoho organization ID $organizationId = 'YOUR_ORGANIZATION_ID'; $apiUrl = "https://subscriptions.zoho.com/api/v1/coupons/{$couponCode}"; $headers = [ 'Authorization' => "Zoho-authtoken {$apiToken}", 'X-com-zoho-subscriptions-organizationid' => $organizationId, 'Content-Type' => 'application/json', ]; $client = new Client(); $response = $client->get($apiUrl, ['headers' => $headers]); $responseData = json_decode($response->getBody(), true); if ($responseData['code'] === 'success') { // Coupon code is valid, you can use $responseData['coupon'] to get coupon details if needed return response()->json(['valid' => true, 'coupon' => $responseData['coupon']]); } else { // Coupon code is not valid return response()->json(['valid' => false]); } } }
Editor is loading...