OneTrial with Laravel
- Snippet on the signup page:
html<script src="https://onetrial.dev/v1.js" data-key="YOUR_PUBLIC_KEY" async></script>
- Send the token with the form:
js// Signup form (browser): include the token in your POSTconst token = await OneTrial.getToken(); // window.OneTrial is set by the snippetOneTrial.markSubmit(); // records time-to-submitformData.append('visitorToken', token);
- Decide in the signup controller:
php// app/Http/Controllers/SignupController.phppublic function store(Request $request) {$email = $request->input('email'); $user = User::create([...]);$res = Http::withToken(env('ONETRIAL_API_KEY'))->post('https://onetrial.dev/api/v1/decisions', ['visitorToken' => $request->input('visitorToken'), 'email' => $email, 'ip' => $request->ip(), 'userId' => $user->id,])->json();if ($res['decision'] === 'deny') return view('paid-plan');if ($res['decision'] === 'challenge') return redirect()->away($res['challengeUrl']);$this->createTrial($user);return response()->json(['ok' => true]);}
- Env:
ONETRIAL_API_KEY=ot_test_...(server only). Test keys hit the same engine; switch toot_live_when you go live. - Verify:
GET /api/v1/integration/statusreturns a checklist. Shadow mode is on until you flip it.