Beispiel #1
0
    def _process_flexcheckout_data(self, data):
        """ Create a token from Flexcheckout feedback data.

        :param dict data: The feedback data from Flexcheckout
        :return: None
        """
        token_name = data.get('CARDNUMBER') \
                     or payment_utils.build_token_name()  # CARD.CARNUMBER not requested in backend
        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            token_name,  # Already padded with 'X's
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            data['ALIASID'],
            'verified':
            False,  # No payment has been processed through this token yet
            'active':
            self.
            tokenize,  # Immediately archive the token if it was not requested
        })
        self.write({
            'token_id': token.id,
            'tokenize': False,
        })
Beispiel #2
0
    def _ogone_tokenize_from_feedback_data(self, card_number, acquirer_ref,
                                           is_one_shot_payment):
        """ Create a token from feedback data.

        :param str card_number: The obfuscated number of the card
        :param str acquirer_ref: The acquirer reference of the payment
        :param bool is_one_shot_payment: Whether the token was created for a one-shot payment
        :return: None
        """
        token_name = card_number or payment_utils.build_token_name(
        )  # Not requested in the backend
        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            token_name,  # Already padded with 'X's
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            acquirer_ref,
            'verified':
            False,  # Set to True as soon as a payment is authorized
            'active':
            not is_one_shot_payment,  # Archive immediately if used for one-shot payment
        })
        self.write({
            'token_id': token.id,
            'tokenize': False,
        })
Beispiel #3
0
    def _ogone_tokenize_from_feedback_data(self, data):
        """ Create a token from feedback data.

        :param dict data: The feedback data sent by the provider
        :return: None
        """
        token_name = data.get('CARDNO') or payment_utils.build_token_name()
        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            token_name,  # Already padded with 'X's
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            data['ALIAS'],
            'verified':
            True,  # The payment is authorized, so the payment method is valid
        })
        self.write({
            'token_id': token.id,
            'tokenize': False,
        })
        _logger.info("created token with id %s for partner with id %s",
                     token.id, self.partner_id.id)
Beispiel #4
0
    def _process_feedback_data(self, data):
        """ Override of payment to process the transaction based on dummy data.

        Note: self.ensure_one()

        :param dict data: The dummy feedback data
        :return: None
        :raise: ValidationError if inconsistent data were received
        """
        super()._process_feedback_data(data)
        if self.provider != "test":
            return

        self._set_done()  # Dummy transactions are always successful
        if self.tokenize:
            token = self.env['payment.token'].create({
                'acquirer_id':
                self.acquirer_id.id,
                'name':
                payment_utils.build_token_name(
                    payment_details_short=data['cc_summary']),
                'partner_id':
                self.partner_id.id,
                'acquirer_ref':
                'fake acquirer reference',
                'verified':
                True,
            })
            self.token_id = token.id
Beispiel #5
0
    def _adyen_tokenize_from_feedback_data(self, data):
        """ Create a new token based on the feedback data.

        Note: self.ensure_one()

        :param dict data: The feedback data sent by the provider
        :return: None
        """
        self.ensure_one()

        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            payment_utils.build_token_name(
                data['additionalData'].get('cardSummary')),
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            data['additionalData']['recurring.recurringDetailReference'],
            'adyen_shopper_reference':
            data['additionalData']['recurring.shopperReference'],
            'verified':
            True,  # The payment is authorized, so the payment method is valid
        })
        self.write({
            'token_id': token,
            'tokenize': False,
        })
        _logger.info("created token with id %s for partner with id %s",
                     token.id, self.partner_id.id)
Beispiel #6
0
    def _ogone_tokenize_from_notification_data(self, notification_data):
        """ Create a token from notification data.

        :param dict notification_data: The notification data sent by the provider
        :return: None
        """
        token_name = notification_data.get(
            'CARDNO') or payment_utils.build_token_name()
        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            token_name,  # Already padded with 'X's
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            notification_data['ALIAS'],
            'verified':
            True,  # The payment is authorized, so the payment method is valid
        })
        self.write({
            'token_id': token.id,
            'tokenize': False,
        })
        _logger.info(
            "created token with id %(token_id)s for partner with id %(partner_id)s from "
            "transaction with reference %(ref)s",
            {
                'token_id': token.id,
                'partner_id': self.partner_id.id,
                'ref': self.reference,
            },
        )
Beispiel #7
0
    def _stripe_tokenize_from_notification_data(self, notification_data):
        """ Create a new token based on the notification data.

        :param dict notification_data: The notification data built with Stripe objects.
                                       See `_process_notification_data`.
        :return: None
        """
        if self.operation == 'online_redirect':
            payment_method_id = notification_data.get('charge',
                                                      {}).get('payment_method')
            customer_id = notification_data.get('charge', {}).get('customer')
        else:  # 'validation'
            payment_method_id = notification_data.get('payment_method',
                                                      {}).get('id')
            customer_id = notification_data.get('setup_intent',
                                                {}).get('customer')
        payment_method = notification_data.get('payment_method')
        if not payment_method_id or not payment_method:
            _logger.warning(
                "requested tokenization from notification data with missing payment method"
            )
            return

        if payment_method.get('type') != 'card':
            # Only 'card' payment methods can be tokenized. This case should normally not happen as
            # non-recurring payment methods are not shown to the customer if the "Save my payment
            # details checkbox" is shown. Still, better be on the safe side..
            _logger.warning(
                "requested tokenization of non-recurring payment method")
            return

        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            payment_utils.build_token_name(
                payment_method['card'].get('last4')),
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            customer_id,
            'verified':
            True,
            'stripe_payment_method':
            payment_method_id,
        })
        self.write({
            'token_id': token,
            'tokenize': False,
        })
        _logger.info(
            "created token with id %(token_id)s for partner with id %(partner_id)s from "
            "transaction with reference %(ref)s",
            {
                'token_id': token.id,
                'partner_id': self.partner_id.id,
                'ref': self.reference,
            },
        )
    def _odoo_tokenize_from_feedback_data(self, data):
        """ Create a new token based on the feedback data.

        Note: self.ensure_one()

        :param dict data: The feedback data sent by the provider
        :return: None
        """
        self.ensure_one()

        # Retrieve all stored payment methods for the customer from the API and match them with the
        # acquirer reference of the transaction to find its payment method
        response_content = self.acquirer_id.odoo_adyen_account_id._adyen_rpc(
            'payment_methods',
            dict(shopperReference=data['additionalData']
                 ['recurring.shopperReference']),
        )
        payment_methods = response_content['storedPaymentMethods']
        acquirer_ref = data['additionalData'][
            'recurring.recurringDetailReference']
        payment_method_type = next(pm['type'] for pm in payment_methods
                                   if pm['id'] == acquirer_ref)

        # Create the token
        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            payment_utils.build_token_name(
                data['additionalData'].get('cardSummary')),
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            acquirer_ref,
            'verified':
            True,  # The payment is authorized, so the payment method is valid
            'odoo_payment_method_type':
            payment_method_type,
        })
        self.write({
            'token_id': token,
            'tokenize': False,
        })
        _logger.info("created token with id %s for partner with id %s",
                     token.id, self.partner_id.id)
Beispiel #9
0
    def _flutterwave_tokenize_from_notification_data(self, notification_data):
        """ Create a new token based on the notification data.

        Note: self.ensure_one()

        :param dict notification_data: The notification data sent by the provider.
        :return: None
        """
        self.ensure_one()

        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            payment_utils.build_token_name(
                notification_data['card']['last_4digits']),
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            notification_data['card']['token'],
            'flutterwave_customer_email':
            notification_data['customer']['email'],
            'verified':
            True,  # The payment is confirmed, so the payment method is valid.
        })
        self.write({
            'token_id': token,
            'tokenize': False,
        })
        _logger.info(
            "created token with id %(token_id)s for partner with id %(partner_id)s from "
            "transaction with reference %(ref)s",
            {
                'token_id': token.id,
                'partner_id': self.partner_id.id,
                'ref': self.reference,
            },
        )
Beispiel #10
0
    def _adyen_tokenize_from_notification_data(self, notification_data):
        """ Create a new token based on the notification data.

        Note: self.ensure_one()

        :param dict notification_data: The notification data sent by the provider
        :return: None
        """
        self.ensure_one()

        additional_data = notification_data['additionalData']
        token = self.env['payment.token'].create({
            'acquirer_id':
            self.acquirer_id.id,
            'name':
            payment_utils.build_token_name(additional_data.get('cardSummary')),
            'partner_id':
            self.partner_id.id,
            'acquirer_ref':
            additional_data['recurring.recurringDetailReference'],
            'adyen_shopper_reference':
            additional_data['recurring.shopperReference'],
            'verified':
            True,  # The payment is authorized, so the payment method is valid
        })
        self.write({
            'token_id': token,
            'tokenize': False,
        })
        _logger.info(
            "created token with id %(token_id)s for partner with id %(partner_id)s from "
            "transaction with reference %(ref)s",
            {
                'token_id': token.id,
                'partner_id': self.partner_id.id,
                'ref': self.reference,
            },
        )