diff --git a/mangopay/resources.py b/mangopay/resources.py index d44b5be..8bc7dd5 100644 --- a/mangopay/resources.py +++ b/mangopay/resources.py @@ -1557,9 +1557,30 @@ class Meta: verbose_name_plural = 'card_preauthorized_deposit_payins' url = { InsertQuery.identifier: '/payins/deposit-preauthorized/direct/full-capture', - SelectQuery.identifier: '/payins' + SelectQuery.identifier: '/payins', + 'CREATE_WITHOUT_COMPLEMENT': '/payins/deposit-preauthorized/direct/full-capture', + 'CREATE_PRIOR_TO_COMPLEMENT': '/payins/deposit-preauthorized/direct/capture-with-complement', + 'CREATE_COMPLEMENT': '/payins/deposit-preauthorized/direct/complement' } + def create_without_complement(self, idempotency_key=None, **kwargs): + insert = InsertQuery(self, idempotency_key, **kwargs) + insert.identifier = 'CREATE_WITHOUT_COMPLEMENT' + insert.insert_query = self.get_field_dict() + return insert.execute() + + def create_prior_to_complement(self, idempotency_key=None, **kwargs): + insert = InsertQuery(self, idempotency_key, **kwargs) + insert.identifier = 'CREATE_PRIOR_TO_COMPLEMENT' + insert.insert_query = self.get_field_dict() + return insert.execute() + + def create_complement(self, idempotency_key=None, **kwargs): + insert = InsertQuery(self, idempotency_key, **kwargs) + insert.identifier = 'CREATE_COMPLEMENT' + insert.insert_query = self.get_field_dict() + return insert.execute() + class PaymentMethodMetadata(BaseModel): type = CharField(api_name='Type') @@ -1967,7 +1988,8 @@ class Meta: 'CARD_GET_TRANSACTIONS': '/cards/%(id)s/transactions', 'BANK_ACCOUNT_GET_TRANSACTIONS': '/bankaccounts/%(id)s/transactions', 'PRE_AUTHORIZATION_TRANSACTIONS': '/preauthorizations/%(id)s/transactions', - 'CLIENT_WALLET_TRANSACTIONS': '/clients/wallets/%(fund_type)s/%(currency)s/transactions' + 'CLIENT_WALLET_TRANSACTIONS': '/clients/wallets/%(fund_type)s/%(currency)s/transactions', + 'DEPOSIT_GET_TRANSACTIONS': '/deposit-preauthorizations/%(deposit_id)s/transactions/' } def __str__(self): @@ -2603,6 +2625,13 @@ def get_all_for_card(cls, card_id, *args, **kwargs): select.identifier = 'GET_ALL_FOR_CARD' return select.all(*args, **kwargs) + @classmethod + def get_transactions(cls, deposit_id, *args, **kwargs): + kwargs['deposit_id'] = deposit_id + select = SelectQuery(Transaction, *args, **kwargs) + select.identifier = 'DEPOSIT_GET_TRANSACTIONS' + return select.all(*args, **kwargs) + class VirtualAccount(BaseModel): wallet_id = CharField(api_name='WalletId', required=True) diff --git a/tests/test_deposits.py b/tests/test_deposits.py index 6a1208b..847095f 100644 --- a/tests/test_deposits.py +++ b/tests/test_deposits.py @@ -1,6 +1,8 @@ +import time import unittest -from mangopay.resources import Deposit +from mangopay.resources import Deposit, CardPreAuthorizedDepositPayIn +from mangopay.utils import Money from tests.test_base import BaseTestLive @@ -33,6 +35,24 @@ def test_get_all_for_card(self): self.assertIsInstance(result.data, list) self.assertTrue(len(result.data) > 0) + def test_get_transactions(self): + deposit = self.create_new_deposit() + + params = { + "credited_wallet_id": self.get_johns_wallet().id, + "debited_funds": Money(amount=1000, currency='EUR'), + "fees": Money(amount=0, currency='EUR'), + "deposit_id": deposit.id + } + + CardPreAuthorizedDepositPayIn(**params).create_without_complement() + + time.sleep(1) + transactions = Deposit.get_transactions(deposit.id) + self.assertIsNotNone(transactions) + self.assertIsInstance(transactions.data, list) + self.assertTrue(len(transactions.data) > 0) + @unittest.skip("can't be tested yet") def test_cancel(self): deposit = self.create_new_deposit() diff --git a/tests/test_payins.py b/tests/test_payins.py index bf5d339..c65fe0a 100644 --- a/tests/test_payins.py +++ b/tests/test_payins.py @@ -1279,6 +1279,74 @@ def test_card_preauthorized_deposit_payin(self): self.assertEqual("PREAUTHORIZED", pay_in.payment_type) self.assertEqual("PAYIN", pay_in.type) + def test_deposit_preauthorized_payin_without_complement(self): + deposit = self.create_new_deposit() + + params = { + "credited_wallet_id": self.get_johns_wallet().id, + "debited_funds": Money(amount=1000, currency='EUR'), + "fees": Money(amount=0, currency='EUR'), + "deposit_id": deposit.id + } + + created = CardPreAuthorizedDepositPayIn(**params).create_without_complement() + pay_in = CardPreAuthorizedDepositPayIn().get(created.get('id')) + + self.assertIsNotNone(pay_in) + self.assertEqual("SUCCEEDED", pay_in.status) + self.assertEqual("REGULAR", pay_in.nature) + self.assertEqual("DIRECT", pay_in.execution_type) + self.assertEqual("PREAUTHORIZED", pay_in.payment_type) + self.assertEqual("PAYIN", pay_in.type) + self.assertIsNotNone(pay_in.deposit_id) + + def test_deposit_preauthorized_payin_prior_to_complement(self): + deposit = self.create_new_deposit() + + params = { + "credited_wallet_id": self.get_johns_wallet().id, + "debited_funds": Money(amount=1000, currency='EUR'), + "fees": Money(amount=0, currency='EUR'), + "deposit_id": deposit.id + } + + created = CardPreAuthorizedDepositPayIn(**params).create_prior_to_complement() + pay_in = CardPreAuthorizedDepositPayIn().get(created.get('id')) + + self.assertIsNotNone(pay_in) + self.assertEqual("SUCCEEDED", pay_in.status) + self.assertEqual("REGULAR", pay_in.nature) + self.assertEqual("DIRECT", pay_in.execution_type) + self.assertEqual("PREAUTHORIZED", pay_in.payment_type) + self.assertEqual("PAYIN", pay_in.type) + self.assertIsNotNone(pay_in.deposit_id) + + def test_deposit_preauthorized_payin_complement(self): + deposit = self.create_new_deposit() + + dto = { + "payment_status": "NO_SHOW_REQUESTED" + } + deposit.update(deposit.get_pk(), **dto).execute() + + params = { + "credited_wallet_id": self.get_johns_wallet().id, + "debited_funds": Money(amount=1000, currency='EUR'), + "fees": Money(amount=0, currency='EUR'), + "deposit_id": deposit.id + } + + created = CardPreAuthorizedDepositPayIn(**params).create_complement() + pay_in = CardPreAuthorizedDepositPayIn().get(created.get('id')) + + self.assertIsNotNone(pay_in) + self.assertEqual("SUCCEEDED", pay_in.status) + self.assertEqual("REGULAR", pay_in.nature) + self.assertEqual("DIRECT", pay_in.execution_type) + self.assertEqual("PREAUTHORIZED", pay_in.payment_type) + self.assertEqual("PAYIN", pay_in.type) + self.assertIsNotNone(pay_in.deposit_id) + @unittest.skip("can't be tested yet") def test_card_preauthorized_deposit_payin_check_card_info(self): deposit = self.create_new_deposit()