def test_Disputes_GetSettlementTransfer(self):
        self.refreshClientDisputes()

        dispute = None

        for d in self._clientDisputes:
            if (d.Status == DisputeStatus.CLOSED
                    and d.DisputeType == DisputeType.NOT_CONTESTABLE):
                dispute = d
                break

        self.assertIsNotNone(
            dispute,
            'Cannot test getting settlement transfer because there\'s no closed and not contestable disputes in the disputes list.'
        )

        repudiationId = self.sdk.disputes.GetTransactions(
            dispute.Id, Pagination(1, 1))[0].Id
        repudiation = self.sdk.disputes.GetRepudiation(repudiationId)

        post = Settlement()
        post.AuthorId = repudiation.AuthorId
        post.DebitedFunds = Money(1, 'EUR')
        post.Fees = Money(0, 'EUR')

        transfer = self.sdk.disputes.CreateSettlementTransfer(
            post, repudiationId)

        self.assertIsNotNone(transfer)

        result = self.sdk.disputes.GetSettlementTransfer(transfer.Id)

        self.assertIsNotNone(result)
        self.assertIsNotNone(result.RepudiationId)
        self.assertEqual(result.RepudiationId, repudiation.Id)
Exemple #2
0
    def _getList (self, methodKey, pagination, responseClassName = None, entityId = None, filter = None, sorting = None):
        """Get list with entities object from API.
        param string methodKey Key with request data
        param pagination Pagination object
        param object responseClassName Name of entity class from response
        param int entityId Entity identifier
        param object filter Object to filter data
        param object sorting Object to sort data
        return object Response data
        """
        urlMethod = self._buildUrl(methodKey, entityId)

        if pagination == None:
            pagination = Pagination()

        rest = RestTool(self._root, True)
        additionalUrlParams = {}
        if (filter != None):
            additionalUrlParams['filter'] = filter
        if (sorting != None):
            additionalUrlParams['sort'] = sorting.GetSortParameter()

        response = rest.Request(urlMethod, self._getRequestType(methodKey), None, pagination, additionalUrlParams)

        if responseClassName != None:
            return self._castResponseToEntity(response, responseClassName)
        return response
    def test_Disputes_GetFilteredDisputeDocuments(self):

        now = int(time.time()) + 100

        filterAfter = FilterTransactions()
        filterBefore = FilterTransactions()
        filterAfter.AfterDate = now
        filterBefore.BeforeDate = now

        pagination = Pagination()

        result1 = self.sdk.disputes.GetDocumentsForClient(
            pagination, filterAfter)
        result2 = self.sdk.disputes.GetDocumentsForClient(
            pagination, filterBefore)

        self.assertIsNotNone(result1)
        self.assertIsNotNone(result2)
        self.assertTrue(len(result1) == 0)
        self.assertTrue(len(result2) > 0)

        filterType = FilterTransactions()
        filterType.Type = result2[0].Type
        result3 = self.sdk.disputes.GetDocumentsForClient(
            pagination, filterType)
        self.assertIsNotNone(result3)
        self.assertTrue(len(result3) > 0)

        for dd in result3:
            self.assertTrue(dd.Type, result2[0].Type)
    def test_KycDocuments_GetAll_SortByCreationDate(self):
        pagination = Pagination(1, 10)
        sorting = Sorting()
        sorting.AddField('CreationDate', SortDirection.DESC)

        list = self.sdk.kycdocuments.GetAll(pagination, sorting)

        self.assertTrue(list[0].CreationDate >= list[1].CreationDate)
    def test_Hooks_All(self):
        hook = self.getJohnHook()
        pagination = Pagination(1, 1)

        list = self.sdk.hooks.GetAll(pagination)

        self.assertTrue(isinstance(list[0], Hook))
        self.assertEqual(hook.Id, list[0].Id)
        self.assertEqual(pagination.Page, 1)
        self.assertEqual(pagination.ItemsPerPage, 1)
Exemple #6
0
    def test_Users_Transactions_SortByCreationDate(self):
        john = self.getJohn()
        self.getJohnsPayInCardDirect()
        self.getJohnsPayInCardDirect()
        pagination = Pagination(1, 10)
        sorting = Sorting()
        sorting.AddField('CreationDate', SortDirection.DESC)

        list = self.sdk.users.GetTransactions(john.Id, pagination, sorting)

        self.assertTrue(list[0].CreationDate > list[1].CreationDate)
    def test_Users_GetKycDocuments(self):
        kycDocument = self.getUserKycDocument()
        user = self.getJohn()
        pagination = Pagination(1, 10)
        self.sdk.users.GetKycDocuments(user.Id, pagination)
        pagination.Page = pagination.TotalPages
        getKycDocuments = self.sdk.users.GetKycDocuments(user.Id, pagination)

        kycFromList = self.getEntityFromList(kycDocument.Id, getKycDocuments)
        self.assertIsInstance(kycFromList, KycDocument)
        self.assertEqualInputProps(kycDocument, kycFromList)
    def test_KycDocuments_GetAll(self):
        kycDocument = self.getUserKycDocument()
        pagination = Pagination(1, 100)
        self.sdk.kycdocuments.GetAll(pagination)
        pagination.Page = pagination.TotalPages
        list = self.sdk.kycdocuments.GetAll(pagination)

        kycFromList = self.getEntityFromList(kycDocument.Id, list)
        
        self.assertTrue(isinstance(kycFromList, KycDocument))
        self.assertEqualInputProps(kycDocument, kycFromList)
        self.assertEqual(pagination.ItemsPerPage, 100)
Exemple #9
0
    def test_Users_BankAccounts_SortByCreationDate(self):
        john = self.getJohn()
        self.getJohnsAccount()
        self._johnsAccount = None
        self.getJohnsAccount()
        pagination = Pagination(1, 10)
        sorting = Sorting()
        sorting.AddField('CreationDate', SortDirection.DESC)

        list = self.sdk.users.GetBankAccounts(john.Id, pagination, sorting)

        self.assertTrue(list[0].CreationDate >= list[1].CreationDate)
    def refreshClientDisputes(self):
        sorting = Sorting()
        sorting.AddField("CreationDate", SortDirection.DESC)
        pagination = Pagination(1, 100)
        self._clientDisputes = self.sdk.disputes.GetAll(
            pagination, None, sorting)

        self.assertIsNotNone(self._clientDisputes,
                             'INITIALIZATION FAILURE - cannot test disputes')
        self.assertTrue(
            len(self._clientDisputes) > 0,
            'INITIALIZATION FAILURE - cannot test disputes')
        return
    def test_Clients_GetWalletTransactions(self):
        feesWallets = self.sdk.clients.GetWallets(FundsType.FEES, Pagination(1, 1))
        creditWallets = self.sdk.clients.GetWallets(FundsType.CREDIT, Pagination(1, 1))
        defaultWallets = self.sdk.clients.GetWallets(FundsType.DEFAULT, Pagination(1, 1))

        if (feesWallets == None or len(feesWallets) == 0 or creditWallets == None or len(creditWallets) == 0 or defaultWallets == None or len(defaultWallets) == 0):
            self.assertTrue(False, "Cannot test getting client's wallet because there is no any wallet for client.")

        wallet = None
        result = None
        if (feesWallets != None and len(feesWallets) > 0):
            wallet = feesWallets[0]
        else:
            if (creditWallets != None and len(creditWallets) > 0):
                wallet = creditWallets[0]
            else:
                wallet = defaultWallets[0]

        result = self.sdk.clients.GetWalletTransactions(wallet.FundsType, wallet.Currency)

        self.assertIsNotNone(result)
        self.assertTrue(len(result) > 0)
Exemple #12
0
    def test_Wallets_Transactions(self):
        john = self.getJohn()
        wallet = self.getJohnsWallet()
        payIn = self.getJohnsPayInCardWeb()

        pagination = Pagination(1, 1)
        filter = FilterTransactions()
        filter.Type = TransactionType.PAYIN
        transactions = self.sdk.wallets.GetTransactions(wallet.Id, pagination, filter)

        self.assertEqual(len(transactions), 1)
        self.assertIsInstance(transactions[0], Transaction)
        self.assertEqual(transactions[0].AuthorId, john.Id)
        self.assertEqualInputProps(transactions[0], payIn)
Exemple #13
0
    def getJohnHook(self):
        if self._johnsHook == None:
            pagination = Pagination(1, 1)
            list = self.sdk.hooks.GetAll(pagination)

            if list[0] != None:
                self._johnsHook = list[0]
            else:
                hook = Hook()
                hook.EventType = EventType.PAYIN_NORMAL_CREATED
                hook.Url = 'http://test.com'
                self._johnsHook = self.sdk.hooks.Create(hook)

        return self._johnsHook
    def test_Users_BankAccounts(self):
        john = self.getJohn()
        account = self.getJohnsAccount()
        pagination = Pagination(1, 12)

        list = self.sdk.users.GetBankAccounts(john.Id, pagination)

        self.assertIsInstance(list[0], BankAccount)
        self.assertEqual(account.Id, list[0].Id)
        self.assertEqualInputProps(account, list[0])
        self.assertEqual(pagination.Page, 1)
        self.assertEqual(pagination.ItemsPerPage, 12)
        self.assertTrue(pagination.TotalPages > 0)
        self.assertTrue(pagination.TotalItems > 0)
    def test_Disputes_SubmitDisputeDocument(self):
        self.refreshClientDisputes()

        dispute = None
        disputeDocument = None

        filter = FilterDisputeDocuments()
        filter.Status = DisputeDocumentStatus.CREATED

        for d in self._clientDisputes:
            if (d.Status == DisputeStatus.PENDING_CLIENT_ACTION or d.Status
                    == DisputeStatus.REOPENED_PENDING_CLIENT_ACTION):
                dd = self.sdk.disputes.GetDocumentsForDispute(
                    d.Id, Pagination(1, 1), filter)[0]
                if (dd != None):
                    dispute = d
                    disputeDocument = dd
                    break

        if (dispute == None):
            for d in self._clientDisputes:
                if (d.Status == DisputeStatus.PENDING_CLIENT_ACTION or d.Status
                        == DisputeStatus.REOPENED_PENDING_CLIENT_ACTION):
                    documentPost = DisputeDocument()
                    documentPost.Type = DisputeDocumentType.DELIVERY_PROOF
                    disputeDocument = self.sdk.disputes.CreateDocument(
                        documentPost, d.Id)

        self.assertIsNotNone(
            dispute,
            'Cannot test submitting dispute\'s documents because there\'s no dispute with expected status in the disputes list.'
        )

        self.assertIsNotNone(
            disputeDocument,
            'Cannot test submitting dispute\'s documents because there\'s no dispute document that can be updated.'
        )

        disputeDocumentPut = DisputeDocument()
        disputeDocumentPut.Id = disputeDocument.Id
        disputeDocumentPut.Status = DisputeDocumentStatus.VALIDATION_ASKED

        result = self.sdk.disputes.SubmitDisputeDocument(
            disputeDocumentPut, dispute.Id)

        self.assertIsNotNone(result)
        self.assertTrue(disputeDocument.Type == result.Type)
        self.assertTrue(
            result.Status == DisputeDocumentStatus.VALIDATION_ASKED)
Exemple #16
0
    def test_Wallets_Transactions_SortByCreationDate(self):
        wallet = self.getJohnsWallet()
        #create 2 pay-in objects
        self.getJohnsPayInCardWeb()
        self.getJohnsPayInCardWeb()

        sorting = Sorting()
        sorting.AddField('CreationDate', SortDirection.DESC)
        pagination = Pagination(1, 20)
        filter = FilterTransactions()
        filter.Type = TransactionType.PAYIN

        transactions = self.sdk.wallets.GetTransactions(wallet.Id, pagination, filter, sorting)

        self.assertTrue(transactions[0].CreationDate > transactions[1].CreationDate)
    def test_Events_GetEvents_Page_Of_Type(self):
        self.pageLength = 3
        pagination = Pagination(1, self.pageLength)
        filter = FilterTransactions()
        self.type = EventType.PAYIN_NORMAL_CREATED
        filter.EventType = self.type

        event = self.sdk.events.Get(pagination, filter)
        self.assertTrue(len(event) <= self.pageLength)
        if (len(event) > 0):
            self.assertEqual(event[0].EventType, self.type)
        if (len(event) > 1):
            self.assertEqual(event[1].EventType, self.type)
        if (len(event) > 2):
            self.assertEqual(event[2].EventType, self.type)
    def test_Disputes_GetFilteredDisputes(self):

        now = int(time.time())

        filterAfter = FilterTransactions()
        filterBefore = FilterTransactions()
        filterAfter.AfterDate = now
        filterBefore.BeforeDate = now

        pagination = Pagination()

        result1 = self.sdk.disputes.GetAll(pagination, filterAfter)
        result2 = self.sdk.disputes.GetAll(pagination, filterBefore)

        self.assertIsNotNone(result1)
        self.assertIsNotNone(result2)
        self.assertTrue(len(result1) == 0)
        self.assertTrue(len(result2) > 0)
Exemple #19
0
    def test_Mandates_Get_For_Bank_Account(self):
        user = self.getJohn()
        bankAccountId = self.getJohnsAccount().Id
        returnUrl = 'http://test.test'

        mandatePost = Mandate()
        mandatePost.BankAccountId = bankAccountId
        mandatePost.Culture = 'EN'
        mandatePost.ReturnURL = returnUrl

        mandateCreated = self.sdk.mandates.Create(mandatePost)

        sorting = Sorting()
        sorting.AddField("CreationDate", SortDirection.DESC)
        mandates = self.sdk.mandates.GetForBankAccount(user.Id, bankAccountId, Pagination(), sorting)

        self.assertIsNotNone(mandates)
        self.assertIsNotNone(mandates[0])
        self.assertTrue(mandateCreated.Id == mandates[0].Id)
    def test_Disputes_GetTransactions(self):
        self.refreshClientDisputes()

        dispute = None

        for d in self._clientDisputes:
            if (d.DisputeType == DisputeType.NOT_CONTESTABLE):
                dispute = d
                break

        self.assertIsNotNone(
            dispute,
            'Cannot test getting dispute\'s transactions because there\'s no not contestable dispute in the disputes list.'
        )

        pagination = Pagination(1, 10)
        transactions = self.sdk.disputes.GetTransactions(
            dispute.Id, pagination)

        self.assertIsNotNone(transactions)
        self.assertTrue(len(transactions) > 0)
    def test_Disputes_GetDisputesForWallet(self):
        self.refreshClientDisputes()

        dispute = None

        for d in self._clientDisputes:
            if (d.InitialTransactionId != None):
                dispute = d
                break

        self.assertIsNotNone(
            dispute,
            'Cannot test getting disputes for wallet because there\'s no dispute with transaction ID in the disputes list.'
        )

        walletId = self.sdk.payIns.Get(
            dispute.InitialTransactionId).CreditedWalletId
        pagination = Pagination(1, 10)
        disputes = self.sdk.disputes.GetDisputesForWallet(walletId, pagination)

        self.assertIsNotNone(disputes)
        self.assertTrue(len(disputes) > 0)
Exemple #22
0
"""

## run some test
#import tests.testapiusers
#t = tests.testapiusers.Test_ApiUsers()
#t.test_Users_GetNatural()

from mangopaysdk.mangopayapi import MangoPayApi
from mangopaysdk.types.pagination import Pagination

api = MangoPayApi()
# test client credentials
api.Config.ClientID = 'sdk-unit-tests'
api.Config.ClientPassword = '******'

# optionally reuse token from previous requests (unless expired)
token = api.authenticationManager.CreateToken()
api.OAuthToken = token

# GET USERS LIST: GET /users
pagination = Pagination(1, 8)
users = api.users.GetAll(pagination)

# display result on screen
print(users)

# optionally store token for future requests (unless expires)
print(api.OAuthToken)

input('...')
    def test_Clients_GetWallets(self):
        feesWallets = self.sdk.clients.GetWallets(FundsType.FEES, Pagination(1, 1))
        creditWallets = self.sdk.clients.GetWallets(FundsType.CREDIT, Pagination(1, 1))

        self.assertIsNotNone(feesWallets)
        self.assertIsNotNone(creditWallets)
 def test_stadnardUseToken(self):
     self.sdk.users.GetAll(Pagination(1, 2))
     token = self.sdk.OAuthTokenManager.GetToken()
     self.sdk.users.GetAll(Pagination(1, 2))
     self.assertEqual(token.access_token, self.sdk.OAuthTokenManager.GetToken().access_token)
 def test_isTokenLeaking(self):
     api = self.buildNewMangoPayApi()
     self.sdk.users.GetAll(Pagination(1, 2))
     token1 = self.sdk.OAuthTokenManager.GetToken()
     token2 = api.OAuthTokenManager.GetToken()
     self.assertEqual(token1.access_token, token2.access_token)