Skip to content
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

[feature] added Swish payin #380

Merged
merged 1 commit into from
Feb 14, 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
3 changes: 2 additions & 1 deletion mangopay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
25 changes: 24 additions & 1 deletion mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
37 changes: 36 additions & 1 deletion tests/test_payins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down