Skip to content

[feature] handle creation of deposit preauthorized payins #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 21 additions & 1 deletion tests/test_deposits.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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()
Expand Down
68 changes: 68 additions & 0 deletions tests/test_payins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading