Submit
Path:
~
/
home
/
getwphos
/
www
/
giulianos
/
wp-content
/
plugins
/
wpforms-lite
/
src
/
Integrations
/
Square
/
Api
/
Webhooks
/
File Content:
SubscriptionUpdated.php
<?php namespace WPForms\Integrations\Square\Api\Webhooks; use RuntimeException; use WPForms\Db\Payments\UpdateHelpers; /** * Webhook subscription.updated class. * * @since 1.9.5 */ class SubscriptionUpdated extends Base { /** * Update the subscription status. * * @since 1.9.5 * * @return bool * * @throws RuntimeException If payment isn't found or not updated. */ public function handle(): bool { $payment = wpforms()->obj( 'payment' )->get_by( 'subscription_id', $this->data->object->subscription->id ); if ( ! $payment ) { return false; } // Track canceled subscriptions. if ( isset( $this->data->object->subscription->canceled_date ) ) { if ( ! UpdateHelpers::cancel_subscription( $payment->id, 'Square subscription cancelled from the Square dashboard.' ) ) { throw new RuntimeException( 'Subscription cancellation was not updated.' ); } return true; } $status = strtolower( $this->data->object->subscription->status ); // Return true if the subscription status is the same as the status in the webhook data. if ( $payment->subscription_status === $status ) { return true; } // Update subscription status. if ( ! wpforms()->obj( 'payment' )->update( $payment->id, [ 'subscription_status' => $status ] ) ) { throw new RuntimeException( 'Payment not updated' ); } wpforms()->obj( 'payment_meta' )->add_log( $payment->id, sprintf( 'Square subscription was set to %1$s.', $status ) ); return true; } }
Submit
FILE
FOLDER
Name
Size
Permission
Action
Base.php
4468 bytes
0644
PaymentCreated.php
5689 bytes
0644
PaymentUpdated.php
5017 bytes
0644
RefundUpdated.php
2783 bytes
0644
SubscriptionCreated.php
841 bytes
0644
SubscriptionUpdated.php
1498 bytes
0644
N4ST4R_ID | Naxtarrr