(
        cls,
        payment_method: Union[str, "PaymentMethod"],
        customer: Union[str, Customer],
        api_key: str = djstripe_settings.STRIPE_SECRET_KEY,
    )
return cls.sync_from_stripe_data(stripe_payment_method)
Attach a payment method to a customer
Attach a payment method to a customer
Attach a payment method to a customer
def attach(
        cls,
        payment_method: Union[str, "PaymentMethod"],
        customer: Union[str, Customer],
        api_key: str = djstripe_settings.STRIPE_SECRET_KEY,
    ) -> "PaymentMethod":
        """
        Attach a payment method to a customer
        """

        if isinstance(payment_method, StripeModel):
            payment_method = payment_method.id

        if isinstance(customer, StripeModel):
            customer = customer.id

        extra_kwargs = {}
        if not isinstance(payment_method, stripe.PaymentMethod):
            # send api_key if we're not passing in a Stripe object
            # avoids "Received unknown parameter: api_key" since api uses the
            # key cached in the Stripe object
            extra_kwargs = {"api_key": api_key}

        stripe_payment_method = stripe.PaymentMethod.attach(
            payment_method, customer=customer, **extra_kwargs
        )
        return cls.sync_from_stripe_data(stripe_payment_method)
def attach ( cls , payment_method : Union [ str , "PaymentMethod" ] , customer : Union [ str , Customer ] , api_key : str = djstripe_settings . STRIPE_SECRET_KEY , ) -> "PaymentMethod" : if isinstance ( payment_method , StripeModel ) : payment_method = payment_method . id if isinstance ( customer , StripeModel ) : customer = customer . id extra_kwargs = { } if not isinstance ( payment_method , stripe . PaymentMethod ) : # send api_key if we're not passing in a Stripe object # avoids "Received unknown parameter: api_key" since api uses the # key cached in the Stripe object extra_kwargs = { "api_key" : api_key } stripe_payment_method = stripe . PaymentMethod . attach ( payment_method , customer = customer , * * extra_kwargs ) return cls . sync_from_stripe_data ( stripe_payment_method )