diff --git a/mangopay/constants.py b/mangopay/constants.py index 43010d5..9b48101 100644 --- a/mangopay/constants.py +++ b/mangopay/constants.py @@ -287,7 +287,8 @@ ("BANK_WIRE", "bank_wire", "Bank Wire"), ("APPLEPAY", "applepay", "Applepay"), ("GOOGLEPAY", "googlepay", "Googlepay"), - ("MBWAY", "mbway", "Mbway") + ("MBWAY", "mbway", "Mbway"), + ("MULTIBANCO", "multibanco", "Multibanco") ) CARD_STATUS_CHOICES = Choices( diff --git a/mangopay/resources.py b/mangopay/resources.py index 0478d5d..ee080d9 100644 --- a/mangopay/resources.py +++ b/mangopay/resources.py @@ -477,7 +477,8 @@ def cast(cls, result): ("BANK_WIRE", "EXTERNAL_INSTRUCTION"): BankWirePayInExternalInstruction, ("APPLEPAY", "DIRECT"): ApplepayPayIn, ("GOOGLEPAY", "DIRECT"): GooglepayPayIn, - ("MBWAY", "DIRECT"): MbwayPayIn + ("MBWAY", "DIRECT"): MbwayPayIn, + ("MULTIBANCO", "DIRECT"): MultibancoPayIn, } return types.get((payment_type, execution_type), cls) @@ -759,6 +760,23 @@ class Meta: SelectQuery.identifier: '/payins' } +class MultibancoPayIn(PayIn): + creation_date = DateTimeField(api_name='CreationDate') + author = ForeignKeyField(User, api_name='AuthorId', required=True) + debited_funds = MoneyField(api_name='DebitedFunds', required=True) + fees = MoneyField(api_name='Fees', required=True) + statement_descriptor = CharField(api_name='StatementDescriptor') + redirect_url = CharField(api_name='RedirectURL') + return_url = CharField(api_name='ReturnURL', required=True) + + class Meta: + verbose_name = 'multibanco_payin' + verbose_name_plural = 'multibanco_payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/multibanco', + SelectQuery.identifier: '/payins' + } + class CardWebPayIn(PayIn): author = ForeignKeyField(User, api_name='AuthorId', required=True) credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True) diff --git a/tests/test_payins.py b/tests/test_payins.py index d1deeb7..748165f 100644 --- a/tests/test_payins.py +++ b/tests/test_payins.py @@ -9,7 +9,7 @@ from mangopay.resources import DirectDebitDirectPayIn, Mandate, ApplepayPayIn, GooglepayPayIn, \ RecurringPayInRegistration, \ - RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn + RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn, MultibancoPayIn from mangopay.utils import (Money, ShippingAddress, Shipping, Billing, Address, SecurityInfo, ApplepayPaymentData, GooglepayPaymentData, DebitedBankAccount, BrowserInfo) @@ -1157,3 +1157,40 @@ def test_PayIns_MbwayDirect_Create(self): self.assertEqual("DIRECT", result.execution_type) self.assertEqual("MBWAY", result.payment_type) self.assertEqual("PAYIN", result.type) + + def test_PayIns_MultibancoDirect_Create(self): + user = BaseTestLive.get_john(True) + + # create wallet + credited_wallet = Wallet() + credited_wallet.owners = (user,) + credited_wallet.currency = 'EUR' + credited_wallet.description = 'WALLET IN EUR' + credited_wallet = Wallet(**credited_wallet.save()) + + pay_in = MultibancoPayIn() + pay_in.author = user + pay_in.credited_wallet = credited_wallet + pay_in.fees = Money() + pay_in.fees.amount = 100 + pay_in.fees.currency = 'EUR' + pay_in.debited_funds = Money() + pay_in.debited_funds.amount = 1000 + pay_in.debited_funds.currency = 'EUR' + pay_in.statement_descriptor = 'test' + pay_in.redirect_url = 'https://r3.girogate.de/ti/multibanco?tx=140066339483&rs=XOj6bbIqBxdIHjdDmb1o90RoCiKp8iwj&cs=162f500c5754acdebc8379df496cc6c5ababe4dbe15e3ccda1d691de5e87af26' + pay_in.return_url = 'http://www.my-site.com/returnURL?transactionId=wt_8362acb9-6dbc-4660-b826-b9acb9b850b1' + pay_in.tag = 'Multibanco tag' + + result = MultibancoPayIn(**pay_in.save()) + fetched = MultibancoPayIn().get(result.id) + + self.assertIsNotNone(result) + self.assertIsNotNone(fetched) + self.assertEqual(result.id, fetched.id) + + self.assertEqual("CREATED", result.status) + self.assertEqual("REGULAR", result.nature) + self.assertEqual("WEB", result.execution_type) + self.assertEqual("MULTIBANCO", result.payment_type) + self.assertEqual("PAYIN", result.type)