From a9711e153e45647f408626731138860c32dd54a2 Mon Sep 17 00:00:00 2001 From: Iulian Masar Date: Tue, 11 Feb 2025 10:54:45 +0200 Subject: [PATCH] added Swish payin --- mangopay/constants.py | 3 ++- mangopay/resources.py | 25 ++++++++++++++++++++++++- tests/test_payins.py | 37 ++++++++++++++++++++++++++++++++++++- 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/mangopay/constants.py b/mangopay/constants.py index 591242e..d8587dd 100644 --- a/mangopay/constants.py +++ b/mangopay/constants.py @@ -310,7 +310,8 @@ ("BLIK", "blik", "Blik"), ("IDEAL", "ideal", "Ideal"), ("GIROPAY", "giropay", "Giropay"), - ("BCMC", "bancontact", "Bancontact") + ("BCMC", "bancontact", "Bancontact"), + ("SWISH", "swish", "Swish") ) CARD_STATUS_CHOICES = Choices( diff --git a/mangopay/resources.py b/mangopay/resources.py index 64a433d..c8d7194 100644 --- a/mangopay/resources.py +++ b/mangopay/resources.py @@ -660,7 +660,8 @@ def cast(cls, result): ("KLARNA", "WEB"): KlarnaPayIn, ("IDEAL", "WEB"): IdealPayIn, ("GIROPAY", "WEB"): GiropayPayIn, - ("BANCONTACT", "WEB"): BancontactPayIn + ("BANCONTACT", "WEB"): BancontactPayIn, + ("SWISH", "WEB"): SwishPayIn, } return types.get((payment_type, execution_type), cls) @@ -1148,6 +1149,28 @@ class Meta: } +class SwishPayIn(PayIn): + author = ForeignKeyField(User, api_name='AuthorId', required=True) + credited_wallet = ForeignKeyField(Wallet, api_name='CreditedWalletId', required=True) + debited_funds = MoneyField(api_name='DebitedFunds', required=True) + fees = MoneyField(api_name='Fees', required=True) + return_url = CharField(api_name='ReturnURL', required=True) + statement_descriptor = CharField(api_name='StatementDescriptor') + creation_date = DateTimeField(api_name='CreationDate') + redirect_url = CharField(api_name='RedirectURL') + deep_link_url = CharField(api_name='DeepLinkURL') + qr_code_url = CharField(api_name='QRCodeURL') + payment_flow = CharField(api_name='PaymentFlow') + + class Meta: + verbose_name = 'swish_payin' + verbose_name_plural = 'swish_payins' + url = { + InsertQuery.identifier: '/payins/payment-methods/swish', + SelectQuery.identifier: '/payins' + } + + class BancontactPayIn(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 3013335..330da17 100644 --- a/tests/test_payins.py +++ b/tests/test_payins.py @@ -8,7 +8,7 @@ RecurringPayInRegistration, \ RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn, PayPalWebPayIn, \ GooglePayDirectPayIn, MultibancoPayIn, SatispayPayIn, BlikPayIn, KlarnaPayIn, IdealPayIn, GiropayPayIn, \ - CardRegistration, BancontactPayIn + CardRegistration, BancontactPayIn, SwishPayIn from mangopay.utils import (Money, ShippingAddress, Shipping, Billing, Address, SecurityInfo, ApplepayPaymentData, GooglepayPaymentData, DebitedBankAccount, LineItem, CardInfo) from tests import settings @@ -1556,6 +1556,41 @@ def test_PayIns_GiropayWeb_Create(self): self.assertEqual("GIROPAY", result.payment_type) self.assertEqual("PAYIN", result.type) + def test_PayIns_SwishWeb_Create(self): + user = BaseTestLive.get_john(True) + + # create wallet + credited_wallet = Wallet() + credited_wallet.owners = (user,) + credited_wallet.currency = 'SEK' + credited_wallet.description = 'WALLET IN SEK' + credited_wallet = Wallet(**credited_wallet.save()) + + pay_in = SwishPayIn() + pay_in.author = user + pay_in.credited_wallet = credited_wallet + pay_in.fees = Money() + pay_in.fees.amount = 0 + pay_in.fees.currency = 'SEK' + pay_in.debited_funds = Money() + pay_in.debited_funds.amount = 100 + pay_in.debited_funds.currency = 'SEK' + pay_in.return_url = 'https://mangopay.com/' + pay_in.tag = 'Swish PayIn' + + result = SwishPayIn(**pay_in.save()) + fetched = SwishPayIn().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("SWISH", result.payment_type) + self.assertEqual("PAYIN", result.type) + def test_PayIns_BancontactWeb_Create(self): user = BaseTestLive.get_john(True)