← All changes
|
app/Modules/Payments/PaymentMethods/Stripe/StripeSettings.php
+13
-1
6.2.8
→
trunk
View file →
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace FluentForm\App\Modules\Payments\PaymentMethods\Stripe; |
| 4 | 4 | |
| 5 | +use FluentForm\App\Models\Subscription; | |
| 5 | 6 | use FluentForm\Framework\Helpers\ArrayHelper; |
| 6 | 7 | use FluentForm\App\Modules\Payments\PaymentHelper; |
| 7 | 8 | |
| 8 | 9 | if (!defined('ABSPATH')) { |
| @@ -237,10 +238,13 @@ | ||
| 237 | 238 | $eventType = $event->type; |
| 238 | 239 | |
| 239 | 240 | $metaDataEvents = [ |
| 240 | 241 | 'checkout.session.completed', |
| 242 | + 'checkout.session.async_payment_succeeded', | |
| 243 | + 'checkout.session.async_payment_failed', | |
| 241 | 244 | 'charge.refunded', |
| 242 | - 'charge.succeeded' | |
| 245 | + 'charge.succeeded', | |
| 246 | + 'charge.failed', | |
| 243 | 247 | ]; |
| 244 | 248 | |
| 245 | 249 | if (in_array($eventType, $metaDataEvents)) { |
| 246 | 250 | $data = $event->data->object; |
| @@ -245,8 +249,16 @@ | ||
| 245 | 249 | if (in_array($eventType, $metaDataEvents)) { |
| 246 | 250 | $data = $event->data->object; |
| 247 | 251 | $metaData = (array)$data->metadata; |
| 248 | 252 | return ArrayHelper::get($metaData, 'form_id'); |
| 253 | + } | |
| 254 | + | |
| 255 | + // A delayed subscription's first invoice settles the entry, so it needs the form's own key too. Once the entry is | |
| 256 | + // linked, renewals keep the global key: a form moved to its own account still bills older subscriptions on it. | |
| 257 | + $invoice = $event->data->object; | |
| 258 | + if ('invoice.payment_succeeded' === $eventType && isset($invoice->subscription, $invoice->subscription_details->metadata->form_id) | |
| 259 | + && !Subscription::byVendorSubscriptionId($invoice->subscription)->first()) { | |
| 260 | + return $invoice->subscription_details->metadata->form_id; | |
| 249 | 261 | } |
| 250 | 262 | |
| 251 | 263 | return false; |
| 252 | 264 | } |