From 3b80166e6d8bfe0cfc16b681540cd6d1a4d6f6f1 Mon Sep 17 00:00:00 2001
From: Damien Bouvy <dbo@odoo.com>
Date: Mon, 27 Apr 2020 13:42:53 +0000
Subject: [PATCH] [FIX] payment_stripe: iDEAL payments

closes odoo/odoo#50546

X-original-commit: 29b3b67a168b905a72be36ef14ff428c9771a40a
Signed-off-by: Damien Bouvy (dbo) <dbo@odoo.com>
---
 addons/payment_stripe/models/payment.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py
index 81b553587dd9..63306ef83dcf 100644
--- a/addons/payment_stripe/models/payment.py
+++ b/addons/payment_stripe/models/payment.py
@@ -40,7 +40,7 @@ class PaymentAcquirerStripe(models.Model):
 
         base_url = self.get_base_url()
         stripe_session_data = {
-            'payment_method_types[]': 'card',
+            'payment_method_types[0]': 'card',
             'line_items[][amount]': int(tx_values['amount'] if tx_values['currency'].name in INT_CURRENCIES else float_round(tx_values['amount'] * 100, 2)),
             'line_items[][currency]': tx_values['currency'].name,
             'line_items[][quantity]': 1,
@@ -51,6 +51,9 @@ class PaymentAcquirerStripe(models.Model):
             'payment_intent_data[description]': tx_values['reference'],
             'customer_email': tx_values.get('partner_email') or tx_values.get('billing_partner_email'),
         }
+        if tx_values.get('billing_partner_country').code.lower() == 'nl' and tx_values.get('currency').name.lower() == 'eur':
+            # enable iDEAL for NL-based customers (€ payments only)
+            stripe_session_data['payment_method_types[1]'] = 'ideal'
         tx_values['session_id'] = self._create_stripe_session(stripe_session_data)
 
         return tx_values
@@ -104,7 +107,10 @@ class PaymentAcquirerStripe(models.Model):
 
     @api.model
     def stripe_s2s_form_process(self, data):
-        last4 = data.get('card', {}).get('last4')
+        if not data.get('card'):
+            # can't save the token if it's not a card (e.g. iDEAL)
+            return self.env['payment.token']
+        last4 = data.get('card').get('last4')
         if not last4:
             # PM was created with a setup intent, need to get last4 digits through
             # yet another call -_-
-- 
GitLab