Skip to content

Reference

shared.services.payment_providers.stripe.base_stripe

BaseStripe

BaseStripe(api_key, webhook_secret)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def __init__(
    self,
    api_key: str | None,
    webhook_secret: str | None,
) -> None:
    if not api_key or not webhook_secret:
        raise RuntimeError("Stripe API key or Stripe Webhook secretis not set")
    else:
        stripe.max_network_retries = 3

    self.api_key = api_key
    self.webhook_secret = webhook_secret

DETACHED_SOURCE_ERROR_MESSAGE class-attribute instance-attribute

DETACHED_SOURCE_ERROR_MESSAGE = "The reusable source you provided is consumed because it was previously charged without being attached to a customer or was detached from a customer"

FAILED_PAYMENT class-attribute instance-attribute

FAILED_PAYMENT = 'The payment failed'

IBAN_HIGH_LIKELIHOOD_OF_CHARGEBACK_MESSAGE class-attribute instance-attribute

IBAN_HIGH_LIKELIHOOD_OF_CHARGEBACK_MESSAGE = "The payment is blocked due to a high likelihood of chargeback"

IBAN_SUSPENDED_ERROR_MESSAGE class-attribute instance-attribute

IBAN_SUSPENDED_ERROR_MESSAGE = "The payment is blocked because the used IBAN has been suspended"

INVALID_IBAN_ERROR_MESSAGE class-attribute instance-attribute

INVALID_IBAN_ERROR_MESSAGE = (
    "The BIC for the provided IBAN cannot be found"
)

INVALID_MANDATE_FOR_SOURCE_ERROR_MESSAGE class-attribute instance-attribute

INVALID_MANDATE_FOR_SOURCE_ERROR_MESSAGE = "The source you provided requires a valid accepted mandate to be in a chargeable state"

LAST_API_VERSION class-attribute instance-attribute

LAST_API_VERSION = '2020-08-27'

MAX_DAYS_FOR_DEBIT_REFUND class-attribute instance-attribute

MAX_DAYS_FOR_DEBIT_REFUND = 360

MAX_STRIPE_IBAN_SUSPENSION_DAYS class-attribute instance-attribute

MAX_STRIPE_IBAN_SUSPENSION_DAYS = 90

MINIMAL_CHARGE_AMOUNT class-attribute instance-attribute

MINIMAL_CHARGE_AMOUNT = 50

NOT_CORRECTLY_ATTACHED_SOURCE_ERROR_MESSAGE class-attribute instance-attribute

NOT_CORRECTLY_ATTACHED_SOURCE_ERROR_MESSAGE = "The provided PaymentMethod was previously used with a PaymentIntent without Customer attachment, shared with a connected account without Customer attachment, or was detached from a Customer."

PROCESSED_CHARGE_EVENT_TYPES class-attribute instance-attribute

PROCESSED_CHARGE_EVENT_TYPES = {failed, refunded, succeeded}

PROCESSED_DISPUTE_EVENT_TYPES class-attribute instance-attribute

PROCESSED_DISPUTE_EVENT_TYPES = {
    created,
    funds_withdrawn,
    closed,
}

PROCESSED_PAYMENT_INTENT_EVENT_TYPES class-attribute instance-attribute

PROCESSED_PAYMENT_INTENT_EVENT_TYPES = {
    canceled,
    created,
    partially_funded,
}

SUSPENDED_SOURCE_ERROR_MESSAGES class-attribute instance-attribute

SUSPENDED_SOURCE_ERROR_MESSAGES = [
    IBAN_SUSPENDED_ERROR_MESSAGE,
    IBAN_HIGH_LIKELIHOOD_OF_CHARGEBACK_MESSAGE,
    INVALID_MANDATE_FOR_SOURCE_ERROR_MESSAGE,
    DETACHED_SOURCE_ERROR_MESSAGE,
    NOT_CORRECTLY_ATTACHED_SOURCE_ERROR_MESSAGE,
    UNEXPECTED_ERROR_MESSAGE,
    INVALID_IBAN_ERROR_MESSAGE,
    FAILED_PAYMENT,
]

UNEXPECTED_ERROR_MESSAGE class-attribute instance-attribute

UNEXPECTED_ERROR_MESSAGE = "There was an unexpected error while processing your request."

__abstract__ class-attribute instance-attribute

__abstract__ = True

api_key instance-attribute

api_key = api_key

create_stripe_customer

create_stripe_customer(customer_data)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def create_stripe_customer(
    self,
    customer_data: StripeCustomerData,
) -> stripe.Customer:
    stripe_customer = stripe.Customer.create(
        name=customer_data.name,
        description=customer_data.description,
        email=customer_data.email if customer_data.email else None,
        preferred_locales=(
            customer_data.preferred_locales
            if customer_data.preferred_locales
            else None
        ),
        metadata=(
            {"customer_type": customer_data.customer_type.value}
            if customer_data.customer_type
            else None
        ),
        api_key=self.api_key,
        expand=["sources"],
    )

    stripe_customer.save()

    return stripe_customer

on_cash_balance_funds_available abstractmethod

on_cash_balance_funds_available(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_cash_balance_funds_available(self, event: CashBalanceEvent):  # type: ignore[no-untyped-def]
    pass

on_cash_balance_transaction abstractmethod

on_cash_balance_transaction(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_cash_balance_transaction(self, event: CashBalanceTransactionEvent):  # type: ignore[no-untyped-def]
    pass

on_charge_event abstractmethod

on_charge_event(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_charge_event(self, event: ChargeEvent):  # type: ignore[no-untyped-def]
    pass

on_dispute_created abstractmethod

on_dispute_created(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_dispute_created(self, event: DisputeEvent):  # type: ignore[no-untyped-def]
    pass

on_dispute_funds_withdrawn abstractmethod

on_dispute_funds_withdrawn(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_dispute_funds_withdrawn(self, event: DisputeEvent):  # type: ignore[no-untyped-def]
    pass

on_dispute_lost abstractmethod

on_dispute_lost(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_dispute_lost(self, event: DisputeEvent):  # type: ignore[no-untyped-def]
    pass

on_intent_canceled abstractmethod

on_intent_canceled(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_intent_canceled(self, event: PaymentIntentEvent):  # type: ignore[no-untyped-def]
    pass

on_intent_created abstractmethod

on_intent_created(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_intent_created(self, event: PaymentIntentEvent):  # type: ignore[no-untyped-def]
    pass

on_intent_partially_funded abstractmethod

on_intent_partially_funded(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_intent_partially_funded(self, event: PaymentIntentPartiallyFundedEvent):  # type: ignore[no-untyped-def]
    pass

on_refund_updated abstractmethod

on_refund_updated(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_refund_updated(self, event: RefundEvent):  # type: ignore[no-untyped-def]
    pass

on_source_transaction_sepa_credit_transfer_created abstractmethod

on_source_transaction_sepa_credit_transfer_created(event)
Source code in shared/services/payment_providers/stripe/base_stripe.py
@abstractmethod
def on_source_transaction_sepa_credit_transfer_created(  # type: ignore[no-untyped-def]
    self, event: SourceTransactionEvent
):
    pass

process_webhook

process_webhook(request)

Process the data from the webhook.

Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook(self, request):  # type: ignore[no-untyped-def]
    """Process the data from the webhook."""
    self.verify_webhook(request.data, request.headers["Stripe-Signature"])  # type: ignore[no-untyped-call]
    event = request.get_json()
    # Example of an event:
    """
    {
        'id': 'evt_1QIXU8IInYkvhSGNE897LBoU',
        'object': 'event',
        'api_version': '2020-08-27',
        'created': 1730992740,
        'data': {
            'object': {
                'id': 'ccsbtxn_1QIXU8IInYkvhSGNqnTjx1Wi',
                'object': 'customer_cash_balance_transaction',
                'created': 1730992740,
                'currency': 'eur',
                'customer': 'cus_R8C9gB1qOwdKPm',
                'ending_balance': 5900,
                'funded': {
                    'bank_transfer': {
                        'eu_bank_transfer': {
                            'bic': 'COBADEFFXXX',
                            'iban_last4': '3000',
                            'sender_name': 'Test Sender'
                        },
                        'reference': 'test_reference',
                        'type': 'eu_bank_transfer'
                    }
                },
                'livemode': False,
                'net_amount': 1300,
                'type': 'funded'
            }
        },
        'livemode': False,
        'pending_webhooks': 2,
        'request': {
            'id': 'req_8kX2tqO7FlHh5i',
            'idempotency_key': '22d4ede6-868c-4c78-8686-1412ea324742'
        },
        'type': 'customer_cash_balance_transaction.created'
    }
    """
    event_id = event["id"]
    event_type = event["type"]
    data_object = event["data"]["object"]
    data_event = data_object["object"]
    object_id = data_object.get(
        "id"
    )  # can be none for some events (ex: cash balance)
    current_logger.info(
        "Received Stripe event",
        event_id=event_id,
        event_type=event_type,
        object_id=object_id,
    )

    try:
        if data_event == "charge":
            self.process_webhook_charge(
                event_type, stripe.Charge.retrieve(object_id, api_key=self.api_key)
            )
        elif data_event == "source":
            self.process_webhook_source(
                event_type, stripe.Source.retrieve(object_id, api_key=self.api_key)
            )
        elif data_event == "dispute":
            self.process_webhook_dispute(
                event_type, stripe.Dispute.retrieve(object_id, api_key=self.api_key)
            )
        elif data_event == "refund":
            self.process_webhook_refund(
                event_type, stripe.Refund.retrieve(object_id, api_key=self.api_key)
            )
        elif data_event == "source_transaction":
            self.process_webhook_source_transaction(event_type, data_object)
        elif data_event == "payment_intent":
            self.process_webhook_payment_intent(
                event_type,
                stripe.PaymentIntent.retrieve(object_id, api_key=self.api_key),
            )
        elif data_event == "cash_balance":
            customer_id = data_object["customer"]
            self.process_webhook_cash_balance(
                event_type,
                stripe.Customer.retrieve_cash_balance(
                    customer_id, api_key=self.api_key
                ),
            )
        elif data_event == "customer_cash_balance_transaction":
            self.process_webhook_cash_balance_transaction(
                event_type,
                cash_balance_transaction=data_object,
            )
    except RateLimitError as e:
        current_logger.warning(
            "Stripe webhook failed due to Stripe's rate limit",
            event_id=event_id,
            event_type=event_type,
        )
        raise e
    except StripeError:
        current_logger.exception(
            "Could not process Stripe webhook",
            event_id=event_id,
            event_type=event_type,
        )

process_webhook_cash_balance

process_webhook_cash_balance(event_type, cash_balance)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_cash_balance(
    self,
    event_type: StripeCashBalanceEventType,
    cash_balance: stripe.CashBalance,
) -> None:
    if event_type != StripeCashBalanceEventType.funds_available:
        return  # type: ignore[unreachable]

    event = CashBalanceEvent(
        customer_id=cash_balance.customer,
        available_amount=cash_balance["available"]["eur"],
    )

    self.on_cash_balance_funds_available(event=event)

process_webhook_cash_balance_transaction

process_webhook_cash_balance_transaction(
    event_type, cash_balance_transaction
)

As STRIPE documentation is not entirely clear here is an example of the cash_balance_transaction object: The object when the funds arrive look like this { 'id': 'ccsbtxn_1QIXU8IInYkvhSGNqnTjx1Wi', 'object': 'customer_cash_balance_transaction', 'created': 1730992740, 'currency': 'eur', 'customer': 'cus_R8C9gB1qOwdKPm', 'ending_balance': 5900, 'funded': { 'bank_transfer': { 'eu_bank_transfer': { 'bic': 'COBADEFFXXX', 'iban_last4': '3000', 'sender_name': 'Test Sender' }, 'reference': 'zsolt_test43', 'type': 'eu_bank_transfer' } }, 'livemode': False, 'net_amount': 1300, 'type': 'funded' } Then the payment intent is applied on the funds: { 'id': 'ccsbtxn_1QKKAmIInYkvhSGNO4ouc5pL', 'object': 'customer_cash_balance_transaction', 'applied_to_payment': { 'payment_intent': 'pi_3QKKAlIInYkvhSGN0CVK4Vlc' }, 'created': 1731418224, 'currency': 'eur', 'customer': 'cus_R8C9gB1qOwdKPm', 'ending_balance': 0, 'livemode': False, 'net_amount': -2700, 'type': 'applied_to_payment' }

Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_cash_balance_transaction(  # type: ignore[no-untyped-def]
    self,
    event_type: StripeCashBalanceTransactionEventType,
    cash_balance_transaction,
) -> None:
    """
    As STRIPE documentation is not entirely clear here is an example of the cash_balance_transaction object:
    The object when the funds arrive look like this
    {
    'id': 'ccsbtxn_1QIXU8IInYkvhSGNqnTjx1Wi',
    'object': 'customer_cash_balance_transaction',
    'created': 1730992740,
    'currency': 'eur',
    'customer': 'cus_R8C9gB1qOwdKPm',
    'ending_balance': 5900,
    'funded': {
        'bank_transfer': {
            'eu_bank_transfer': {
                'bic': 'COBADEFFXXX',
                'iban_last4': '3000',
                'sender_name': 'Test Sender'
            },
            'reference': 'zsolt_test43',
            'type': 'eu_bank_transfer'
        }
    },
    'livemode': False,
    'net_amount': 1300,
    'type': 'funded'
    }
    Then the payment intent is applied on the funds:
    {
        'id': 'ccsbtxn_1QKKAmIInYkvhSGNO4ouc5pL',
        'object': 'customer_cash_balance_transaction',
        'applied_to_payment': {
            'payment_intent': 'pi_3QKKAlIInYkvhSGN0CVK4Vlc'
        },
        'created': 1731418224,
        'currency': 'eur',
        'customer': 'cus_R8C9gB1qOwdKPm',
        'ending_balance': 0,
        'livemode': False,
        'net_amount': -2700,
        'type': 'applied_to_payment'
    }
    """

    if event_type != StripeCashBalanceTransactionEventType.transaction_created:
        return  # type: ignore[unreachable]

    CONSIDERED_TRANSACTION_TYPES = [StripeCashBalanceTransactionType.funded]

    transaction_type = cash_balance_transaction["type"]

    if transaction_type not in CONSIDERED_TRANSACTION_TYPES:
        return

    event = CashBalanceTransactionEvent(
        transaction_id=cash_balance_transaction["id"],
        customer_id=cash_balance_transaction["customer"],
        ending_balance=int(cash_balance_transaction["ending_balance"]),
        wired_amount=int(cash_balance_transaction["net_amount"]),
        wire_reference=cash_balance_transaction["funded"]["bank_transfer"].get(
            "reference"
        ),
    )

    self.on_cash_balance_transaction(event=event)

process_webhook_charge

process_webhook_charge(event_type, charge)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_charge(
    self, event_type: StripeChargeEventType, charge: stripe.Charge
) -> None:
    if event_type not in self.PROCESSED_CHARGE_EVENT_TYPES:
        return
    payment_method_type = charge.get("payment_method_details", {}).get("type", None)

    # for now we only use it for card payment
    payment_method_details = (
        PaymentMethodDetails(
            type="card",
            card=StripePaymentCard(
                last4=charge.payment_method_details.card.last4,
                exp_month=charge.payment_method_details.card.exp_month,
                exp_year=charge.payment_method_details.card.exp_year,
            ),
        )
        if payment_method_type == "card"
        else None
    )
    event = ChargeEvent(
        charge_id=charge.id,
        payment_intent_id=charge.get("payment_intent", None),
        status=charge.status,
        refunds=[],
        created=datetime.fromtimestamp(charge.created),
        outcome=charge.get("outcome", None),
        failure_code=charge.get("failure_code", None),
        payment_method=charge.get("payment_method", None),
        payment_method_details=(
            payment_method_details if payment_method_details else None
        ),
        metadata=charge.get("metadata", None),
    )
    if event_type == StripeChargeEventType.refunded:
        if "refunds" in charge:
            for refund in charge.refunds.data:
                event.refunds.append(
                    RefundData(
                        id=refund.id,
                        amount=refund.amount,
                        status=refund.status,
                        created=datetime.fromtimestamp(refund.created),
                    )
                )
        else:
            event.refunds.append(
                RefundData(
                    id=charge.id,
                    amount=charge.amount,
                    status=charge.status,
                    created=datetime.fromtimestamp(charge.created),
                )
            )

    self.on_charge_event(event)

process_webhook_dispute

process_webhook_dispute(event_type, dispute)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_dispute(
    self, event_type: StripeDisputeEventType, dispute: stripe.Dispute
) -> None:
    if event_type not in self.PROCESSED_DISPUTE_EVENT_TYPES:
        return
    event = DisputeEvent(
        charge_id=dispute.charge,
        dispute_id=dispute.id,
        status=dispute.status,
        created=datetime.fromtimestamp(dispute.created),
        amount=dispute.amount,
        reason=dispute.reason,
    )
    if event_type == StripeDisputeEventType.created:
        self.on_dispute_created(event)
    elif event_type == StripeDisputeEventType.funds_withdrawn:
        self.on_dispute_funds_withdrawn(event)
    elif event_type == StripeDisputeEventType.closed:
        if dispute.status == StripeDisputeStatus.lost:
            self.on_dispute_lost(event)
        elif dispute.status == StripeDisputeStatus.won:
            # we don't handle won disputes yet as the case is very rare (1 occurrence since the beginning)
            # in case it happens, we log an error
            current_logger.error(
                "Not handling won dispute, please investigate",
                dispute_id=dispute.id,
            )

process_webhook_payment_intent

process_webhook_payment_intent(event_type, payment_intent)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_payment_intent(
    self,
    event_type: StripePaymentIntentEventType,
    payment_intent: stripe.PaymentIntent,
) -> None:
    if event_type not in self.PROCESSED_PAYMENT_INTENT_EVENT_TYPES:
        return

    reason: str | None = None
    charges = payment_intent.get("charges", {}).get("data")
    if charges:
        last_charge = charges[0]
        reason = last_charge.get("failure_code", None) or last_charge.get(
            "outcome", {}
        ).get("reason")

    metadata = payment_intent.get("metadata", {})
    event = PaymentIntentEvent(
        payment_intent_id=payment_intent.get("id", None),
        failure_reason=reason,
        amount=payment_intent.get("amount", None),
        contract_ref=metadata.get("contract_ref"),
        contract_type=metadata.get("contract_type"),
    )

    match event_type:
        case StripePaymentIntentEventType.created:
            self.on_intent_created(event)
        case StripePaymentIntentEventType.canceled:
            self.on_intent_canceled(event)
        case StripePaymentIntentEventType.partially_funded:
            partially_funded_event = PaymentIntentPartiallyFundedEvent(
                payment_intent_id=payment_intent["id"],
                amount=payment_intent["amount"],
                amount_remaining=payment_intent["next_action"][
                    "display_bank_transfer_instructions"
                ]["amount_remaining"],
                # Metadata, not always present depending on the use case
                contract_ref=metadata.get("contract_ref"),
                contract_type=metadata.get("contract_type"),
                contract_identifier=metadata.get("contract_identifier"),
                invoice_number=metadata.get("invoice_number"),
            )
            self.on_intent_partially_funded(partially_funded_event)

process_webhook_refund

process_webhook_refund(event_type, refund)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_refund(
    self, event_type: StripeRefundEventType, refund: stripe.Refund
) -> None:
    event: RefundEvent = RefundEvent(
        refund_id=refund.id,
        status=refund.status,
    )
    if event_type == StripeRefundEventType.updated:
        self.on_refund_updated(event)

process_webhook_source

process_webhook_source(event_type, source)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_source(
    self,
    event_type: StripeSourceEventType,
    source: stripe.Source,  # noqa: ARG002
) -> None:
    current_logger.info(
        f"Received Stripe source event of type {event_type}. Ignoring."
    )

process_webhook_source_transaction

process_webhook_source_transaction(
    event_type, source_transaction
)

For info, since this isn't well documented in the Stripe docs, the source_transaction dict looks like this { 'id': 'srctxn_1Gmgj4AvZBiC5m0dFFMiXTU5', 'object': 'source_transaction', 'amount': 1000, 'created': 1590414742, 'currency': 'eur', 'livemode': False, 'sepa_credit_transfer': { 'sender_iban': 'DE89370400440532013000', 'sender_name': 'Jenny Rosen' }, 'source': 'src_1Gmgj3AvZBiC5m0dSmclLnHx', 'status': 'succeeded', 'type': 'sepa_credit_transfer' }

Source code in shared/services/payment_providers/stripe/base_stripe.py
def process_webhook_source_transaction(  # type: ignore[no-untyped-def]
    self, event_type: StripeSourceTransactionEventType, source_transaction
) -> None:
    """
    For info, since this isn't well documented in the Stripe docs, the source_transaction dict looks like this
    {
        'id': 'srctxn_1Gmgj4AvZBiC5m0dFFMiXTU5',
        'object': 'source_transaction',
        'amount': 1000,
        'created': 1590414742,
        'currency': 'eur',
        'livemode': False,
        'sepa_credit_transfer': {
            'sender_iban': 'DE89370400440532013000',
            'sender_name': 'Jenny Rosen'
        },
        'source': 'src_1Gmgj3AvZBiC5m0dSmclLnHx',
        'status': 'succeeded',
        'type': 'sepa_credit_transfer'
    }
    """
    if (
        event_type == StripeSourceTransactionEventType.created
        and source_transaction["type"] == "sepa_credit_transfer"
    ):
        event = SourceTransactionEvent(
            source_id=source_transaction["source"],
            amount=source_transaction["amount"],
        )
        self.on_source_transaction_sepa_credit_transfer_created(event)

update_stripe_customer

update_stripe_customer(customer_id, customer_data)
Source code in shared/services/payment_providers/stripe/base_stripe.py
def update_stripe_customer(
    self,
    customer_id: str,
    customer_data: StripeCustomerData,
) -> stripe.Customer:
    stripe_customer = stripe.Customer.retrieve(
        customer_id,
        api_key=self.api_key,
        expand=["sources"],
    )

    stripe_customer.update(
        dict(
            name=customer_data.name,
            description=customer_data.description,
            metadata=(
                {"customer_type": customer_data.customer_type.value}
                if customer_data.customer_type
                else None
            ),
            address=(
                {"country": customer_data.address.country}
                if customer_data.address
                else None
            ),
        )
    )
    stripe_customer.save()
    return stripe_customer

verify_webhook

verify_webhook(payload, signature)

Verify if the connection made via the webhook is valid.

Throws ValueError if payload is invalid and SignatureVerificationError if webhook signature is invalid.

Source code in shared/services/payment_providers/stripe/base_stripe.py
def verify_webhook(self, payload, signature):  # type: ignore[no-untyped-def]
    """Verify if the connection made via the webhook is valid.

    Throws ValueError if payload is invalid and
    SignatureVerificationError if webhook signature is invalid.
    """
    import stripe

    if not self.webhook_secret:
        raise RuntimeError("Stripe webhook secret environment variable is not set.")

    stripe.Webhook.construct_event(payload, signature, self.webhook_secret)

webhook_secret instance-attribute

webhook_secret = webhook_secret

shared.services.payment_providers.stripe.entities

CashBalanceEvent dataclass

CashBalanceEvent(customer_id, available_amount)

available_amount instance-attribute

available_amount

customer_id instance-attribute

customer_id

CashBalanceTransactionEvent dataclass

CashBalanceTransactionEvent(
    transaction_id,
    customer_id,
    ending_balance,
    wired_amount,
    wire_reference=None,
)

customer_id instance-attribute

customer_id

ending_balance instance-attribute

ending_balance

transaction_id instance-attribute

transaction_id

wire_reference class-attribute instance-attribute

wire_reference = None

wired_amount instance-attribute

wired_amount

ChargeEvent dataclass

ChargeEvent(
    charge_id,
    payment_intent_id,
    status,
    refunds,
    created,
    outcome=None,
    failure_code=None,
    payment_method=None,
    payment_method_details=None,
    metadata=None,
)

charge_id instance-attribute

charge_id

created instance-attribute

created

failure_code class-attribute instance-attribute

failure_code = None

metadata class-attribute instance-attribute

metadata = None

outcome class-attribute instance-attribute

outcome = None

payment_intent_id instance-attribute

payment_intent_id

payment_method class-attribute instance-attribute

payment_method = None

payment_method_details class-attribute instance-attribute

payment_method_details = None

refunds instance-attribute

refunds

status instance-attribute

status

DisputeEvent dataclass

DisputeEvent(
    charge_id, dispute_id, status, created, amount, reason
)

amount instance-attribute

amount

charge_id instance-attribute

charge_id

created instance-attribute

created

dispute_id instance-attribute

dispute_id

reason instance-attribute

reason

status instance-attribute

status

OutcomeEvent dataclass

OutcomeEvent(reason=None)

reason class-attribute instance-attribute

reason = None

PaymentIntentEvent dataclass

PaymentIntentEvent(
    payment_intent_id,
    failure_reason,
    amount,
    contract_ref,
    contract_type,
)

amount instance-attribute

amount

contract_ref instance-attribute

contract_ref

contract_type instance-attribute

contract_type

failure_reason instance-attribute

failure_reason

payment_intent_id instance-attribute

payment_intent_id

PaymentIntentPartiallyFundedEvent dataclass

PaymentIntentPartiallyFundedEvent(
    payment_intent_id,
    amount,
    contract_ref,
    contract_type,
    contract_identifier,
    invoice_number,
    amount_remaining,
)

amount instance-attribute

amount

amount_remaining instance-attribute

amount_remaining

contract_identifier instance-attribute

contract_identifier

contract_ref instance-attribute

contract_ref

contract_type instance-attribute

contract_type

invoice_number instance-attribute

invoice_number

payment_intent_id instance-attribute

payment_intent_id

PaymentMethodDetails dataclass

PaymentMethodDetails(type, card)

card instance-attribute

card

type instance-attribute

type

RefundData dataclass

RefundData(id, amount, status, created)

amount instance-attribute

amount

created instance-attribute

created

id instance-attribute

id

status instance-attribute

status

RefundEvent dataclass

RefundEvent(refund_id, status)

refund_id instance-attribute

refund_id

status instance-attribute

status

SourceTransactionEvent dataclass

SourceTransactionEvent(source_id, amount)

amount instance-attribute

amount

source_id instance-attribute

source_id

StripeCashBalanceEventType

Bases: AlanBaseEnum

funds_available class-attribute instance-attribute

funds_available = 'cash_balance.funds_available'

StripeCashBalanceTransactionEventType

Bases: AlanBaseEnum

transaction_created class-attribute instance-attribute

transaction_created = (
    "customer_cash_balance_transaction.created"
)

StripeCashBalanceTransactionType

Bases: AlanBaseEnum

funded class-attribute instance-attribute

funded = 'funded'

StripeChargeEventType

Bases: AlanBaseEnum

captured class-attribute instance-attribute

captured = 'charge.captured'

expired class-attribute instance-attribute

expired = 'charge.expired'

failed class-attribute instance-attribute

failed = 'charge.failed'

pending class-attribute instance-attribute

pending = 'charge.pending'

refunded class-attribute instance-attribute

refunded = 'charge.refunded'

succeeded class-attribute instance-attribute

succeeded = 'charge.succeeded'

updated class-attribute instance-attribute

updated = 'charge.updated'

StripeCheckoutMode

Bases: AlanBaseEnum

payment class-attribute instance-attribute

payment = 'payment'

setup class-attribute instance-attribute

setup = 'setup'

StripeCustomerAddressData dataclass

StripeCustomerAddressData(country)

country instance-attribute

country

StripeCustomerData dataclass

StripeCustomerData(
    name,
    description,
    customer_type,
    email=None,
    preferred_locales=None,
    address=None,
)

address class-attribute instance-attribute

address = None

customer_type instance-attribute

customer_type

description instance-attribute

description

email class-attribute instance-attribute

email = None

name instance-attribute

name

preferred_locales class-attribute instance-attribute

preferred_locales = None

StripeDisputeEventType

Bases: AlanBaseEnum

closed class-attribute instance-attribute

closed = 'charge.dispute.closed'

created class-attribute instance-attribute

created = 'charge.dispute.created'

funds_reinstated class-attribute instance-attribute

funds_reinstated = 'charge.dispute.funds_reinstated'

funds_withdrawn class-attribute instance-attribute

funds_withdrawn = 'charge.dispute.funds_withdrawn'

updated class-attribute instance-attribute

updated = 'charge.dispute.updated'

StripeDisputeStatus

Bases: AlanBaseEnum

charge_refunded class-attribute instance-attribute

charge_refunded = 'charge_refunded'

lost class-attribute instance-attribute

lost = 'lost'

needs_response class-attribute instance-attribute

needs_response = 'needs_response'

under_review class-attribute instance-attribute

under_review = 'under_review'

warning_closed class-attribute instance-attribute

warning_closed = 'warning_closed'

warning_needs_response class-attribute instance-attribute

warning_needs_response = 'warning_needs_response'

warning_under_review class-attribute instance-attribute

warning_under_review = 'warning_under_review'

won class-attribute instance-attribute

won = 'won'

StripeIBANData dataclass

StripeIBANData(owner, iban, sepa_unique_id)

iban instance-attribute

iban

owner instance-attribute

owner

sepa_unique_id instance-attribute

sepa_unique_id

StripeIBANOwner dataclass

StripeIBANOwner(name, type, address=None)

address class-attribute instance-attribute

address = None

name instance-attribute

name

type instance-attribute

type

StripeIBANOwnerAddress dataclass

StripeIBANOwnerAddress(
    city=None,
    country=None,
    line1=None,
    line2=None,
    postal_code=None,
    state=None,
)

city class-attribute instance-attribute

city = None

country class-attribute instance-attribute

country = None

line1 class-attribute instance-attribute

line1 = None

line2 class-attribute instance-attribute

line2 = None

postal_code class-attribute instance-attribute

postal_code = None

state class-attribute instance-attribute

state = None

StripePaymentCard dataclass

StripePaymentCard(last4, exp_month, exp_year)

exp_month instance-attribute

exp_month

exp_year instance-attribute

exp_year

last4 instance-attribute

last4

StripePaymentIntentEventType

Bases: AlanBaseEnum

amount_capturable_updated class-attribute instance-attribute

amount_capturable_updated = (
    "payment_intent.amount_capturable_updated"
)

canceled class-attribute instance-attribute

canceled = 'payment_intent.canceled'

created class-attribute instance-attribute

created = 'payment_intent.created'

partially_funded class-attribute instance-attribute

partially_funded = 'payment_intent.partially_funded'

processing class-attribute instance-attribute

processing = 'payment_intent.processing'

requires_action class-attribute instance-attribute

requires_action = 'payment_intent.requires_action'

succeeded class-attribute instance-attribute

succeeded = 'payment_intent.succeeded'

StripeRefundEventType

Bases: AlanBaseEnum

updated class-attribute instance-attribute

updated = 'charge.refund.updated'

StripeSEPACreditTransferSourceData dataclass

StripeSEPACreditTransferSourceData(name, contract_id)

contract_id instance-attribute

contract_id

name instance-attribute

name

StripeSourceEventType

Bases: AlanBaseEnum

canceled class-attribute instance-attribute

canceled = 'source.canceled'

chargeable class-attribute instance-attribute

chargeable = 'source.chargeable'

failed class-attribute instance-attribute

failed = 'source.failed'

mandate_notification class-attribute instance-attribute

mandate_notification = 'source.mandate_notification'

refund_attributes_required class-attribute instance-attribute

refund_attributes_required = (
    "source.refund_attributes_required"
)

StripeSourceTransactionEventType

Bases: AlanBaseEnum

created class-attribute instance-attribute

created = 'source.transaction.created'

updated class-attribute instance-attribute

updated = 'source.transaction.updated'

shared.services.payment_providers.stripe.helpers

STRIPE_DASHBOARD_URL module-attribute

STRIPE_DASHBOARD_URL = 'https://dashboard.stripe.com'

build_stripe_customer_dashboard_url

build_stripe_customer_dashboard_url(customer_id)
Source code in shared/services/payment_providers/stripe/helpers.py
def build_stripe_customer_dashboard_url(customer_id: str) -> str:
    return (
        f"{STRIPE_DASHBOARD_URL}/customers/{customer_id}"
        if is_production_mode()
        else f"{STRIPE_DASHBOARD_URL}/test/customers/{customer_id}"
    )

build_stripe_payment_dashboard_url

build_stripe_payment_dashboard_url(payment_id)
Source code in shared/services/payment_providers/stripe/helpers.py
def build_stripe_payment_dashboard_url(payment_id: str) -> str:
    return (
        f"{STRIPE_DASHBOARD_URL}/payments/{payment_id}"
        if is_production_mode()
        else f"{STRIPE_DASHBOARD_URL}/test/payments/{payment_id}"
    )