From fa46ee4867f8ca8c2df6936eb29e0091a5bf65ce Mon Sep 17 00:00:00 2001 From: Sys-MA <71400136+Sys-MA@users.noreply.github.com> Date: Thu, 7 Jan 2021 14:43:42 -0500 Subject: [PATCH] Update ProfilesAPI.java --- .../java/com/beanstream/api/ProfilesAPI.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/main/java/com/beanstream/api/ProfilesAPI.java b/src/main/java/com/beanstream/api/ProfilesAPI.java index e7c1bc4..7eb79db 100644 --- a/src/main/java/com/beanstream/api/ProfilesAPI.java +++ b/src/main/java/com/beanstream/api/ProfilesAPI.java @@ -401,6 +401,48 @@ public void setCard(Card card) { this.card = card; } + } + /** + * Add a new token to the profile. It gets appended to the end of the list of + * cards. Make sure your Merchant account can support more cards. The + * default amount is 1. You can change this limit in the online Members area + * for Merchants located at: https://www.beanstream.com/admin/sDefault.asp + * and heading to Configuration : Payment Profile Configuration + * + * @param profileId The profile id. + * @param token The token to add. + * @return ProfileResponse + * @throws BeanstreamApiException when not successful + */ + public ProfileResponse addToken(String profileId, Token token) + throws BeanstreamApiException { + ProfilesUtils.validateProfileId(profileId); + String url = PaymentsUrls.getProfileCardsUrl(config.getPlatform(), + config.getVersion(), profileId); + + ProfilesUtils.validateToken(token); + + TokenWrapper tw = new TokenWrapper(token); + String response = connector.ProcessTransaction(HttpMethod.post, url, tw); + return gson.fromJson(response, ProfileResponse.class); + + } + + private class TokenWrapper { + private Token token; + + private TokenWrapper(Card token) { + this.token = token; + } + + public Token getToken() { + return token; + } + + public void setToken(Card token) { + this.token = token; + } + } /** * Removes the card from the profile. Card IDs are their index in