@@ -1115,6 +1115,47 @@ def _api_update(cls, id, **data):
1115
1115
def _api_delete (cls , id ):
1116
1116
raise UserError (405 , 'Method Not Allowed' )
1117
1117
1118
+ @classmethod
1119
+ def _api_list_all (cls , url , type = None , created = None , limit = None ,
1120
+ starting_after = None , ** kwargs ):
1121
+ if kwargs :
1122
+ raise UserError (400 , 'Unexpected ' + ', ' .join (kwargs .keys ()))
1123
+
1124
+ filters = []
1125
+ try :
1126
+ if type is not None :
1127
+ assert _type (type ) is str
1128
+ filters .append (lambda obj : obj .type == type )
1129
+ if created is not None :
1130
+ assert _type (created ) is dict
1131
+ gt = try_convert_to_int (created .pop ('gt' , None ))
1132
+ if gt is not None :
1133
+ filters .append (lambda obj : obj .created > gt )
1134
+
1135
+ gte = try_convert_to_int (created .pop ('gte' , None ))
1136
+ if gte is not None :
1137
+ filters .append (lambda obj : obj .created >= gte )
1138
+
1139
+ lt = try_convert_to_int (created .pop ('lt' , None ))
1140
+ if lt is not None :
1141
+ filters .append (lambda obj : obj .created < lt )
1142
+
1143
+ lte = try_convert_to_int (created .pop ('lte' , None ))
1144
+ if lte is not None :
1145
+ filters .append (lambda obj : obj .created <= lte )
1146
+
1147
+ assert not created # no other params are supported
1148
+ except AssertionError :
1149
+ raise UserError (400 , 'Bad request' )
1150
+
1151
+ li = super ()._api_list_all (
1152
+ url , limit = limit , starting_after = starting_after
1153
+ )
1154
+
1155
+ li ._list = [obj for obj in li ._list if all (f (obj ) for f in filters )]
1156
+
1157
+ return li
1158
+
1118
1159
1119
1160
class Invoice (StripeObject ):
1120
1161
object = 'invoice'
@@ -1877,18 +1918,21 @@ def __init__(self, amount=None, currency=None, customer=None,
1877
1918
self ._authentication_failed = False
1878
1919
1879
1920
def _on_success (self ):
1921
+ schedule_webhook (Event ('payment_intent.succeeded' , self ))
1880
1922
if self .invoice :
1881
1923
invoice = Invoice ._api_retrieve (self .invoice )
1882
1924
invoice ._on_payment_success ()
1883
1925
1884
1926
def _report_failure (self ):
1927
+ schedule_webhook (Event ('payment_intent.payment_failed' , self ))
1885
1928
if self .invoice :
1886
1929
invoice = Invoice ._api_retrieve (self .invoice )
1887
1930
invoice ._on_payment_failure_now ()
1888
1931
1889
1932
self .latest_charge ._raise_failure ()
1890
1933
1891
- def _on_failure_later (self ):
1934
+ def _report_async_failure (self ):
1935
+ schedule_webhook (Event ('payment_intent.payment_failed' , self ))
1892
1936
if self .invoice :
1893
1937
invoice = Invoice ._api_retrieve (self .invoice )
1894
1938
invoice ._on_payment_failure_later ()
@@ -1905,7 +1949,7 @@ def _create_charge(self, on_failure_now):
1905
1949
charge .payment_intent = self .id
1906
1950
self .latest_charge = charge
1907
1951
charge ._initialize_charge (self ._on_success , on_failure_now ,
1908
- self ._on_failure_later )
1952
+ self ._report_async_failure )
1909
1953
1910
1954
@property
1911
1955
def status (self ):
0 commit comments