/
card.py
78 lines (64 loc) · 2.67 KB
/
card.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from __future__ import absolute_import, division, print_function
from stripe import error
from stripe import util
from stripe.api_resources.abstract import DeletableAPIResource
from stripe.api_resources.abstract import UpdateableAPIResource
from stripe.api_resources.account import Account
from stripe.api_resources.customer import Customer
from stripe.six.moves.urllib.parse import quote_plus
class Card(DeletableAPIResource, UpdateableAPIResource):
"""
You can store multiple cards on a customer in order to charge the customer
later. You can also store multiple debit cards on a recipient in order to
transfer to those cards later.
Related guide: [Card Payments with Sources](https://stripe.com/docs/sources/cards).
"""
OBJECT_NAME = "card"
def instance_url(self):
token = util.utf8(self.id)
extn = quote_plus(token)
if hasattr(self, "customer"):
customer = util.utf8(self.customer)
base = Customer.class_url()
owner_extn = quote_plus(customer)
class_base = "sources"
elif hasattr(self, "account"):
account = util.utf8(self.account)
base = Account.class_url()
owner_extn = quote_plus(account)
class_base = "external_accounts"
else:
raise error.InvalidRequestError(
"Could not determine whether card_id %s is "
"attached to a customer, or "
"account." % token,
"id",
)
return "%s/%s/%s/%s" % (base, owner_extn, class_base, extn)
@classmethod
def modify(cls, sid, **params):
raise NotImplementedError(
"Can't modify a card without a customer or account ID. "
"Use stripe.Customer.modify_source('customer_id', 'card_id', ...) "
"(see https://stripe.com/docs/api/cards/update) or "
"stripe.Account.modify_external_account('account_id', 'card_id', ...) "
"(see https://stripe.com/docs/api/external_account_cards/update)."
)
@classmethod
def retrieve(
cls,
id,
api_key=None,
stripe_version=None,
stripe_account=None,
**params
):
raise NotImplementedError(
"Can't retrieve a card without a customer or account ID. "
"Use stripe.Customer.retrieve_source('customer_id', 'card_id') "
"(see https://stripe.com/docs/api/cards/retrieve) or "
"stripe.Account.retrieve_external_account('account_id', 'card_id') "
"(see https://stripe.com/docs/api/external_account_cards/retrieve)."
)