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/ Ideal and Giropay integration #341

Merged
merged 2 commits into from
Nov 2, 2023
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: 32 additions & 1 deletion mangopay/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@
("MULTIBANCO", "multibanco", "Multibanco"),
("SATISPAY", "satispay", "Satispay"),
("BLIK", "blik", "Blik"),
("KLARNA", "klarna", "Klarna")
("IDEAL", "ideal", "Ideal"),
("GIROPAY", "giropay", "Giropay")
)

CARD_STATUS_CHOICES = Choices(
Expand Down Expand Up @@ -361,3 +362,33 @@
('GET_FROM_FILE', 'get_from_file', 'Get From File'),
('NO_SHIPPING', 'no_shipping', 'No Shipping')
)

BIC_CHOICES = Choices(
('RABONL2U'),
('ABNANL2A'),
('FVLBNL22'),
('TRIONL2U'),
('INGBNL2A'),
('SNSBNL2A'),
('ASNBNL21'),
('RBRBNL21'),
('KNABNL2H'),
('BUNQNL2A'),
('REVOLT21'),
('BITSNL2A')
)

BANK_NAME_CHOICES = Choices(
('Rabobank'),
('ABN AMRO'),
('Van Lanschot Baniers'),
('Triodos Bank'),
('ING Bank'),
('SNS Bank'),
('ASN'),
('RegioBank'),
('Knab'),
('Bunq'),
('Revolut'),
('Yoursafe')
)
42 changes: 41 additions & 1 deletion mangopay/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,9 @@ def cast(cls, result):
("MULTIBANCO", "WEB"): MultibancoPayIn,
("SATISPAY", "WEB"): SatispayPayIn,
("BLIK", "WEB"): BlikPayIn,
("KLARNA", "WEB"): KlarnaPayIn
("KLARNA", "WEB"): KlarnaPayIn,
("IDEAL", "WEB"): IdealPayIn,
("GIROPAY", "WEB"): GiropayPayIn,
}

return types.get((payment_type, execution_type), cls)
Expand Down Expand Up @@ -986,6 +988,44 @@ class Meta:
SelectQuery.identifier: '/payins'
}

class IdealPayIn(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)
bic = CharField(api_name='Bic', choices=constants.BIC_CHOICES, required=True)
statement_descriptor = CharField(api_name='StatementDescriptor')
creation_date = DateTimeField(api_name='CreationDate')
redirect_url = CharField(api_name='RedirectURL')
bank_name = CharField(api_name='BankName', choices=constants.BANK_NAME_CHOICES)

class Meta:
verbose_name = 'ideal_payin'
verbose_name_plural = 'ideal_payins'
url = {
InsertQuery.identifier: '/payins/payment-methods/ideal',
SelectQuery.identifier: '/payins'
}

class GiropayPayIn(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')

class Meta:
verbose_name = 'giropay_payin'
verbose_name_plural = 'giropay_payins'
url = {
InsertQuery.identifier: '/payins/payment-methods/giropay',
SelectQuery.identifier: '/payins'
}


class CardWebPayIn(PayIn):
author = ForeignKeyField(User, api_name='AuthorId', required=True)
Expand Down
76 changes: 75 additions & 1 deletion tests/test_payins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from mangopay.resources import DirectDebitDirectPayIn, Mandate, ApplepayPayIn, GooglepayPayIn, \
RecurringPayInRegistration, \
RecurringPayInCIT, PayInRefund, RecurringPayInMIT, CardPreAuthorizedDepositPayIn, MbwayPayIn, PayPalWebPayIn, \
GooglePayDirectPayIn, MultibancoPayIn, SatispayPayIn, BlikPayIn, KlarnaPayIn
GooglePayDirectPayIn, MultibancoPayIn, SatispayPayIn, BlikPayIn, KlarnaPayIn, IdealPayIn, GiropayPayIn
from mangopay.utils import (Money, ShippingAddress, Shipping, Billing, Address, SecurityInfo, ApplepayPaymentData,
GooglepayPaymentData, DebitedBankAccount, LineItem)
from tests import settings
Expand Down Expand Up @@ -1416,3 +1416,77 @@ def test_PayIns_KlarnaWeb_Create(self):
self.assertEqual("WEB", result.execution_type)
self.assertEqual("KLARNA", result.payment_type)
self.assertEqual("PAYIN", result.type)

def test_PayIns_IdealWeb_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 = IdealPayIn()
pay_in.author = user
pay_in.credited_wallet = credited_wallet
pay_in.fees = Money()
pay_in.fees.amount = 200
pay_in.fees.currency = 'EUR'
pay_in.debited_funds = Money()
pay_in.debited_funds.amount = 2000
pay_in.debited_funds.currency = 'EUR'
pay_in.statement_descriptor = 'test'
pay_in.return_url = 'https://mangopay.com/'
pay_in.bic = 'INGBNL2A'
pay_in.tag = 'Ideal PayIn'

result = IdealPayIn(**pay_in.save())
fetched = IdealPayIn().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("IDEAL", result.payment_type)
self.assertEqual("PAYIN", result.type)


def test_PayIns_GiropayWeb_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 = GiropayPayIn()
pay_in.author = user
pay_in.credited_wallet = credited_wallet
pay_in.fees = Money()
pay_in.fees.amount = 200
pay_in.fees.currency = 'EUR'
pay_in.debited_funds = Money()
pay_in.debited_funds.amount = 2000
pay_in.debited_funds.currency = 'EUR'
pay_in.statement_descriptor = 'test'
pay_in.return_url = 'https://mangopay.com/'
pay_in.tag = 'Giropay PayIn'

result = GiropayPayIn(**pay_in.save())
fetched = GiropayPayIn().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("GIROPAY", result.payment_type)
self.assertEqual("PAYIN", result.type)
Loading