wp-user-avatar
/
src
/
Membership
/
PaymentMethods
/
Stripe
/
WebhookHandlers
/
PaymentIntentSucceeded.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
PaymentIntentSucceeded.php
36 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Membership\PaymentMethods\Stripe\WebhookHandlers; |
| 4 | |
| 5 | use ProfilePress\Core\Membership\Models\Order\OrderFactory; |
| 6 | use ProfilePress\Core\Membership\Models\Subscription\SubscriptionFactory; |
| 7 | use ProfilePress\Core\Membership\PaymentMethods\WebhookHandlerInterface; |
| 8 | use ProfilePress\Core\Membership\Repositories\OrderRepository; |
| 9 | |
| 10 | class PaymentIntentSucceeded implements WebhookHandlerInterface |
| 11 | { |
| 12 | public function handle($event_data) |
| 13 | { |
| 14 | $order = OrderFactory::fromId( |
| 15 | $event_data['metadata']['order_id'] ?? 0 |
| 16 | ); |
| 17 | |
| 18 | $payment_intent_id = $event_data['id']; |
| 19 | |
| 20 | if ( ! $order->exists()) { |
| 21 | $orders = OrderRepository::init()->retrieveBy(['transaction_id' => $payment_intent_id, 'number' => 1]); |
| 22 | if ( ! empty($orders)) $order = $orders[0]; |
| 23 | } |
| 24 | |
| 25 | if ($order->exists() && ! $order->is_completed()) { |
| 26 | $order->complete_order($payment_intent_id); |
| 27 | } |
| 28 | |
| 29 | $subscription = SubscriptionFactory::fromId($order->subscription_id); |
| 30 | |
| 31 | if ($subscription->exists() && ! $order->get_plan()->is_auto_renew()) { |
| 32 | $subscription->activate_subscription(); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 |