Created
October 17, 2019 06:09
-
-
Save Kalimaha/19cb08f52666dea9eae92661d2cfc6a9 to your computer and use it in GitHub Desktop.
MDES pushAccount
This file contains hidden or 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
| package au.com.mebank.bfamdesplayground.repositories | |
| import com.mastercard.api.core.ApiConfig | |
| import com.mastercard.api.core.model.RequestMap | |
| import com.mastercard.api.core.security.mdes.MDESCryptography | |
| import com.mastercard.api.core.security.oauth.OAuthAuthentication | |
| import org.springframework.util.ResourceUtils | |
| import java.io.FileInputStream | |
| import com.mastercard.api.mdestokenconnect.PushAccount | |
| const val KEY_ALIAS = "keyalias" | |
| const val KEY_PASSWORD = "keystorepassword" | |
| const val CONSUMER_KEY = "oCwdl50RQLOSlrSzIGsTuDpClCQo0kKX34P5ZHZd2a3d9dde!828148b322b04402824f548355ecb2f20000000000000000" | |
| const val SERVICE_CERTIFICATE_PATH = "classpath:certificate.p12" | |
| const val MASTERCARD_CERTIFICATE_PATH = "classpath:mastercard_certificate.crt" | |
| fun pushAccount(type: String = "IOS"): String { | |
| initSDK() | |
| val requestMap = RequestMap() | |
| requestMap.set("requestId", "123456") | |
| requestMap.set("pushFundingAccount.encryptedPayload.encryptedData.cardAccountData.accountNumber", "5123456789012346") | |
| requestMap.set("tokenRequestorId", "12345678901") | |
| val response: List<Map<String, Object>> = PushAccount.create(requestMap).get("availablePushMethods") as List<Map<String, Object>> | |
| return response.find { it["type"].toString() == type }?.get("uri").toString() | |
| } | |
| private fun initSDK() { | |
| val certificate = FileInputStream(ResourceUtils.getFile(SERVICE_CERTIFICATE_PATH)) | |
| val masterCardCertificate = FileInputStream(ResourceUtils.getFile(MASTERCARD_CERTIFICATE_PATH)) | |
| val cryptographyInterceptor = MDESCryptography(masterCardCertificate, null) | |
| ApiConfig.setDebug(false) | |
| ApiConfig.setSandbox(true) | |
| ApiConfig.addCryptographyInterceptor(cryptographyInterceptor) | |
| ApiConfig.setAuthentication(OAuthAuthentication(CONSUMER_KEY, certificate, KEY_ALIAS, KEY_PASSWORD)) | |
| } |
This file contains hidden or 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
| package au.com.mebank.bfamdesplayground.repositories | |
| import org.junit.jupiter.api.Test | |
| import org.assertj.core.api.Assertions.assertThat | |
| class MDESRepositoryTest { | |
| @Test | |
| fun `returns URI for iOS devices`() { | |
| assertThat(pushAccount()).isEqualTo("tokenrequestor1://com.tokenrequestor1.pushtoken") | |
| } | |
| @Test | |
| fun `returns URI for web devices`() { | |
| assertThat(pushAccount(type = "WEB")).isEqualTo("http://www.tokenrequestor1.com/pushtoken") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment