| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,152 @@ |
| 1 |
+<?php |
|
| 2 |
+require_once(__DIR__ . '/../init.php'); |
|
| 3 |
+ |
|
| 4 |
+// Please fetch your API key from here https://portal.telnyx.com/#/app/api-keys |
|
| 5 |
+\Telnyx\Telnyx::setApiKey('######');
|
|
| 6 |
+ |
|
| 7 |
+?> |
|
| 8 |
+<style> |
|
| 9 |
+ .code {
|
|
| 10 |
+ background: #ddd; |
|
| 11 |
+ border: 1px solid #333; |
|
| 12 |
+ padding: 20px; |
|
| 13 |
+ border-radius: 3px; |
|
| 14 |
+ } |
|
| 15 |
+</style> |
|
| 16 |
+<?php |
|
| 17 |
+if (isset($_POST['action'])) {
|
|
| 18 |
+ switch ($_POST['action']) {
|
|
| 19 |
+ case 'send_verification': |
|
| 20 |
+ |
|
| 21 |
+ // Create a Verification profile |
|
| 22 |
+ $verify_profile = \Telnyx\VerifyProfile::create(["name" => "Test Profile"]); |
|
| 23 |
+ |
|
| 24 |
+ // Trigger a verification request and send SMS |
|
| 25 |
+ $verification = \Telnyx\Verification::create([ |
|
| 26 |
+ 'verify_profile_id' => $verify_profile['id'], |
|
| 27 |
+ 'phone_number' => $_POST['phone'], |
|
| 28 |
+ 'type' => 'sms' |
|
| 29 |
+ ]); |
|
| 30 |
+ ?> |
|
| 31 |
+ <h3>Verification was sent to: <?php echo $_POST['phone'];?></h3> |
|
| 32 |
+ <form method="post" action=""> |
|
| 33 |
+ |
|
| 34 |
+ <input type="hidden" name="action" value="check_verification"> |
|
| 35 |
+ <input type="hidden" name="verification_id" value="<?php echo $verification['id']; ?>"> |
|
| 36 |
+ |
|
| 37 |
+ <button type="submit">Check Verification Status</button> |
|
| 38 |
+ <pre class="code"> |
|
| 39 |
+ // Retrieve the status of the verification |
|
| 40 |
+ $verification = \Telnyx\Verification::retrieve('<?php echo $verification['id']; ?>');
|
|
| 41 |
+ </pre> |
|
| 42 |
+ </form> |
|
| 43 |
+ <?php |
|
| 44 |
+ break; |
|
| 45 |
+ |
|
| 46 |
+ case 'check_verification': |
|
| 47 |
+ |
|
| 48 |
+ // Retrieve the status of the verification |
|
| 49 |
+ $verification = \Telnyx\Verification::retrieve($_POST['verification_id']); |
|
| 50 |
+ |
|
| 51 |
+ ?> |
|
| 52 |
+ <h3>Verification Status for ID: <?php echo $_POST['verification_id'];?></h3> |
|
| 53 |
+ <pre><?php print_r($verification); ?></pre> |
|
| 54 |
+ |
|
| 55 |
+ <form method="post" action=""> |
|
| 56 |
+ |
|
| 57 |
+ <input type="hidden" name="action" value="check_verification"> |
|
| 58 |
+ <input type="hidden" name="verification_id" value="<?php echo $_POST['verification_id']; ?>"> |
|
| 59 |
+ |
|
| 60 |
+ <button type="submit">Check Verification Status</button> |
|
| 61 |
+ <pre class="code"> |
|
| 62 |
+ // Retrieve the status of the verification |
|
| 63 |
+ $verification = \Telnyx\Verification::retrieve('<?php echo $_POST['verification_id']; ?>');
|
|
| 64 |
+ </pre> |
|
| 65 |
+ </form> |
|
| 66 |
+ |
|
| 67 |
+ |
|
| 68 |
+ <h3>Submit Verification Code</h3> |
|
| 69 |
+ |
|
| 70 |
+ <form method="post" action=""> |
|
| 71 |
+ |
|
| 72 |
+ <input type="hidden" name="action" value="submit_verification_code"> |
|
| 73 |
+ <input type="hidden" name="verification_id" value="<?php echo $_POST['verification_id']; ?>"> |
|
| 74 |
+ |
|
| 75 |
+ <input id="verify-code-text" type="text" name="verification_code" placeholder="000000" oninput="update_verification_code()"> |
|
| 76 |
+ |
|
| 77 |
+ <button type="submit">Submit Verification Code</button> |
|
| 78 |
+ <pre class="code"> |
|
| 79 |
+ // Submit verificaiton code |
|
| 80 |
+ $verify_status = \Telnyx\Verification::submit_verification('<?php echo $verification['phone_number']; ?>', '<span id="verify-code">000000</span>');
|
|
| 81 |
+ </pre> |
|
| 82 |
+ </form> |
|
| 83 |
+ <script> |
|
| 84 |
+ function update_verification_code() {
|
|
| 85 |
+ var textbox = document.getElementById("verify-code-text");
|
|
| 86 |
+ var span = document.getElementById("verify-code");
|
|
| 87 |
+ span.innerHTML = textbox.value; |
|
| 88 |
+ } |
|
| 89 |
+ </script> |
|
| 90 |
+ <?php |
|
| 91 |
+ break; |
|
| 92 |
+ |
|
| 93 |
+ case 'submit_verification_code': |
|
| 94 |
+ |
|
| 95 |
+ // Retrieve the status of the verification |
|
| 96 |
+ $verification = \Telnyx\Verification::retrieve($_POST['verification_id']); |
|
| 97 |
+ |
|
| 98 |
+ // Submit verification code here |
|
| 99 |
+ $verify_status = \Telnyx\Verification::submit_verification($verification['phone_number'], $_POST['verification_code']); |
|
| 100 |
+ ?> |
|
| 101 |
+ <h3>Submitted Verification Code: <?php echo $_POST['verification_code']; ?></h3> |
|
| 102 |
+ |
|
| 103 |
+ <pre><?php print_r($verify_status); ?></pre> |
|
| 104 |
+ |
|
| 105 |
+ <form method="post" action=""> |
|
| 106 |
+ |
|
| 107 |
+ <input type="hidden" name="action" value="check_verification"> |
|
| 108 |
+ <input type="hidden" name="verification_id" value="<?php echo $_POST['verification_id']; ?>"> |
|
| 109 |
+ |
|
| 110 |
+ <button type="submit">Check Verification Status</button> |
|
| 111 |
+ <pre class="code"> |
|
| 112 |
+ // Retrieve the status of the verification |
|
| 113 |
+ $verification = \Telnyx\Verification::retrieve('<?php echo $_POST['verification_id']; ?>');
|
|
| 114 |
+ </pre> |
|
| 115 |
+ </form> |
|
| 116 |
+ <?php |
|
| 117 |
+ break; |
|
| 118 |
+ } |
|
| 119 |
+} |
|
| 120 |
+else {
|
|
| 121 |
+ ?> |
|
| 122 |
+ <h1>Telnyx Verify Demo</h1> |
|
| 123 |
+ <p>Hi and welcome to the Telnyx Verify API demo.</p> |
|
| 124 |
+ <form method="post" action=""> |
|
| 125 |
+ |
|
| 126 |
+ <input type="hidden" name="action" value="send_verification"> |
|
| 127 |
+ |
|
| 128 |
+ <p><label>Enter a phone number. Please remember to include <a target="_blank" href="https://support.telnyx.com/en/articles/1130706-sip-connection-number-formats">country code</a>:</label></p> |
|
| 129 |
+ <input id="phone-number-text" type="text" name="phone" placeholder="+15557770000" oninput="update_phone()"> |
|
| 130 |
+ <button type="submit">Send Verification Code to Phone</button> |
|
| 131 |
+ <pre class="code"> |
|
| 132 |
+ // Create a Verification profile |
|
| 133 |
+ $verify_profile = VerifyProfile::create(["name" => "Test Profile"]); |
|
| 134 |
+ |
|
| 135 |
+ // Trigger a verification request and send SMS |
|
| 136 |
+ $verification = Verification::create([ |
|
| 137 |
+ 'verify_profile_id' => $verify_profile['id'], |
|
| 138 |
+ 'phone_number' => '<span id="phone-number-code">+15557770000</span>', |
|
| 139 |
+ 'type' => 'sms' |
|
| 140 |
+ ]); |
|
| 141 |
+ </pre> |
|
| 142 |
+ </form> |
|
| 143 |
+ <script> |
|
| 144 |
+ function update_phone() {
|
|
| 145 |
+ var textbox = document.getElementById("phone-number-text");
|
|
| 146 |
+ var span = document.getElementById("phone-number-code");
|
|
| 147 |
+ span.innerHTML = textbox.value; |
|
| 148 |
+ } |
|
| 149 |
+ </script> |
|
| 150 |
+ <?php |
|
| 151 |
+} |
|
| 152 |
+ |