# Sample Codes source: https://developer.mastercard.com/priceless-planet-carbon-tracker/tutorial/api-testing/step4/index.md ## Sample Codes {#sample-codes} ### Following are the sample codes for testing supported use cases. {#following-are-the-sample-codes-for-testing-supported-use-cases} #### 1. User Enrollment {#1-user-enrollment} This endpoint requires **an encrypted** payload. For encryption to be enabled, you need to pass true to the `getApiClient` method for getting the ApiClient for this endpoint. ```java IssuerApi issuerApiForEncryptionDecryption = new IssuerApi(getApiClient(true)); System.out.println("Calling User Registration Api"); UserReference userReference = issuerApiForEncryptionDecryption.userRegistration(getUserProfile()); System.out.println("User Registration Response : " + userReference); System.out.println("------------------------------------------------------------------"); ``` ##### Payload Before Encryption {#payload-before-encryption} Note: If the issuer has opted to disable the Donate feature, then the fields Name, Billing Address, and Locale in the payload are not mandatory. ```java public static UserProfile getUserProfile() { UserProfile userProfile = new UserProfile(); Email email = new Email(); email.setType("home"); email.setValue("PPCT" + new RandomString().nextString() + "@gmail.com"); userProfile.setEmail(email); UserName userName = new UserName(); userName.setFirstName("dummmyUserrz"); userName.setLastName("Useraf"); userProfile.setName(userName); // Not mandatory when the Donate feature is disabled. userProfile.setCardholderName("dummyaqa User"); userProfile.setCardBaseCurrency("USD"); String cardNumber = new CreditCardGenerator().generate(binRange, 16); userProfile.setCardNumber(cardNumber); CardExpiry cardExpiry = new CardExpiry(); cardExpiry.setMonth("09"); cardExpiry.setYear("2024"); Address address = new Address(); address.setCountryCode("USA"); address.setLocality("rly station"); address.setLine1("7836 West Elm Street"); address.setLine2("Huntington 120"); address.setPostalCode("11746"); address.setState("Huntington"); address.setLine3("7832 West "); address.setType("work"); address.setCity("Brooklyn"); userProfile.setBillingAddress(address); // Not mandatory when the Donate feature is disabled. userProfile.setExpiryInfo(cardExpiry); userProfile.setLocale("en-US"); // Not mandatory when the Donate feature is disabled. return userProfile; } ``` ##### Use API client configuration for this API as described in step 3 (Encryption and Decryption). {#use-api-client-configuration-for-this-api-as-described-in-step-3-encryption-and-decryption}
##### Response {#response} In response, you get a unique `userid` generated with its status and the last four digits of the card. ```json { "userid": "c8b38606-12b2-43c6-a641-be8eb0ab9dec", "cardNumberLastFourDigits": "3150", "status": "ACTIVE" } ``` #### 2. Get User Dashboard {#2-get-user-dashboard} This endpoint requires response decryption, so you need to pass true to the `getApiClient` method to get the ApiClient for this endpoint. Also, you need to pass the `userId` and `locale` in the request to get a dashboard for that particular user. ```java IssuerApi issuerApiForEncryptionDecryption = new IssuerApi(getApiClient(false)); System.out.println("Calling Get DashBoard API"); Dashboard dashboard = issuerApiForEncryptionDecryption.getAuthToken(userReference.getUserId(), "en-US"); System.out.println("Get Dashboard API response: " + dashboard); System.out.println("------------------------------------------------------------------"); ``` ##### Use API client configuration for this API as described in step 3 (Encryption and Decryption). {#use-api-client-configuration-for-this-api-as-described-in-step-3-encryption-and-decryption-1}
##### Response {#response-1} In response, you will get the web URL along with the expiry of the web URL, which the issuer app loads in the WebView to display the consumer dashboard. ```json { "url": "https://carbon-calculator-experience-mtf.apps.stl.pcfprod00.mastercard.int/#/webview/home?auth_token=eyJ4NXQjUzI1NiI6IktZcVRVVy1MM21GbkkyQ0lfMHVEVXRNNF84Uk9WOW10RlgzNXp4b21zYWsiLCJraWQiOiI4ODc3OS1BUElfRW5hYmxlbWVudF9TeW5hcHNlX1BEUCIsImN0eSI6IkpXUyIsInR5cCI6IkpXVCIsImFsZyI6IlJTMjU2In0.eyJ1c2VyX2NvbnNlbnQiOiJmYWxzZSIsInN1YiI6Im5vdF9hdmFpbGFibGUiLCJzY3AiOiJjb20ubWFzdGVyY2FyZC5wcmljZWxlc3NwbGFuZXQ6Y2FyYm9uLXRyYWNrZXI6Y2FyYm9uLXRyYWNrZXItYXBpLXByaXZhdGU6M2VkYzRlNjMtZDI2NC00YzY5LWE3OWQtOGVjNjllNDRjNTg2IiwiZ3JwIjpbXSwiaXNzIjoiTUFTVEVSQ0FSRF9TQVMiLCJ0aWQiOiJub3RfYXZhaWxhYmxlIiwiYXVkIjoiUHJpY2VsZXNzUGxhbmV0Q2FyYm9uVHJhY2tlciIsIm5iZiI6MTYzODk3MjU4NywiZ3JhbnRfdHlwZSI6Im9hdXRoMl9hY2Nlc3NfdG9rZW4iLCJleHAiOjE2Mzg5NzM0ODcsIm9uZV90aW1lIjoiZmFsc2UiLCJpYXQiOjE2Mzg5NzI1ODcsImp0aSI6ImVmNmU4N2ZkNWVjMTI0YWY1OGI0YjgzYTc4NjA1NTY2IiwiY2lkIjoiQjZBbzVFNzFXbjM3Wm15OERiTVVkWHE4WFE0VHFwQTVmMHJzOGxWMDcxODA5ODQ0In0.aAq6YajYpAiJVSdkqZPaxcCHPkt4GuWmA_qHMk9lXmqpxHRbZWWG09k2IszAJpelswREwqhG-vi7EfKUmidMulpQDJywQdV2zRRyYjIgK0ZABS1KW2m8f9j_I0buXuHB-cv6yT3Ps0VGIbl9qYTOVba-Drf3ahJAwHoQH1JdfdV75Ai9arMoKfynS6Kf_hBBECKifYjVL4ot7RQqgTB52VN_rbtUjeugre7C77SZDn4jm0qXd1FXN1Ht90hI9WqrMsNPy3ixqsRsaElmPA-_PB8ohGXBAGYwk1JjIUohCqhej3GSjiJKT60k6u6vaUGaeyquNujVAZLC-9bjmz1Pdg&lang=en-US", "expiryInMillis": "900000" } ``` #### 3. Get Aggregate Carbon Score {#3-get-aggregate-carbon-score} This endpoint does not require encryption, so you need to pass false to the `getApiClient` method for getting an ApiClient for this endpoint. Also, pass the `userid` in the request to get the carbon score for the particular user. ```java IssuerApi issuerApi = new IssuerApi(getApiClient(false)); System.out.println("Calling Get Aggregate Scores for given user API"); AggregateCarbonScore aggregateCarbonScore = issuerApi.getAggregateCarbonScore(userReference.getUserid()); System.out.println("Get Aggregate Scores for given user API Response is : " + aggregateCarbonScore); System.out.println("------------------------------------------------------------------"); ``` ##### Response {#response-2} In response, you get `carbonEmissionInGrams` for the transactions made in the current month. ```json { "carbonEmissionInGrams": "0" "aggregateDate": "December|2021" } ``` #### 4. Get Issuer {#4-get-issuer} This endpoint does not require encryption, so you need to pass false to the `getApiClient` method to get the ApiClient for this endpoint. ```java IssuerApi issuerApi = new IssuerApi(getApiClient(false)); System.out.println("Calling Calculate Experience to Get Issuer Details"); IssuerProfileDetails issuerProfileDetails = issuerApi.getIssuer(); System.out.println("Calling Calculate Experience Get issuer API response : " + issuerProfileDetails); System.out.println("------------------------------------------------------------------"); ``` ##### Response {#response-3} In response, you get the issuer details. ```json { "clientId": "B6Ao5E71Wn37Zmy8DbMUdXq8XQ4TqpA5f0rs8lV071809844", "customerId": "144136", "supportedAccountRange": "222300,552433,222305,11112,5050,5051", "callbackUrl": "https://www.google.com/", "status": "ACTIVE", "email": "johndoe@partnerbank.com", "currencyCode": "USD", "countryCode": "USA", "countryName": "United States", "privacyNoticeURL": "https://developer.mastercard.com/", "termsAndConditionURL": "https://developer.mastercard.com/", "optOutURL": "https://developer.mastercard.com/", "preferredTheme": { "backgroundColor": "#FFFFFF", "widgetBackgroundColor": "#F2F3F4", "fontColor": "#111111", "barGraphColor":"#FFA500", "buttonColor": "#FFA500", "buttonTextColor": "#FFFFFF", "titleFontType": "Mark Offc For MC", "titleFontSize": "28px", "subTitleFontType": "Mark Offc For MC", "subTitleFontSize": "20px", "paragraphFontType": "Mark Offc For MC", "paragraphFontSize": "15px", "buttonTextFontType": "Mark Offc For MC", "buttonTextFontSize": "15px", "linkFontType": "Mark Offc For MC", "linkFontSize": "15px" } } ``` #### 5. Update Issuer {#5-update-issuer} This endpoint does not require encryption, so you need to pass false to the `getApiClient` method to get the ApiClient for this endpoint. You need to pass the fields along with the value which is required to be updated for the issuer. ```java IssuerApi issuerApi = new IssuerApi(getApiClient(false)); System.out.println("Calling Update Issuer Api"); IssuerConfiguration issuerConfiguration = new IssuerConfiguration(); issuerConfiguration.setSupportedAccountRange("5051"); Map preferredTheme= new HashMap<>(); preferredTheme.put("backgroundColor", "#FFFFFF"); preferredTheme.put("buttonTextColor","#FFFFFF"); preferredTheme.put("widgetBackgroundColor","#FFFFFF"); preferredTheme.put("fontColor","#000000"); preferredTheme.put("barGraphColor", "#111111"); preferredTheme.put("buttonColor","#999999"); preferredTheme.put("titleFontType", "Mark Offc For MC"); preferredTheme.put("titleFontSize", "28px"); preferredTheme.put("subTitleFontType", "Mark Offc For MC"); preferredTheme.put("subTitleFontSize", "20px"); preferredTheme.put("paragraphFontType", "Mark Offc For MC"); preferredTheme.put("paragraphFontSize", "15px"); preferredTheme.put("buttonTextFontType", "Mark Offc For MC"); preferredTheme.put("buttonTextFontSize", "15px"); preferredTheme.put("linkFontType", "Mark Offc For MC"); preferredTheme.put("linkFontSize", "15px"); issuerConfiguration.setPreferredTheme(preferredTheme); IssuerProfile issuerProfile = issuerApi.updateIssuer(issuerConfiguration); System.out.println("Update Issuer API Response is : " + issuerProfile); System.out.println("------------------------------------------------------------------"); ``` ##### Response {#response-4} In response, you get the updated issuer details. ```json { "clientId": "fjl2fxzsYl1OpvxkBItC9nVw1PSQc_b-eQMcmQFg011ab4b5", "customerId": "12345", "supportedAccountRange": "534403, 518145, 518152, 5403, 5424", "status": "ACTIVE", "termsAndConditionURL": "https://www.issuer.term-and-conditions.html", "privacyNoticeURL": "https://www.issuer.privacy-policy-url.html", "optOutURL": "https://www.issuer.opt-out-url.html", "preferredTheme": { "backgroundColor": "#FFFFFF", "widgetBackgroundColor": "#FFFFFF", "fontColor": "#000000", "buttonColor": "#999999", "barGraphColor": "111111", "buttonTextColor": "#FFFFFF", "titleFontType": "Mark Offc For MC", "titleFontSize": "28px", "subTitleFontType": "Mark Offc For MC", "subTitleFontSize": "20px", "paragraphFontType": "Mark Offc For MC", "paragraphFontSize": "15px", "buttonTextFontType": "Mark Offc For MC", "buttonTextFontSize": "15px", "linkFontType": "Mark Offc For MC", "linkFontSize": "15px" } } ``` #### 6. Update User {#6-update-user} This endpoint requires **an encrypted** payload. For encryption to be enabled, you need to pass true to the `getApiClient` method for getting the ApiClient for this endpoint. ```java IssuerApi issuerApiForEncryptionDecryption = new IssuerApi(getApiClient(true)); System.out.println("Calling Update User Api"); UserReference updateUserReference = issuerApiForEncryptionDecryption.updateUser(userReference.getUserid(), getUpdateUserProfile()); System.out.println("Update user Response : " + updateUserReference); System.out.println("------------------------------------------------------------------"); ``` ##### Payload Before Encryption {#payload-before-encryption-1} ```java public static UpdateUserProfile getUpdateUserProfile() { UpdateUserProfile updateUserProfile = new UpdateUserProfile(); UserName userName = new UserName(); userName.setFirstName("dummmyUserrz"); userName.setLastName("Useraf"); updateUserProfile.setName(userName); Address address = new Address(); address.setCountryCode("USA"); address.setLocality("rly station"); address.setLine1("7836 West Elm Street"); address.setLine2("Huntington 120"); address.setPostalCode("11746"); address.setState("Huntington"); address.setLine3("7832 West "); address.setType("work"); address.setCity("Brooklyn"); updateUserProfile.setBillingAddress(address); updateUserProfile.setLocale("en-US"); return updateUserProfile; } ``` ##### Use API client configuration for this API as described in step 3 (Encryption and Decryption). {#use-api-client-configuration-for-this-api-as-described-in-step-3-encryption-and-decryption-2}
##### Response {#response-5} In response, you get a unique `userid` for which user information is updated with its status and the last four digits of the card. ```json { "userid": "c8b38606-12b2-43c6-a641-be8eb0ab9dec", "cardNumberLastFourDigits": "3150", "status": "ACTIVE" } ``` #### 7. Delete User {#7-delete-user} This endpoint does not require encryption, so you need to pass false to the `getApiClient` method to get the ApiClient for this endpoint. You need to pass one or more userIDs in the ArrayList for deletion. ```java IssuerApi issuerApi = new IssuerApi(getApiClient(false)); System.out.println("Calling Delete User API"); List userIds = new ArrayList<>(); userIds.add(userReference.getUserid()); List deletedUserIds = issuerApi.deleteUsers(userIds); System.out.println("Delete User Api response is: " + deletedUserIds); ``` ##### Response {#response-6} In response, you get deleted `userIDs` in the ArrayList. ```json [ "c8b38606-12b2-43c6-a641-be8eb0ab9dec" ] ```