Esempio n. 1
0
    def _send_payment_request(self):
        """ Override of payment to send a payment request to Stripe with a confirmed PaymentIntent.

        Note: self.ensure_one()

        :return: None
        :raise: UserError if the transaction is not linked to a token
        """
        super()._send_payment_request()
        if self.provider != 'stripe':
            return

        if not self.token_id:
            raise UserError("Stripe: " +
                            _("The transaction is not linked to a token."))

        # Make the payment request to Stripe
        payment_intent = self._stripe_create_payment_intent()
        _logger.info(
            "payment request response for transaction with reference %s:\n%s",
            self.reference, pprint.pformat(payment_intent))
        self.stripe_payment_intent = payment_intent['id']

        # Handle the payment request response
        notification_data = {'reference': self.reference}
        StripeController._include_payment_intent_in_notification_data(
            payment_intent, notification_data)
        self._handle_notification_data('stripe', notification_data)
Esempio n. 2
0
    def _send_refund_request(self,
                             amount_to_refund=None,
                             create_refund_transaction=True):
        """ Override of payment to send a refund request to Stripe.

        Note: self.ensure_one()

        :param float amount_to_refund: The amount to refund.
        :param bool create_refund_transaction: Whether a refund transaction should be created or
                                               not.
        :return: The refund transaction, if any.
        :rtype: recordset of `payment.transaction`
        """
        if self.provider != 'stripe':
            return super()._send_refund_request(
                amount_to_refund=amount_to_refund,
                create_refund_transaction=create_refund_transaction,
            )
        refund_tx = super()._send_refund_request(
            amount_to_refund=amount_to_refund, create_refund_transaction=True)

        # Make the refund request to stripe.
        data = self.acquirer_id._stripe_make_request(
            'refunds',
            payload={
                'charge':
                self.acquirer_reference,
                'amount':
                payment_utils.to_minor_currency_units(
                    -refund_tx.
                    amount,  # Refund transactions' amount is negative, inverse it.
                    refund_tx.currency_id,
                ),
            })
        _logger.info(
            "Refund request response for transaction wih reference %s:\n%s",
            self.reference, pprint.pformat(data))
        # Handle the refund request response.
        notification_data = {}
        StripeController._include_refund_in_notification_data(
            data, notification_data)
        refund_tx._handle_notification_data('stripe', notification_data)

        return refund_tx
Esempio n. 3
0
    def _send_payment_request(self):
        """ Override of payment to send a payment request to Stripe with a confirmed PaymentIntent.

        Note: self.ensure_one()

        :return: None
        :raise: UserError if the transaction is not linked to a token
        """
        super()._send_payment_request()
        if self.provider != 'stripe':
            return

        # Make the payment request to Stripe
        if not self.token_id:
            raise UserError("Stripe: " + _("The transaction is not linked to a token."))

        payment_intent = self._stripe_create_payment_intent()
        feedback_data = {'reference': self.reference}
        StripeController._include_payment_intent_in_feedback_data(payment_intent, feedback_data)
        _logger.info("entering _handle_feedback_data with data:\n%s", pprint.pformat(feedback_data))
        self._handle_feedback_data('stripe', feedback_data)
Esempio n. 4
0
    def _send_void_request(self):
        """ Override of payment to send a void request to Stripe.

        Note: self.ensure_one()

        :return: None
        """
        super()._send_void_request()
        if self.provider != 'stripe':
            return

        # Make the void request to Stripe
        payment_intent = self.acquirer_id._stripe_make_request(
            f'payment_intents/{self.stripe_payment_intent}/cancel')
        _logger.info(
            "void request response for transaction with reference %s:\n%s",
            self.reference, pprint.pformat(payment_intent))

        # Handle the void request response
        notification_data = {'reference': self.reference}
        StripeController._include_payment_intent_in_notification_data(
            payment_intent, notification_data)
        self._handle_notification_data('stripe', notification_data)