当前位置: 首页>>代码示例>>Python>>正文


Python stripe.com方法代码示例

本文整理汇总了Python中stripe.com方法的典型用法代码示例。如果您正苦于以下问题:Python stripe.com方法的具体用法?Python stripe.com怎么用?Python stripe.com使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stripe的用法示例。


在下文中一共展示了stripe.com方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate_and_save_stripe_fixture

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def generate_and_save_stripe_fixture(decorated_function_name: str, mocked_function_name: str,
                                     mocked_function: CallableT) -> Callable[[Any, Any], Any]:  # nocoverage
    def _generate_and_save_stripe_fixture(*args: Any, **kwargs: Any) -> Any:
        # Note that mock is not the same as mocked_function, even though their
        # definitions look the same
        mock = operator.attrgetter(mocked_function_name)(sys.modules[__name__])
        fixture_path = stripe_fixture_path(decorated_function_name, mocked_function_name, mock.call_count)
        try:
            with responses.RequestsMock() as request_mock:
                request_mock.add_passthru("https://api.stripe.com")
                # Talk to Stripe
                stripe_object = mocked_function(*args, **kwargs)
        except stripe.error.StripeError as e:
            with open(fixture_path, 'w') as f:
                error_dict = e.__dict__
                error_dict["headers"] = dict(error_dict["headers"])
                f.write(json.dumps(error_dict, indent=2, separators=(',', ': '), sort_keys=True) + "\n")
            raise e
        with open(fixture_path, 'w') as f:
            if stripe_object is not None:
                f.write(str(stripe_object) + "\n")
            else:
                f.write("{}\n")
        return stripe_object
    return _generate_and_save_stripe_fixture 
开发者ID:zulip,项目名称:zulip,代码行数:27,代码来源:test_stripe.py

示例2: charge_card

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def charge_card(card, amount, description='', live_mode=False):
    """Charges a card, one time

    It is preferred to create a customer and charge the customer

    https://stripe.com/docs/api/python#create_charge
    https://stripe.com/docs/tutorials/charges
    https://stripe.com/docs/api/python#charges
    """
    _initialize_stripe(live_mode=live_mode)
    charge = safe_stripe_call(
        stripe.Charge.create,
        **{
            'amount' : amount, # amount in cents
            'currency' : 'usd',
            'card' : card,
            'description' : '',
        }
    )
    return charge 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:22,代码来源:utils.py

示例3: retrieve_event

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def retrieve_event(event_id, live_mode=False):
    """Retrieve the Stripe event by `event_id`

    Succeeds when `live_mode==True` and there a corresponding `event_id`
    Fails when event was generated from the Stripe dashboard webhook test

    https://stripe.com/docs/api#retrieve_event
    """
    _initialize_stripe(live_mode=live_mode)
    event = safe_stripe_call(
        stripe.Event.retrieve,
        *(
            event_id,
        )
    )
    return event 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:18,代码来源:utils.py

示例4: add_card

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def add_card(self, card):
        """Add an additional credit card to the customer

        https://stripe.com/docs/api/python#create_card
        """
        stripe_customer = self.retrieve()
        if stripe_customer:
            stripe_card = safe_stripe_call(
                stripe_customer.sources.create,
                **{
                    'source' : card,
                }
            )
        else:
            stripe_card = None
        was_added = stripe_card is not None
        return was_added 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:19,代码来源:models.py

示例5: replace_card

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def replace_card(self, card):
        """Adds a new credit card and delete this Customer's old one

        WARNING: This deletes the old card. Use `add_card` instead to just add a card without deleting

        https://stripe.com/docs/api/python#update_customer
        """
        stripe_customer = self.retrieve()
        if stripe_customer:
            stripe_customer.source = card
            cu = safe_stripe_call(
                stripe_customer.save,
                **{}
            )
        else:
            cu = None
        was_replaced = cu is not None
        return was_replaced 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:20,代码来源:models.py

示例6: get_card

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def get_card(self):
        """
        https://stripe.com/docs/api/python#list_cards
        """
        stripe_customer = self.retrieve()
        if stripe_customer:
            cards = safe_stripe_call(
                stripe_customer.sources.all,
                **{
                    'limit' : 1,
                    'object' : 'card',
                }
            )
            cards = cards.get('data')
            if len(cards) > 0:
                card = cards[0]
            else:
                card = None
        else:
            card = None
        return card 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:23,代码来源:models.py

示例7: retrieve_subscription

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def retrieve_subscription(self, subscription_id):
        """Retrieves a Subscription for this Customer

        https://stripe.com/docs/api#retrieve_subscription
        """
        subscription = None

        if subscription_id:
            stripe_customer = self.retrieve()
            if stripe_customer:
                subscription = safe_stripe_call(
                    stripe_customer.subscriptions.retrieve,
                    **{
                        'id' : subscription_id,
                    }
                )
            else:
                # missing Stripe customer
                pass
        else:
            # missing subscription id
            pass

        return subscription 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:26,代码来源:models.py

示例8: change_subscription_plan

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def change_subscription_plan(self, subscription_id, new_plan):
        """Changes the plan on a Subscription for this Customer

        https://stripe.com/docs/api#update_subscription
        """
        subscription = self.retrieve_subscription(subscription_id)
        if subscription:
            subscription.plan = new_plan
            #subscription.prorate = True
            subscription.save()

            # if the new plan is more expensive, pay right away
            # pro-ration is the default behavior
            # or, just naively create the invoice every time and trust that Stripe handles it correctly
            self.create_invoice_and_pay()
        else:
            pass
        return subscription 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:20,代码来源:models.py

示例9: free_upgrade_or_downgrade

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def free_upgrade_or_downgrade(self, subscription_id, new_plan):
        """Updates the plan on a Subscription for this Customer

        Does an immediate upgrade or downgrade to the new plan, but does
        not charge the Customer.
        This can be used, for example, when providing a free upgrade as
        a courtesy, or for admin-initiated subscription plan changes.

        If intending to charge the customer immediately at time of change
        or with proration, use `change_subscription_plan()` instead.

        https://stripe.com/docs/billing/subscriptions/prorations#disable-prorations
        https://stripe.com/docs/api#update_subscription
        """
        subscription = self.retrieve_subscription(subscription_id)
        if subscription:
            subscription.plan = new_plan
            subscription.prorate = False
            subscription.save()
            # DO NOT CREATE AN INVOICE
        else:
            pass
        return subscription 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:25,代码来源:models.py

示例10: cancel_subscription

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def cancel_subscription(self, subscription_id):
        """Cancels a Subscription for this Customer

        https://stripe.com/docs/api#cancel_subscription

        Returns:
        - True if `subscription_id` was canceled
        - False if `subscription_id` was not found
        """
        subscription = self.retrieve_subscription(subscription_id)
        if subscription:
            subscription.delete()
            was_deleted = True
        else:
            was_deleted = False
        return was_deleted

    ##
    # delete 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:21,代码来源:models.py

示例11: delete

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def delete(self):
        """Deletes a customer

        https://stripe.com/docs/api/python#delete_customer
        """
        stripe_customer = self.retrieve()
        if stripe_customer:
            obj = safe_stripe_call(
                stripe_customer.delete
            )
            if obj:
                super(BaseStripeCustomer, self).delete()
            else:
                pass
        else:
            pass 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:18,代码来源:models.py

示例12: api_url

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def api_url(cls, url=''):
        warnings.warn(
            'The `api_url` class method of APIRequestor is '
            'deprecated and will be removed in version 2.0.'
            'If you need public access to this function, please email us '
            'at support@stripe.com.',
            DeprecationWarning)
        return '%s%s' % (stripe.api_base, url) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:10,代码来源:api_requestor.py

示例13: _deprecated_encode

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def _deprecated_encode(cls, stk, key, value):
        warnings.warn(
            'The encode_* class methods of APIRequestor are deprecated and '
            'will be removed in version 2.0. '
            'If you need public access to this function, please email us '
            'at support@stripe.com.',
            DeprecationWarning, stacklevel=2)
        stk.extend(_api_encode({key: value})) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:10,代码来源:api_requestor.py

示例14: encode

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def encode(cls, d):
        """
        Internal: encode a string for url representation
        """
        warnings.warn(
            'The `encode` class method of APIRequestor is deprecated and '
            'will be removed in version 2.0.'
            'If you need public access to this function, please email us '
            'at support@stripe.com.',
            DeprecationWarning)
        return urllib.urlencode(list(_api_encode(d))) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:13,代码来源:api_requestor.py

示例15: build_url

# 需要导入模块: import stripe [as 别名]
# 或者: from stripe import com [as 别名]
def build_url(cls, url, params):
        warnings.warn(
            'The `build_url` class method of APIRequestor is deprecated and '
            'will be removed in version 2.0.'
            'If you need public access to this function, please email us '
            'at support@stripe.com.',
            DeprecationWarning)
        return _build_api_url(url, cls.encode(params)) 
开发者ID:MayOneUS,项目名称:pledgeservice,代码行数:10,代码来源:api_requestor.py


注:本文中的stripe.com方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。