Skip to content

Commit

Permalink
Integrated Multibanco
Browse files Browse the repository at this point in the history
  • Loading branch information
Silviana Ghita committed Sep 4, 2023
1 parent d700b5e commit ed4578e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
3 changes: 2 additions & 1 deletion mangopay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
20 changes: 19 additions & 1 deletion mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 38 additions & 1 deletion tests/test_payins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

0 comments on commit ed4578e

Please sign in to comment.