Exemple #1
0
 def setUp(self):
     keyFile = join(dirname(dirname(realpath(__file__))), "resources",
                    "mcapi_sandbox_key.p12")
     self.auth = OAuthAuthentication(
         "L5BsiPgaF-O3qA36znUATgQXwJB6MRoMSdhjd7wt50c97279!50596e52466e3966546d434b7354584c4975693238513d3d",
         keyFile, "test", "password")
     Config.setAuthentication(self.auth)
Exemple #2
0
	def setAuthentication(self, keyId):
		authentication = self.authentications[keyId]

		if authentication is None:
			raise Exception("No authentication found for keyId: " + keyId)

		Config.setAuthentication(authentication)
    def getInstance():
        if ResourceConfig.__initialized == False:
            ResourceConfig.__initialized = True

            tmpInstance = ResourceConfig.__new__(ResourceConfig)

            Config.registerResourceConfig(tmpInstance)
            tmpInstance.setEnvironment(Config.getEnvironment())

            ResourceConfig.__instance = tmpInstance

        return ResourceConfig.__instance
Exemple #4
0
    def getInstance():
        if ResourceConfig.__initialized == False:
            print("initilizing.... true")
            ResourceConfig.__initialized = True

            print("creating a new instance")
            tmpInstance = ResourceConfig.__new__(ResourceConfig)

            print("regestring a new instance")
            Config.registerResourceConfig(tmpInstance)
            tmpInstance.setEnvironment(Config.getEnvironment())

            print("saving instance")
            ResourceConfig.__instance = tmpInstance

        return ResourceConfig.__instance
def main():
    consumerKey = "YT8iexhqzg5vWetxDvntC5f13J6JFEnwlL8FTKtm7837dcf6!66f2fd60279d4e649c9343a6d0964d410000000000000000"
    # You should copy this from "My Keys" on your project page e.g. UTfbhDCSeNYvJpLL5l028sWL9it739PYh6LU5lZja15xcRpY!fd209e6c579dc9d7be52da93d35ae6b6c167c174690b72fa
    keyStorePath = "D:\keyalias-sandbox.p12"
    # e.g. /Users/yourname/project/sandbox.p12 | C:\Users\yourname\project\sandbox.p12
    keyAlias = "keyalias"  # For production: change this to the key alias you chose when you created your production key
    keyPassword = "******"  # For production: change this to the key alias you chose when you created your production key

    auth = OAuthAuthentication(consumerKey, keyStorePath, keyAlias, keyPassword)
    Config.setAuthentication(auth)
    Config.setDebug(True)  # Enable http wire logging
    Config.setSandbox(True)

    try:
        mapObj = RequestMap()
        mapObj.set("SearchRequest.AccountPan", "5412345678901234")
        mapObj.set("SearchRequest.ExcludeDeletedIndicator", "false")
        mapObj.set("SearchRequest.AuditInfo.UserId", "A1435477")
        mapObj.set("SearchRequest.AuditInfo.UserName", "John Smith")
        mapObj.set("SearchRequest.AuditInfo.Organization", "Any Bank")
        mapObj.set("SearchRequest.AuditInfo.Phone", "5555551234")

        response = Search.create(mapObj)

    except APIException as e:
        print("HttpStatus: %s") % e.getHttpStatus()
        print("Message: %s") % e.getMessage()
        print("ReasonCode: %s") % e.getReasonCode()
        print("Source: %s") % e.getSource()
def test_login(consumerKey, keyPassword):
    auth = OAuthAuthentication(consumerKey, keyStorePath, keyAlias,
                               keyPassword)
    Config.setAuthentication(auth)
    Config.setDebug(True)  # Enable http wire logging
    Config.setSandbox(True)

    try:
        mapObj = RequestMap()
        mapObj.set("AccountHolderMessagingRequest.TokenUniqueReference",
                   "DWSPMC00000000010906a349d9ca4eb1a4d53e3c90a11d9c")
        mapObj.set("AccountHolderMessagingRequest.MessageText",
                   " You have earned a statement credit ")
        mapObj.set("AccountHolderMessagingRequest.MessageExpiration",
                   "2020-09-18T18:04:35-06:00")
        mapObj.set("AccountHolderMessagingRequest.MessageLanguageCode", "en")
        mapObj.set("AccountHolderMessagingRequest.MessageIdentifier",
                   "6598123486451346764616431064")
        mapObj.set(
            "AccountHolderMessagingRequest.IssuerApplicationMessageDisplay",
            "FALSE")
        mapObj.set("AccountHolderMessagingRequest.AuditInfo.UserId",
                   "A1435477")
        mapObj.set("AccountHolderMessagingRequest.AuditInfo.UserName",
                   "John Smith")
        mapObj.set("AccountHolderMessagingRequest.AuditInfo.Organization",
                   "Any Bank")
        mapObj.set("AccountHolderMessagingRequest.AuditInfo.Phone",
                   "5555551234")

        response = AccountHolderMessaging.create(mapObj)
        out(response,
            "AccountHolderMessagingResponse.Token.TokenUniqueReference")
        #-->DWSPMC00000000010906a349d9ca4eb1a4d53e3c90a11d9c

    except APIException as e:
        err("HttpStatus: %s", e.getHttpStatus())
        err("Message: %s", e.getMessage())
        err("ReasonCode: %s", e.getReasonCode())
        err("Source: %s", e.getSource())
Exemple #7
0
    def __init__(self,
                 consumer_key=None,
                 key_store_path=None,
                 key_alias=None,
                 keystore_password=None,
                 app_id=None):
        self.consumer_key = consumer_key if consumer_key else CREDS[
            'consumer_key']
        self.key_store_path = key_store_path if key_store_path else CREDS[
            'key_store_path']
        self.key_alias = key_alias if key_alias else CREDS['key_alias']
        self.keystore_password = keystore_password if keystore_password else CREDS[
            'keystore_password']
        self.oauth = OAuthAuthentication(self.consumer_key,
                                         self.key_store_path, self.key_alias,
                                         self.keystore_password)

        Config.setAuthentication(self.oauth)
        Config.setDebug(True)  # Enable http wire logging
        Config.setSandbox(True)

        self.app_id = CREDS['app_identifier']
def main():
	consumerKey = "YT8iexhqzg5vWetxDvntC5f13J6JFEnwlL8FTKtm7837dcf6!66f2fd60279d4e649c9343a6d0964d410000000000000000"
	# You should copy this from "My Keys" on your project page e.g. UTfbhDCSeNYvJpLL5l028sWL9it739PYh6LU5lZja15xcRpY!fd209e6c579dc9d7be52da93d35ae6b6c167c174690b72fa
	keyStorePath = "D:\keyalias-sandbox.p12"
	# e.g. /Users/yourname/project/sandbox.p12 | C:\Users\yourname\project\sandbox.p12
	keyAlias = "keyalias"   # For production: change this to the key alias you chose when you created your production key
	keyPassword = "******"   # For production: change this to the key alias you chose when you created your production key

	auth = OAuthAuthentication(consumerKey, keyStorePath, keyAlias, keyPassword)
	Config.setAuthentication(auth)
	Config.setDebug(True) # Enable http wire logging
	Config.setSandbox(True)
	
	try:
		mapObj = RequestMap()
		response = SystemStatus.query(mapObj)
		print("SystemStatusResponse.CommentText--> %s") % response.get("SystemStatusResponse.CommentText") #SystemStatusResponse.CommentText-->System is fully operational.

	except APIException as e:
		print("HttpStatus: %s") % e.getHttpStatus()
		print("Message: %s") % e.getMessage()
		print("ReasonCode: %s") % e.getReasonCode()
		print("Source: %s") % e.getSource()
Exemple #9
0
    def test_config(self):
        self.assertEqual(Config.getEnvironment(), Environment.SANDBOX)

        Config.setSandbox(False)
        self.assertEqual(Config.getEnvironment(), Environment.PRODUCTION)

        Config.setSandbox(True)
        self.assertEqual(Config.getEnvironment(), Environment.SANDBOX)

        Config.setEnvironment(Environment.STAGE)
        self.assertEqual(Config.getEnvironment(), Environment.STAGE)

        Config.setEnvironment("")
        self.assertEqual(Config.getEnvironment(), Environment.STAGE)

        Config.setEnvironment(None)
        self.assertEqual(Config.getEnvironment(), Environment.STAGE)
Exemple #10
0
    def test_environment(self):
        inputMap = []

        Config.setEnvironment(Environment.SANDBOX)
        resourceConfig = ResourceConfig()

        config = OperationConfig("/fraud/#env/v1/account-inquiry", "create",
                                 [], [])
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())

        #dafault
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())
        url = self.controller.getURL(config, metadata, inputMap)
        self.assertEqual(
            url, "https://sandbox.api.mastercard.com/fraud/v1/account-inquiry")

        #dafault
        Config.setEnvironment(Environment.PRODUCTION_MTF)
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())
        self.assertEqual(
            self.controller.getURL(config, metadata, inputMap),
            "https://api.mastercard.com/fraud/mtf/v1/account-inquiry")

        Config.setEnvironment(Environment.PRODUCTION_ITF)
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())
        self.assertEqual(
            self.controller.getURL(config, metadata, inputMap),
            "https://api.mastercard.com/fraud/itf/v1/account-inquiry")

        Config.setEnvironment(Environment.STAGE)
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())
        self.assertEqual(
            self.controller.getURL(config, metadata, inputMap),
            "https://stage.api.mastercard.com/fraud/v1/account-inquiry")

        Config.setEnvironment("")
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())
        self.assertEqual(
            self.controller.getURL(config, metadata, inputMap),
            "https://stage.api.mastercard.com/fraud/v1/account-inquiry")

        Config.setEnvironment(None)
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())
        self.assertEqual(
            self.controller.getURL(config, metadata, inputMap),
            "https://stage.api.mastercard.com/fraud/v1/account-inquiry")

        Config.setEnvironment(Environment.LOCALHOST)
        metadata = OperationMetadata("0.0.1", resourceConfig.getHost(),
                                     resourceConfig.getContext())
        self.assertEqual(self.controller.getURL(config, metadata, inputMap),
                         "http://localhost:8081/fraud/v1/account-inquiry")

        Config.clearResourceConfig()
Exemple #11
0
    def test_getRequestObject(self):

        defaultHeaders = {
            APIController.KEY_ACCEPT: APIController.APPLICATION_JSON,
            APIController.KEY_CONTENT_TYPE: APIController.APPLICATION_JSON,
            APIController.KEY_USER_AGENT: APIController.PYTHON_SDK + "/0.0.1"
        }

        inputMap = {
            "param1": 1,
            "param2": 2,
            "a": "1",
            APIController.KEY_ACCEPT: APIController.APPLICATION_JSON,
            APIController.KEY_CONTENT_TYPE: APIController.APPLICATION_JSON,
            APIController.KEY_USER_AGENT: APIController.PYTHON_SDK + "/0.0.1"
        }

        config = OperationConfig("/fraud/api/v1/account-inquiry", "create",
                                 ['Accept', 'Content-Type', 'User-Agent'],
                                 ["a"])
        metadata = OperationMetadata("0.0.1",
                                     "https://sandbox.api.mastercard.com")

        url = "https://sandbox.api.mastercard.com/fraud/api/v1/account-inquiry"

        Config.setAuthentication(None)

        #Create Request with inputMap
        request = self.controller.getRequestObject(config, metadata, inputMap)

        self.assertEqual(request.url, url)
        self.assertEqual(request.params, {
            APIController.KEY_FORMAT: APIController.JSON,
            "a": "1"
        })
        self.assertEqual(json.loads(request.data), inputMap)
        self.assertEqual(request.headers, defaultHeaders)

        inputMap = {"param1": 1, "param2": 2, "a": "1", "b": 2}

        config = OperationConfig("/fraud/api/v1/account-inquiry", "list",
                                 ['Accept', 'Content-Type', 'User-Agent'],
                                 ["a", "b"])

        #List Request with inputMap
        request = self.controller.getRequestObject(config, metadata, inputMap)

        self.assertEqual(request.params, {
            "param1": 1,
            "param2": 2,
            "a": "1",
            "b": 2,
            "Format": "JSON"
        })
        self.assertEqual(request.data, [])
        self.assertEqual(request.headers, defaultHeaders)
        self.assertEqual(request.url, url)

        inputMap = {"a": "1", "b": 2}

        #List Request with no inputMap
        request = self.controller.getRequestObject(config, metadata, inputMap)

        self.assertEqual(request.params, {"a": "1", "b": 2, "Format": "JSON"})
        self.assertEqual(request.data, [])
        self.assertEqual(request.headers, defaultHeaders)
        self.assertEqual(request.url, url)
def main():
    consumerKey = "YT8iexhqzg5vWetxDvntC5f13J6JFEnwlL8FTKtm7837dcf6!17c438eb264f403f80d8fada38b34e1b0000000000000000"
    # You should copy this from "My Keys" on your project page e.g. UTfbhDCSeNYvJpLL5l028sWL9it739PYh6LU5lZja15xcRpY!fd209e6c579dc9d7be52da93d35ae6b6c167c174690b72fa
    keyStorePath = "D:\ub-mdescs-1499832439-sandbox.p12"
    # e.g. /Users/yourname/project/sandbox.p12 | C:\Users\yourname\project\sandbox.p12
    keyAlias = "keyalias"  # For production: change this to the key alias you chose when you created your production key
    keyPassword = "******"  # For production: change this to the key alias you chose when you created your production key

    auth = OAuthAuthentication(consumerKey, keyStorePath, keyAlias, keyPassword)
    Config.setAuthentication(auth)
    Config.setDebug(True)  # Enable http wire logging
    Config.setSandbox(True)

    try:
        mapObj = RequestMap()
        mapObj.set("SearchRequest.TokenUniqueReference", "DWSPMC00000000010906a349d9ca4eb1a4d53e3c90a11d9c")
        mapObj.set("SearchRequest.AuditInfo.UserId", "A1435477")
        mapObj.set("SearchRequest.AuditInfo.UserName", "John Smith")
        mapObj.set("SearchRequest.AuditInfo.Organization", "Any Bank")
        mapObj.set("SearchRequest.AuditInfo.Phone", "5555551234")

        response = Search.create(mapObj)
        print("SearchResponse.Accounts.Account[0].AccountPanSuffix--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].AccountPanSuffix")  # SearchResponse.Accounts.Account[0].AccountPanSuffix-->1234
        print("SearchResponse.Accounts.Account[0].ExpirationDate--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].ExpirationDate")  # SearchResponse.Accounts.Account[0].ExpirationDate-->1215
        print("SearchResponse.Accounts.Account[0].AlternateAccountIdentifierSuffix--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].AlternateAccountIdentifierSuffix")  # SearchResponse.Accounts.Account[0].AlternateAccountIdentifierSuffix-->4300
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenUniqueReference--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenUniqueReference")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenUniqueReference-->DWSPMC00000000010906a349d9ca4eb1a4d53e3c90a11d9c
        print(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].PrimaryAccountNumberUniqueReference--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].PrimaryAccountNumberUniqueReference")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].PrimaryAccountNumberUniqueReference-->FWSPMC0000000004793dac803f190a4dca4bad33c90a11d3
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenSuffix--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenSuffix")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenSuffix-->7639
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].ExpirationDate--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].ExpirationDate")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].ExpirationDate-->0216
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].AccountPanSequenceNumber--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].AccountPanSequenceNumber")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].AccountPanSequenceNumber-->002
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].DigitizationRequestDateTime--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].DigitizationRequestDateTime")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].DigitizationRequestDateTime-->2015-01-20T18:04:35-06:00
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenActivatedDateTime--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenActivatedDateTime")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenActivatedDateTime-->2015-01-20T18:04:35-06:00
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].FinalTokenizationDecision--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].FinalTokenizationDecision")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].FinalTokenizationDecision-->A
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].CorrelationId--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].CorrelationId")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].CorrelationId-->101234
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].CurrentStatusCode--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].CurrentStatusCode")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].CurrentStatusCode-->A
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].CurrentStatusDescription--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].CurrentStatusDescription")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].CurrentStatusDescription-->Active
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].ProvisioningStatusCode--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].ProvisioningStatusCode")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].ProvisioningStatusCode-->S
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].ProvisioningStatusDescription--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].ProvisioningStatusDescription")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].ProvisioningStatusDescription-->Provisioning successful
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenRequestorId--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenRequestorId")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenRequestorId-->00212345678
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].WalletId--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].WalletId")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].WalletId-->103
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].PaymentAppInstanceId--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].PaymentAppInstanceId")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].PaymentAppInstanceId-->92de9357a535b2c21a3566e446f43c532a46b54c46
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenType--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenType")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenType-->S
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].LastCommentId--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].LastCommentId")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].LastCommentId-->2376
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceId--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceId")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceId-->3e5edf24a24ba98e27d43e345b532a245e4723d7a9c4f624e93452c92de9357a535b2c21a3566e446f43c532d34s6
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceName--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceName")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceName-->John Phone
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceType--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceType")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.DeviceType-->09
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.SecureElementId--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.SecureElementId")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].Device.SecureElementId-->92de9357a535b2c21a3566e446f43c532a46b54c46
        print("SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenDeletedFromConsumerApp--> %s") % response.get(
            "SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenDeletedFromConsumerApp")  # SearchResponse.Accounts.Account[0].Tokens.Token[0].TokenDeletedFromConsumerApp-->false

    except APIException as e:
        print("HttpStatus: %s") % e.getHttpStatus()
        print("Message: %s") % e.getMessage()
        print("ReasonCode: %s") % e.getReasonCode()
        print("Source: %s") % e.getSource()
 def setUp(self):
     Config.setDebug(True)
     self.resetAuthentication()
def test_login(consumerKey, keyPassword):
    auth = OAuthAuthentication(consumerKey, keyStorePath, keyAlias,
                               keyPassword)
    Config.setAuthentication(auth)
    Config.setDebug(True)  # Enable http wire logging
    Config.setSandbox(True)
 def __init__(cls):
     if cls.initialized == False:
         Config.registerResourceConfig(cls)
         cls.setEnvironment(Config.getEnvironment())
         cls.initialized = True