當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。