Edit File by line
/home/zeestwma/ceyloniy.../wp-conte.../plugins/wpforms-.../src/Integrat.../Square/Api/Webhooks
File: SubscriptionUpdated.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Integrations\Square\Api\Webhooks;
[2] Fix | Delete
[3] Fix | Delete
use RuntimeException;
[4] Fix | Delete
use WPForms\Db\Payments\UpdateHelpers;
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Webhook subscription.updated class.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 1.9.5
[10] Fix | Delete
*/
[11] Fix | Delete
class SubscriptionUpdated extends Base {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Update the subscription status.
[15] Fix | Delete
*
[16] Fix | Delete
* @since 1.9.5
[17] Fix | Delete
*
[18] Fix | Delete
* @return bool
[19] Fix | Delete
*
[20] Fix | Delete
* @throws RuntimeException If payment isn't found or not updated.
[21] Fix | Delete
*/
[22] Fix | Delete
public function handle(): bool {
[23] Fix | Delete
[24] Fix | Delete
$payment = wpforms()->obj( 'payment' )->get_by( 'subscription_id', $this->data->object->subscription->id );
[25] Fix | Delete
[26] Fix | Delete
if ( ! $payment ) {
[27] Fix | Delete
return false;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
// Track canceled subscriptions.
[31] Fix | Delete
if ( isset( $this->data->object->subscription->canceled_date ) ) {
[32] Fix | Delete
if ( ! UpdateHelpers::cancel_subscription( $payment->id, 'Square subscription cancelled from the Square dashboard.' ) ) {
[33] Fix | Delete
throw new RuntimeException( 'Subscription cancellation was not updated.' );
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
return true;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
$status = strtolower( $this->data->object->subscription->status );
[40] Fix | Delete
[41] Fix | Delete
// Return true if the subscription status is the same as the status in the webhook data.
[42] Fix | Delete
if ( $payment->subscription_status === $status ) {
[43] Fix | Delete
return true;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
// Update subscription status.
[47] Fix | Delete
if ( ! wpforms()->obj( 'payment' )->update( $payment->id, [ 'subscription_status' => $status ] ) ) {
[48] Fix | Delete
throw new RuntimeException( 'Payment not updated' );
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
wpforms()->obj( 'payment_meta' )->add_log(
[52] Fix | Delete
$payment->id,
[53] Fix | Delete
sprintf( 'Square subscription was set to %1$s.', $status )
[54] Fix | Delete
);
[55] Fix | Delete
[56] Fix | Delete
return true;
[57] Fix | Delete
}
[58] Fix | Delete
}
[59] Fix | Delete
[60] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function