use of model.banking.Card in project amos-ss17-alexa by c-i-ber.
the class ReplacementCardService method askForCardNumber.
private SpeechletResponse askForCardNumber(Session session, boolean errored) {
// TODO: Load account from session
Collection<Card> cards = AccountAPI.getCardsForAccount(ACCOUNT_NUMBER);
if (cards.size() == 0) {
// This user does not have any cards, ordering a replacement card is impossible.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText("Es wurden keine Kredit- oder EC-Karten gefunden.");
return SpeechletResponse.newTellResponse(speech);
} else {
SsmlOutputSpeech speech = new SsmlOutputSpeech();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<speak>");
if (errored) {
stringBuilder.append("Entschuldigung, das habe ich nicht verstanden. ");
}
stringBuilder.append("Bestellung einer Ersatzkarte. Es wurden folgende Karten gefunden: ");
List<Card> userCards = new ArrayList<>();
for (Card card : cards) {
// Check if this card is active
if (card.getStatus() != Card.Status.ACTIVE) {
continue;
}
userCards.add(card);
String prefix = (card.getCardType() == Card.CardType.CREDIT ? "Kredit" : "EC-");
stringBuilder.append(prefix + "karte mit den Endziffern <say-as interpret-as=\"digits\">" + card.getCardNumber().substring(card.getCardNumber().length() - 4) + "</say-as>. ");
}
// Store all card numbers in the session
SessionStorage.getInstance().getStorage(session.getSessionId()).put(STORAGE_VALID_CARDS, userCards);
stringBuilder.append("Bitte gib die Endziffern der Karte an, für die du Ersatz benötigst.");
stringBuilder.append("</speak>");
speech.setSsml(stringBuilder.toString());
// Create reprompt
Reprompt reprompt = new Reprompt();
reprompt.setOutputSpeech(speech);
return SpeechletResponse.newAskResponse(speech, reprompt);
}
}
use of model.banking.Card in project amos-ss17-alexa by c-i-ber.
the class ReplacementCardService method askIfBlockedOrDamaged.
private SpeechletResponse askIfBlockedOrDamaged(Intent intent, Session session) {
String fourDigits = intent.getSlot("Number").getValue();
LOGGER.info("Digits: " + fourDigits);
boolean validDigits = false;
// Check if these digits are valid
List<Card> userCards = (List<Card>) SessionStorage.getInstance().getStorage(session.getSessionId()).get(STORAGE_VALID_CARDS);
for (Card card : userCards) {
String cardNumber = card.getCardNumber();
if (cardNumber.substring(cardNumber.length() - 4).equals(fourDigits)) {
// Digits are valid
session.setAttribute(STORAGE_SELECTED_CARD_NUMBER, cardNumber);
session.setAttribute(STORAGE_SELECTED_CARD_ID, card.getCardId());
validDigits = true;
break;
}
}
// If these are invalid digits, ask again
if (!validDigits) {
return askForCardNumber(session, true);
}
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText("Wurde die Karte gesperrt oder wurde sie beschädigt?");
// Create reprompt
Reprompt reprompt = new Reprompt();
reprompt.setOutputSpeech(speech);
return SpeechletResponse.newAskResponse(speech, reprompt);
}
use of model.banking.Card in project amos-ss17-alexa by c-i-ber.
the class AccountAPI method getCardsForAccount.
/**
* Get all cards (credit / debit) for the given account.
*
* @param accountNumber Account number
* @return Collection of Cards
* @throws HttpClientErrorException
*/
public static Collection<Card> getCardsForAccount(String accountNumber) throws HttpClientErrorException {
// TODO: Create a generic method for getting embedded JSON-HAL collections (in BankingRESTClient)
Traverson traverson = null;
try {
traverson = new Traverson(new URI(BankingRESTClient.BANKING_API_ENDPOINT + BankingRESTClient.BANKING_API_BASEURL_V2 + "/accounts/" + accountNumber + "/cards"), MediaTypes.HAL_JSON);
} catch (URISyntaxException e) {
log.error("getCardsForAccount failed", e);
return null;
}
ParameterizedTypeReference<Resources<Card>> typeRefDevices = new ParameterizedTypeReference<Resources<Card>>() {
};
Resources<Card> resResponses = traverson.follow(rel("$._links.self.href")).withHeaders(bankingRESTClient.generateHttpHeaders()).toObject(typeRefDevices);
return resResponses.getContent();
}
use of model.banking.Card in project amos-ss17-alexa by c-i-ber.
the class AccountAPI method createCardForAccount.
/**
* Create card.
*
* @param accountNumber the account number
* @param cardType the card type
* @param cardNumber the card number
* @param status the status
* @param expirationDate the expiration date
* @return the card
*/
public static Card createCardForAccount(String accountNumber, Card.CardType cardType, String cardNumber, Card.Status status, String expirationDate) {
Card newCard = new Card();
newCard.setCardType(cardType);
newCard.setCardNumber(cardNumber);
newCard.setStatus(status);
newCard.setExpirationDate(expirationDate);
return createCardForAccount(accountNumber, newCard);
}
use of model.banking.Card in project amos-ss17-alexa by c-i-ber.
the class AmosAlexaSimpleTestImpl method replacementCardDialogTest.
@Test
public void replacementCardDialogTest() throws Exception {
newSession();
final String accountNumber = AmosAlexaSpeechlet.ACCOUNT_ID;
Collection<Card> cards = AccountAPI.getCardsForAccount(accountNumber);
for (Card card : cards) {
AccountAPI.deleteCard(accountNumber, card.getCardId());
}
AccountAPI.createCardForAccount(accountNumber, Card.CardType.DEBIT, accountNumber, Card.Status.ACTIVE, new DateTime(2018, 5, 1, 12, 0).toLocalDate().toString());
ArrayList<String> possibleAnswers = new ArrayList<String>() {
{
add("Bestellung einer Ersatzkarte. Es wurden folgende Karten gefunden: (.*)");
add("Es wurden keine Kredit- oder EC-Karten gefunden.");
}
};
String response = testIntentMatches("ReplacementCardIntent", StringUtils.join(possibleAnswers, "|"));
Pattern p = Pattern.compile("karte mit den Endziffern ([0-9]+)\\.");
Matcher m = p.matcher(response);
if (m.find()) {
String endDigits = m.group(1);
testIntent("PlainNumberIntent", "Number:" + endDigits, "Wurde die Karte gesperrt oder wurde sie beschädigt?");
testIntent("ReplacementCardReasonIntent", "ReplacementReason:beschaedigt", "Soll ein Ersatz für die beschädigte Karte mit den Endziffern " + endDigits + " bestellt werden?");
testIntent("AMAZON.YesIntent", "Okay, eine Ersatzkarte wurde bestellt.");
} else {
fail("Cannot find credit card.");
}
newSession();
response = testIntentMatches("ReplacementCardIntent", StringUtils.join(possibleAnswers, "|"));
p = Pattern.compile("karte mit den Endziffern ([0-9]+)\\.");
m = p.matcher(response);
if (m.find()) {
String endDigits = m.group(1);
testIntent("PlainNumberIntent", "Number:" + endDigits, "Wurde die Karte gesperrt oder wurde sie beschädigt?");
testIntent("ReplacementCardReasonIntent", "ReplacementReason:gesperrt", "Soll ein Ersatz für die gesperrte Karte mit den Endziffern " + endDigits + " bestellt werden?");
testIntent("AMAZON.NoIntent", "");
} else {
fail("Cannot find credit card.");
}
}
Aggregations