adrienverge / localstripe

A fake but stateful Stripe server that you can run locally, for testing purposes.
GNU General Public License v3.0
192 stars 59 forks source link

PaymentIntent: Add latest_charge #214

Closed H--o-l closed 1 year ago

H--o-l commented 1 year ago

From Stripe API version 2022-11-15 changelog:

The charges property on PaymentIntent has been removed. You can use the latest_charge property instead.

This commit adds the latest_charge property on the PaymentIntent object. This commit does not remove PaymentIntent.charges for retro compatibility.

H--o-l commented 1 year ago

I see 2 code cleanings that seem legitimate, what do you think?

Indeed, thanks!


--- a/localstripe/resources.py
+++ b/localstripe/resources.py
@@ -1850,12 +1850,11 @@ class PaymentIntent(StripeObject):
             return 'requires_action'
         if self.latest_charge is None:
             return 'requires_confirmation'
-        charge = self.latest_charge
-        if charge.status == 'succeeded':
+        if self.latest_charge.status == 'succeeded':
             return 'succeeded'
-        elif charge.status == 'failed':
+        elif self.latest_charge.status == 'failed':
             return 'requires_payment_method'
-        elif charge.status == 'pending':
+        elif self.latest_charge.status == 'pending':
             return 'processing'

     @property
@@ -1874,12 +1873,11 @@ class PaymentIntent(StripeObject):
                     'The provided PaymentMethod has failed authentication.'),
             }
         if self.latest_charge:
-            charge = self.latest_charge
-            if charge.status == 'failed':
+            if self.latest_charge.status == 'failed':
                 return {
-                    'charge': charge.id,
-                    'code': charge.failure_code,
-                    'message': charge.failure_message,
+                    'charge': self.latest_charge.id,
+                    'code': self.latest_charge.failure_code,
+                    'message': self.latest_charge.failure_message,
                 }

     @classmethod