How to use the localstripe.resources.PaymentMethod function in localstripe

To help you get started, we’ve selected a few localstripe examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adrienverge / localstripe / localstripe / resources.py View on Github external
date=self.current_period_start)
        invoice._finalize()
        if invoice.status != 'paid':  # 0 € invoices are already 'paid'
            Invoice._api_pay_invoice(invoice.id)

        if invoice.status == 'paid':
            self.status = 'active'
        elif invoice.charge:
            if invoice.charge.status == 'failed':
                if self.status != 'incomplete':
                    self._on_recurring_payment_failure(invoice)
            # If source is SEPA, subscription starts `active` (even with
            # `enable_incomplete_payments`), then is canceled later if the
            # payment fails:
            if (invoice.charge.status == 'pending' and
                    PaymentMethod._api_retrieve(
                        invoice.charge.payment_method).type == 'sepa_debit'):
                self.status = 'active'
github adrienverge / localstripe / localstripe / resources.py View on Github external
def _api_list_all(cls, url, customer=None, type=None, limit=None):
        try:
            assert _type(customer) is str and customer.startswith('cus_')
            assert type in ('card', )
        except AssertionError:
            raise UserError(400, 'Bad request')

        Customer._api_retrieve(customer)  # to return 404 if not existant

        li = super(PaymentMethod, cls)._api_list_all(url, limit=limit)
        li._list = [pm for pm in li._list
                    if pm.customer == customer and pm.type == type]
        return li
github adrienverge / localstripe / localstripe / resources.py View on Github external
assert _type(customer) is str and customer.startswith('cus_')
            assert type in ('card', )
        except AssertionError:
            raise UserError(400, 'Bad request')

        Customer._api_retrieve(customer)  # to return 404 if not existant

        li = super(PaymentMethod, cls)._api_list_all(url, limit=limit)
        li._list = [pm for pm in li._list
                    if pm.customer == customer and pm.type == type]
        return li


extra_apis.extend((
    ('POST', '/v1/payment_methods/{id}/attach', PaymentMethod._api_attach),
    ('POST', '/v1/payment_methods/{id}/detach', PaymentMethod._api_detach)))


class Plan(StripeObject):
    object = 'plan'
    _id_prefix = 'plan_'

    def __init__(self, id=None, metadata=None, amount=None, product=None,
                 currency=None, interval=None, interval_count=1,
                 trial_period_days=None, nickname=None, usage_type='licensed',
                 billing_scheme='per_unit', tiers=None, tiers_mode=None,
                 unit_amount=0, flat_amount=0,
                 active=True,
                 # Legacy arguments, before Stripe API 2018-02-05:
                 name=None, statement_descriptor=None,
                 **kwargs):
        if kwargs:
github adrienverge / localstripe / localstripe / resources.py View on Github external
def _requires_authentication(self):
        return PaymentMethod._requires_authentication(self)
github adrienverge / localstripe / localstripe / resources.py View on Github external
def _charging_is_declined(self):
        return PaymentMethod._charging_is_declined(self)
github adrienverge / localstripe / localstripe / resources.py View on Github external
try:
            assert _type(customer) is str and customer.startswith('cus_')
            assert type in ('card', )
        except AssertionError:
            raise UserError(400, 'Bad request')

        Customer._api_retrieve(customer)  # to return 404 if not existant

        li = super(PaymentMethod, cls)._api_list_all(url, limit=limit)
        li._list = [pm for pm in li._list
                    if pm.customer == customer and pm.type == type]
        return li


extra_apis.extend((
    ('POST', '/v1/payment_methods/{id}/attach', PaymentMethod._api_attach),
    ('POST', '/v1/payment_methods/{id}/detach', PaymentMethod._api_detach)))


class Plan(StripeObject):
    object = 'plan'
    _id_prefix = 'plan_'

    def __init__(self, id=None, metadata=None, amount=None, product=None,
                 currency=None, interval=None, interval_count=1,
                 trial_period_days=None, nickname=None, usage_type='licensed',
                 billing_scheme='per_unit', tiers=None, tiers_mode=None,
                 unit_amount=0, flat_amount=0,
                 active=True,
                 # Legacy arguments, before Stripe API 2018-02-05:
                 name=None, statement_descriptor=None,
                 **kwargs):
github adrienverge / localstripe / localstripe / resources.py View on Github external
def _attaching_is_declined(self):
        return PaymentMethod._attaching_is_declined(self)
github adrienverge / localstripe / localstripe / resources.py View on Github external
assert type(client_secret) is str
            if payment_method_data is not None:
                assert type(payment_method_data) is dict
        except AssertionError:
            raise UserError(400, 'Bad request')

        obj = cls._api_retrieve(id)

        if client_secret and client_secret != obj.client_secret:
            raise UserError(401, 'Unauthorized')

        if payment_method_data:
            if obj.payment_method is not None:
                raise UserError(400, 'Bad request')

            pm = PaymentMethod(**payment_method_data)
            obj.payment_method = pm.id

            if pm._attaching_is_declined():
                obj.status = 'canceled'
                obj.next_action = None
                raise UserError(402, 'Your card was declined.',
                                {'code': 'card_declined'})
            elif pm._requires_authentication():
                obj.status = 'requires_action'
                obj.next_action = {'type': 'use_stripe_sdk',
                                   'use_stripe_sdk': {
                                       'type': 'three_d_secure_redirect',
                                       'stripe_js': ''}}
            else:
                obj.status = 'succeeded'
                obj.next_action = None