wp-user-avatar
/
src
/
Membership
/
PaymentMethods
/
Stripe
/
WebhookHandlers
/
CustomerSubscriptionDeleted.php
ChargeRefunded.php
11 months ago
CheckoutSessionAsyncPaymentFailed.php
4 months ago
CheckoutSessionAsyncPaymentSucceeded.php
4 months ago
CheckoutSessionCompleted.php
4 months ago
CustomerSubscriptionCreated.php
2 years ago
CustomerSubscriptionDeleted.php
3 years ago
CustomerSubscriptionUpdated.php
11 months ago
InvoicePaymentSucceeded.php
2 years ago
PaymentIntentSucceeded.php
3 years ago
index.php
3 years ago
CustomerSubscriptionDeleted.php
28 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Membership\PaymentMethods\Stripe\WebhookHandlers; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionStatus; |
| 6 | use ProfilePress\Core\Membership\PaymentMethods\WebhookHandlerInterface; |
| 7 | use ProfilePress\Core\Membership\Repositories\SubscriptionRepository; |
| 8 | |
| 9 | class CustomerSubscriptionDeleted implements WebhookHandlerInterface |
| 10 | { |
| 11 | public function handle($event_data) |
| 12 | { |
| 13 | $subscription_profile_id = $event_data['id']; |
| 14 | |
| 15 | $subscription = SubscriptionRepository::init()->retrieveBy([ |
| 16 | 'profile_id' => $subscription_profile_id |
| 17 | ]); |
| 18 | |
| 19 | if (empty($subscription)) return; |
| 20 | |
| 21 | $subscription = $subscription[0]; |
| 22 | |
| 23 | if ( ! in_array($subscription->status, [SubscriptionStatus::CANCELLED, SubscriptionStatus::COMPLETED], true)) { |
| 24 | $subscription->cancel(); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 |