-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
213 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 0 additions & 84 deletions
84
src/main/java/com/vonage/sample/serversdk/springboot/NetworkFraudController.java
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
src/main/java/com/vonage/sample/serversdk/springboot/NumberVerificationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.vonage.sample.serversdk.springboot; | ||
|
||
import com.vonage.client.camara.numberverification.NumberVerificationClient; | ||
import static com.vonage.sample.serversdk.springboot.ApplicationConfiguration.NUMBER_VERIFICATION_REDIRECT_ENDPOINT; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.servlet.view.RedirectView; | ||
import java.net.URI; | ||
import java.util.UUID; | ||
|
||
@Controller | ||
public final class NumberVerificationController extends VonageController { | ||
private static final String | ||
NUMBER_VERIFICATION_TEMPLATE_NAME = "number_verification", | ||
NUMBER_VERIFICATION_PARAMS_NAME = "numberVerificationParams", | ||
NUMBER_VERIFICATION_URL = "/numberVerification"; | ||
|
||
private NumberVerificationClient getNumberVerificationClient() { | ||
return getVonageClient().getNumberVerificationClient(); | ||
} | ||
|
||
@GetMapping(NUMBER_VERIFICATION_URL) | ||
public String numberVerificationStart(Model model) { | ||
var numberVerificationParams = new NumberVerificationParams(); | ||
numberVerificationParams.msisdn = "+990123456"; | ||
model.addAttribute(NUMBER_VERIFICATION_PARAMS_NAME, numberVerificationParams); | ||
return NUMBER_VERIFICATION_TEMPLATE_NAME; | ||
} | ||
|
||
@PostMapping(NUMBER_VERIFICATION_URL) | ||
public RedirectView buildVerificationUrl(@ModelAttribute NumberVerificationParams nvParams, Model model) { | ||
var redirectUrl = getServerUrl().resolve(NUMBER_VERIFICATION_REDIRECT_ENDPOINT); | ||
try { | ||
nvParams.url = getNumberVerificationClient().initiateVerification( | ||
nvParams.msisdn, redirectUrl, nvParams.msisdn | ||
); | ||
model.addAttribute(NUMBER_VERIFICATION_PARAMS_NAME, nvParams); | ||
return new RedirectView(nvParams.url.toString()); | ||
} | ||
catch (Exception ex) { | ||
return new RedirectView(ERROR_TEMPLATE); | ||
} | ||
} | ||
|
||
@GetMapping(NUMBER_VERIFICATION_REDIRECT_ENDPOINT) | ||
public String inboundWebhook(@RequestParam String code, @RequestParam(required = false) String state, Model model) { | ||
System.out.println("Received code '"+code+"' with state '"+state+"'."); | ||
boolean result = getNumberVerificationClient().verifyNumber(code); | ||
var nvParams = new NumberVerificationParams(); | ||
nvParams.code = code; | ||
nvParams.msisdn = state; | ||
nvParams.state = state; | ||
nvParams.result = result ? "Number matches." : "Fraudulent!"; | ||
model.addAttribute(NUMBER_VERIFICATION_PARAMS_NAME, nvParams); | ||
return NUMBER_VERIFICATION_TEMPLATE_NAME; | ||
} | ||
|
||
public static class NumberVerificationParams { | ||
private String msisdn, code, state, result; | ||
private URI url; | ||
|
||
public String getMsisdn() { | ||
return msisdn; | ||
} | ||
|
||
public void setMsisdn(String msisdn) { | ||
this.msisdn = msisdn; | ||
} | ||
|
||
public URI getUrl() { | ||
return url; | ||
} | ||
|
||
public void setUrl(URI url) { | ||
this.url = url; | ||
} | ||
|
||
public String getResult() { | ||
return result; | ||
} | ||
|
||
public void setResult(String result) { | ||
this.result = result; | ||
} | ||
|
||
public String getCode() { | ||
return code; | ||
} | ||
|
||
public void setCode(String code) { | ||
this.code = code; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public void setState(String state) { | ||
this.state = state; | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/vonage/sample/serversdk/springboot/SimSwapController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.vonage.sample.serversdk.springboot; | ||
|
||
import com.vonage.client.camara.simswap.SimSwapClient; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
import java.time.Instant; | ||
|
||
@Controller | ||
public final class SimSwapController extends VonageController { | ||
private static final String | ||
SIM_SWAP_TEMPLATE_NAME = "sim_swap", | ||
SIM_SWAP_PARAMS_NAME = "simSwapParams", | ||
SIM_SWAP_URL = "/simSwap"; | ||
|
||
private SimSwapClient getSimSwapClient() { | ||
return getVonageClient().getSimSwapClient(); | ||
} | ||
|
||
@GetMapping(SIM_SWAP_URL) | ||
public String simSwapStart(Model model) { | ||
var simSwapParams = new SimSwapParams(); | ||
simSwapParams.msisdn = "+990123456"; | ||
model.addAttribute(SIM_SWAP_PARAMS_NAME, simSwapParams); | ||
return SIM_SWAP_TEMPLATE_NAME; | ||
} | ||
|
||
@PostMapping(SIM_SWAP_URL) | ||
public String simSwapPost(@ModelAttribute SimSwapParams simSwapParams, Model model) { | ||
if (simSwapParams.msisdn != null) { | ||
simSwapParams.date = getSimSwapClient().retrieveSimSwapDate(simSwapParams.msisdn); | ||
} | ||
model.addAttribute(SIM_SWAP_PARAMS_NAME, simSwapParams); | ||
return SIM_SWAP_TEMPLATE_NAME; | ||
} | ||
|
||
public static class SimSwapParams { | ||
private String msisdn; | ||
private Instant date; | ||
|
||
public String getMsisdn() { | ||
return msisdn; | ||
} | ||
|
||
public void setMsisdn(String msisdn) { | ||
this.msisdn = msisdn; | ||
} | ||
|
||
public Instant getDate() { | ||
return date; | ||
} | ||
|
||
public void setDate(Instant date) { | ||
this.date = date; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE HTML> | ||
<html xmlns:th="http://www.thymeleaf.org" lang="en"> | ||
<head> | ||
<title>Verify phone number network</title> | ||
<div th:include="~{fragments/head :: preamble}"></div> | ||
<script type="text/javascript"> | ||
const updateNumberVerificationSnippet = function() { | ||
updateSnippet( | ||
`URI follow = client.getNumberVerificationClient().initiateVerification("${$('#msisdn').val()}", redirectUrl, null);` | ||
); | ||
}; | ||
|
||
$(document).ready(() => { | ||
updateNumberVerificationSnippet(); | ||
$('#form').change(updateNumberVerificationSnippet); | ||
}); | ||
</script> | ||
</head> | ||
<body> | ||
<a href="/">Home</a><br> | ||
<a href="https://developer.vonage.com/en/number-verification/overview">Number Verification API overview</a><br> | ||
<hr><br> | ||
<div class="flex"> | ||
<div class="w-1/3 p-4"> | ||
<form id="form" th:action="@{/numberVerification}" th:object="${numberVerificationParams}" method="post"> | ||
<div id="to-div" class="md:flex md:items-center mb-6"> | ||
<div class="md:w-1/3"> | ||
<label for="msisdn" class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4"> | ||
German or Spanish phone number: | ||
</label> | ||
</div> | ||
<div class="md:w-2/3"> | ||
<input type="tel" minlength="5" maxlength="50" th:field="*{msisdn}" id="msisdn" placeholder="990111199" class="bg-gray-200 border-2 border-gray-200 rounded w-full py-2 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"/> | ||
</div> | ||
</div> | ||
<div id="submit-div" class="md:w-2/3 float-right"> | ||
<input type="submit" value="Submit" class="float-right mb-8 mr-1 shadow bg-purple-500 hover:bg-purple-400 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded"> | ||
</div> | ||
</form> | ||
</div> | ||
<div th:include="~{fragments/head :: java-code-snippet}"></div> | ||
</div> | ||
<hr><br> | ||
<h3 id="result" th:text="${numberVerificationParams.result}"></h3> | ||
<hr> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters