diff --git a/addons/payment/data/payment_icon_data.xml b/addons/payment/data/payment_icon_data.xml index 44780e8b493..19df0c52c54 100644 --- a/addons/payment/data/payment_icon_data.xml +++ b/addons/payment/data/payment_icon_data.xml @@ -50,6 +50,21 @@ + + EPS + + + + + Giropay + + + + + P24 + + + Codensa Easy Credit diff --git a/addons/payment/static/img/eps.png b/addons/payment/static/img/eps.png new file mode 100644 index 00000000000..71ca1305539 Binary files /dev/null and b/addons/payment/static/img/eps.png differ diff --git a/addons/payment/static/img/giropay.png b/addons/payment/static/img/giropay.png new file mode 100644 index 00000000000..8869385fabb Binary files /dev/null and b/addons/payment/static/img/giropay.png differ diff --git a/addons/payment/static/img/p24.png b/addons/payment/static/img/p24.png new file mode 100644 index 00000000000..5ed3f7bfdfe Binary files /dev/null and b/addons/payment/static/img/p24.png differ diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py index 7e6a685c868..79123a769ff 100644 --- a/addons/payment_stripe/models/payment.py +++ b/addons/payment_stripe/models/payment.py @@ -88,8 +88,15 @@ class PaymentAcquirerStripe(models.Model): PMT('p24', ['pl'], ['eur', 'pln'], 'punctual'), ] + existing_icons = [icon.name.lower() for icon in self.env['payment.icon'].search([])] + linked_icons = [icon.name.lower() for icon in self.payment_icon_ids] + + # We don't filter out pmt in the case the icon doesn't exist at all as it would be **implicit** exclusion + icon_filtered = filter(lambda pmt: pmt.name == 'card' or + pmt.name in linked_icons or + pmt.name not in existing_icons, all_payment_method_types) country = (tx_values['billing_partner_country'].code or 'no_country').lower() - pmt_country_filtered = filter(lambda pmt: not pmt.countries or country in pmt.countries, all_payment_method_types) + pmt_country_filtered = filter(lambda pmt: not pmt.countries or country in pmt.countries, icon_filtered) currency = (tx_values.get('currency').name or 'no_currency').lower() pmt_currency_filtered = filter(lambda pmt: not pmt.currencies or currency in pmt.currencies, pmt_country_filtered) pmt_recurrence_filtered = filter(lambda pmt: tx_values.get('type') != 'form_save' or pmt.recurrence == 'recurring', diff --git a/addons/payment_stripe/tests/test_stripe.py b/addons/payment_stripe/tests/test_stripe.py index 4102fd48319..2ac2819398d 100644 --- a/addons/payment_stripe/tests/test_stripe.py +++ b/addons/payment_stripe/tests/test_stripe.py @@ -29,6 +29,13 @@ class StripeCommon(PaymentAcquirerCommon): 'partner_id': cls.buyer.id, 'verified': True, }) + cls.ideal_icon = cls.env.ref("payment.payment_icon_cc_ideal") + cls.bancontact_icon = cls.env.ref("payment.payment_icon_cc_bancontact") + cls.p24_icon = cls.env.ref("payment.payment_icon_cc_p24") + cls.eps_icon = cls.env.ref("payment.payment_icon_cc_eps") + cls.giropay_icon = cls.env.ref("payment.payment_icon_cc_giropay") + cls.all_icons = [cls.ideal_icon, cls.bancontact_icon, cls.p24_icon, cls.eps_icon, cls.giropay_icon] + cls.stripe.write({'payment_icon_ids': [(5, 0, 0)]}) @odoo.tests.tagged('post_install', '-at_install', '-standard', 'external') @@ -87,7 +94,8 @@ class StripeTest(StripeCommon): self.assertEqual(tx.state, 'done', 'Stripe: validation did not put tx into done state') self.assertEqual(tx.acquirer_reference, stripe_post_data.get('id'), 'Stripe: validation did not update tx id') - def test_add_available_payment_method_types(self): + def test_add_available_payment_method_types_local_enabled(self): + self.stripe.payment_icon_ids = [(6, 0, [i.id for i in self.all_icons])] tx_values = { 'billing_partner_country': self.env.ref('base.be'), 'currency': self.env.ref('base.EUR'), @@ -100,6 +108,61 @@ class StripeTest(StripeCommon): actual = {pmt for key, pmt in stripe_session_data.items() if key.startswith('payment_method_types')} self.assertEqual({'card', 'bancontact'}, actual) + def test_add_available_payment_method_types_local_enabled_2(self): + self.stripe.payment_icon_ids = [(6, 0, [i.id for i in self.all_icons])] + tx_values = { + 'billing_partner_country': self.env.ref('base.pl'), + 'currency': self.env.ref('base.PLN'), + 'type': 'form' + } + stripe_session_data = {} + + self.stripe._add_available_payment_method_types(stripe_session_data, tx_values) + + actual = {pmt for key, pmt in stripe_session_data.items() if key.startswith('payment_method_types')} + self.assertEqual({'card', 'p24'}, actual) + + def test_add_available_payment_method_types_pmt_does_not_exist(self): + self.bancontact_icon.unlink() + tx_values = { + 'billing_partner_country': self.env.ref('base.be'), + 'currency': self.env.ref('base.EUR'), + 'type': 'form' + } + stripe_session_data = {} + + self.stripe._add_available_payment_method_types(stripe_session_data, tx_values) + + actual = {pmt for key, pmt in stripe_session_data.items() if key.startswith('payment_method_types')} + self.assertEqual({'card', 'bancontact'}, actual) + + def test_add_available_payment_method_types_local_disabled(self): + tx_values = { + 'billing_partner_country': self.env.ref('base.be'), + 'currency': self.env.ref('base.EUR'), + 'type': 'form' + } + stripe_session_data = {} + + self.stripe._add_available_payment_method_types(stripe_session_data, tx_values) + + actual = {pmt for key, pmt in stripe_session_data.items() if key.startswith('payment_method_types')} + self.assertEqual({'card'}, actual) + + def test_add_available_payment_method_types_local_all_but_bancontact(self): + self.stripe.payment_icon_ids = [(4, icon.id) for icon in self.all_icons if icon.name.lower() != 'bancontact'] + tx_values = { + 'billing_partner_country': self.env.ref('base.be'), + 'currency': self.env.ref('base.EUR'), + 'type': 'form' + } + stripe_session_data = {} + + self.stripe._add_available_payment_method_types(stripe_session_data, tx_values) + + actual = {pmt for key, pmt in stripe_session_data.items() if key.startswith('payment_method_types')} + self.assertEqual({'card'}, actual) + def test_add_available_payment_method_types_recurrent(self): tx_values = { 'billing_partner_country': self.env.ref('base.be'), @@ -114,8 +177,7 @@ class StripeTest(StripeCommon): self.assertEqual({'card'}, actual) def test_discarded_webhook(self): - with self.assertRaises(ValidationError): - self.env['payment.acquirer']._handle_stripe_webhook(dict(type='payment.intent.succeeded')) + self.assertFalse(self.env['payment.acquirer']._handle_stripe_webhook(dict(type='payment.intent.succeeded'))) def test_handle_checkout_webhook_no_secret(self): self.stripe.stripe_webhook_secret = None