Skip to content

Commit 2705969

Browse files
committed
Fetch PDF
1 parent 25a93c1 commit 2705969

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/ProntoForms.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,40 @@ public static function fetchForm( $subId , ?string $formId = null, ?string $user
7979
// Decode the body of the response
8080
$res = json_decode($res, true);
8181
return $res;
82+
} catch (\Throwable $th) {
83+
// Log in case of error.
84+
info($th->getMessage());
85+
return $th->getMessage();
86+
}
87+
}
88+
89+
90+
public static function fetchPDF( $subId , ?string $formId = null, ?string $userId = null)
91+
{
92+
# retrieve form info...
93+
// Get the IDs
94+
$formId = (!$formId) ? config('prontoforms.form_id') : $formId;
95+
$userId = (!$userId) ? config('prontoforms.user_id') : $userId;
96+
97+
if ($formId == null || $userId == null) {
98+
# value validation...
99+
throw new \Exception('Please enter a form ID or user ID');
100+
}
101+
102+
// Snd the event to Prontoforms
103+
try {
104+
//Request a ProntoForms...
105+
106+
$response = Http::withBasicAuth(
107+
config('prontoforms.user'),
108+
config('prontoforms.pass')
109+
)
110+
->get("https://api.prontoforms.com/api/1/data/". $subId .".pdf");
111+
112+
// // Get the body of the response
113+
$res = response()->make($response->getBody(), 200);
114+
$res->header('Content-Type', 'application/pdf');
115+
return $res;
82116

83117
} catch (\Throwable $th) {
84118
// Log in case of error.
@@ -89,4 +123,5 @@ public static function fetchForm( $subId , ?string $formId = null, ?string $user
89123

90124
}
91125

126+
92127
}

0 commit comments

Comments
 (0)